Take the 2-minute tour ×
ExpressionEngine® Answers is a question and answer site for administrators, end users, developers and designers for ExpressionEngine® CMS. It's 100% free, no registration required.

We have a website, that displays a list of regional offices with their opening and closing times. Part of the design requires that each office is styled to show if its is open or closed.

Our initial thoughts on how to handle this is as follows:

Get the current time {current_time format="%G%i"} so we have 2033

We then have custom fields for each entry, these are {office_open_time} and then {office_close_time} these times are set using GMT (the servers time) so lets take USA as an example 0900 in US time would be 1700 GMT, so the US times we set are:

{office_open_time} = 1700

{office_close_time} = 0100

Our template then checks the times:

{if "{current_time format="%G%i"}" <= "{office_close_time}" AND "{current_time format="%G%i"}" >= "{office_open_time}"}                         
we are open!                    
{if:else}               
we are closed.                  
{/if}

On the whole this works with a few exceptions and issues.

Again lets say our time here in GMT is 2033. The US opening time set in GMT is 1700 so thats correct, but the closing time is 0100 - so the current time is never less than the closing time..!

Then there's also the issue of the weekend but I think we can do that by returning the date as a day and checking if it equals "saturday" OR "sunday" - however I'm not sure how we decide 'when' that's valid... ie it's saturday in the uk before it's saturday in the us!

Any help or suggestions greatly appreciated

share|improve this question
    
Could you ask a more specific question here? –  UltraBob Jan 25 '13 at 9:14

3 Answers 3

A plugin isn't a bad route to take, I would also take a peek at Moment.js (http://momentjs.com/). They have a lot of "time functionality" built that you could probably harness.

share|improve this answer
    
I've bookemarked this - thank you but think we will end up going the plugin root. –  user1503708 Jan 24 '13 at 20:39
    
If you have a couple of shops, then outputting all opening hours and compute with javascript might be a convenient route indeed. –  GDmac Jan 26 '13 at 11:55

I would probably use a custom plugin. Feed the datetimes (and timezone?) into the plugin with parameters (or as tags), and do the checking, math and calculations with PHP inside the plugin. That also leaves you the option for editors to more easily and comfortably enter office hours in their own timezone.

share|improve this answer
    
Thanks GDmac, I think we're all saying the same that a plugin is the way forward here :) –  user1503708 Jan 24 '13 at 20:38
    
maybe even go so far as a complete module. That way you can have custom entry fields as well. –  GDmac Jan 26 '13 at 11:54

via this dude on Facebook:

How about changing your american hours before you test them time (americantime) - (time difference) < opening_time sort of thing?

share|improve this answer
    
I think this is probably a neat solution though it may again require a simple plug-in to handle everything. –  Nathan Pitman Jan 24 '13 at 14:06
    
In VERY simplified terms, Essentially we can get the {countrytime} by setting the offset. Two examples would be the US is -0800 where as China its +0800 Next we'd take that from the current time to give us the time in that country. –  user1503708 Jan 24 '13 at 20:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.