Jump to content

Daylight Saving Time...Simple?


zetahoff

Recommended Posts

I have searched everywhere I know to look (yes...I searched google), however, I have thus far been unable to find a solution to my problem. I would like users to be able to log into my site and set the timezone to whatever they want it to be. Well, that was easy. Now I would like the site to display the correct time. That is not so easy, as it turns out. I don't know how to go about accounting for DST in every timezone in the world. I have found functions in PHP to translate the time into a specific timezone, however, the functions would like for me to tell them whether DST is in effect. I HAVE GOT TO BE OVERLOOKING SOMETHING!! Really, it can't be this hard. The only solution I have come up with is to write a script to manually account for each timezone's DST rules (which apparently changes from region to region within each timezone). If anyone can help me break this wall of stupidity (it has to be something I am overlooking, right?), please do so. You can even let me know how stupid I am.

Link to comment
Share on other sites

Right, however, most of my users are local and would like to have their local time and date displayed on the server. The entire purpose of my webpage (as are most webpages) is to make the life of the user easier. So it would just make sense to display the timezone that they would like to set themselves in accurately.

Link to comment
Share on other sites

timezone_offset_get only works if you know what timezone region the user is in. Just knowing the user's timezone is not enough to tell you if they observer DST or not. There are states in the US where some counties observer DST and others do not.

 

Right, however, most of my users are local and would like to have their local time and date displayed ...

 

If they are local then just adjust the time based upon your local settings. There just is no perfect way to do this. You can either go the simple route of assuming everyone does observe DST and set the fall ahead and back to one region's dates, or you can get real complex and "try" and determine what region they are in based upon IP and the tme zone they choose and then build a huge database of locals and what their start and end of DST is.

 

Or, you could try a Javascript hack. Basically, when they choose their time zone also have two hidden fields on the page. Use some javascript to determine their DST start and end, then populate the hidden fields with those fields.

Link to comment
Share on other sites

Thanks for the help, jesirose. Yes, I had already looked in the PHP manual, however, the DST is still not acurate according to the function you linked to. No, it's not the only function I looked at.

 

And thank you as well, mjdamato. I had thought of that, as well. However, if my user is viewing their data while traveling, they still want the data to appear in the timezone they had chosen before they left for the trip. So I wouldn't be able to rely on the timezone they are currently in. A better example would be if a CEO wanted to view sales by hour in a store in Texas, but he was in Japan, how could I go about displaying the data for him in the Texas timezone? It wouldn't be too difficult if I knew beforehand which timezone's my user's would select. I guess what it comes down to is I will have to give the user the option to choose their timezone from a very long list, such as provided here: http://uk.php.net/manual/en/timezones.php and then use the old TZ to set the timezone. I simply thought there HAD to be an easier way of doing this, especially since several forums, including this one, go ahead and take account for the timezones of their users.

Link to comment
Share on other sites

Ok, so that solution helps if I tell all my clients that they must bring laptops with them whenever they travel, don't use the computers at the head office to check their data unless they want to do the time calculations, and they need to let me know when the time changes, and how many hours it changes, and in which direction. Seems like there should be an easier way to do this....

Link to comment
Share on other sites

if my user is viewing their data while traveling, they still want the data to appear in the timezone they had chosen before they left for the trip.

 

Um, didn't I suggest that you use JS to identify their DST settings when they initially set their timezone? How would that change the time that is displayed to them when they are travelling. If they choose to reset their time zone to the local time then there is nothing you can do.

 

Why are you thinking they have to bring laptops with them? The timezone they selected when registering on the site is the timezone you will use to display time to them It will have nothing to do with what timezone they are actually located in.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.