Topic: Day Light Savings Time

It would be nice if the system could adjust for daylight savings time automatically, and if not that there should at least be a check box for "Currently Daylight Savings Time" so that you didn't have to figure out if it should be +1 or -1 from your timezone.

Re: Day Light Savings Time

The problem is that DST kicks in at different times in different parts of the world.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Day Light Savings Time

Then I'd think the easiest solution would just be a check box for DST ON/OFF so that you didn't have to fudge around with your timezone to get the correct times.

Re: Day Light Savings Time

<?php 
$timezone=5; 
$summer=$timezone+3600*date("I"); 
echo gmdate("D, j M Y H:i:s", time() + $summer);
?>

$timezone is difference to GMT.  I *think* that works, but not tested.

"The invisible and the non-existent look very similar."

Re: Day Light Savings Time

that wouldn't help would it? as it would just ajust all time depending on the server being in DST

Re: Day Light Savings Time

Yes, I *think* it would help. Try reading the manual (http://uk2.php.net/date + http://uk2.php.net/gmdate), especially the bit about "I".

"The invisible and the non-existent look very similar."

Re: Day Light Savings Time

1 if Daylight Savings Time, 0 otherwise. but that is for the servers time, NOT the users afaik

Re: Day Light Savings Time

Nope - the calculations depend on GMT (a constant) and provision of the user's difference to GMT (specified in profile).

"The invisible and the non-existent look very similar."

Re: Day Light Savings Time

To tell you all the truth, I have never quite grasped the concept of timezones and DST. Obviously, I have basic understanding of what timezones and DST are, but only basic. If anyone has suggestions on how to improve PunBB's handling of timezones and DST, I am all ears. By suggestions I mean code smile

"Programming is like sex: one mistake and you have to support it for the rest of your life."

10 (edited by Smartys 2005-05-29 01:24)

Re: Day Light Savings Time

http://kimmo.suominen.com/2005/02/13/timezone/
Google r0x0rs big_smile

Unfortunetly, there's this

There are some external restrictions on the implementation provided by this plugin:

    * using other timezones than that of the server only works on UNIX-like systems, as it is implemented by modifying the TZ variable in the environment
    * changing TZ is not available in PHP?s safe mode
    * when TZ is changed, only a success message is displayed instead of the full form: this is due to PHP only implementing the old putenv interface for the environment (not the POSIX unsetenv(3) interface)

Also here
http://us2.php.net/date

djmaze(AT)cpgnuke(.)com
27-Mar-2005 11:53
PHP date, strftime and mktime functions are DST sensitive
This means if the server is setup to be US GMT-5 and DST sensitive then the mentioned functions add, extract or do nothing with the current DST.

Without a given timestamp:
   - date() uses the current server time.
     This is DST affected if the server uses DST settings
   - gmdate() uses the current GMT time, it extracts server GMT & DST.

With a given timestamp:
   - date() is affected if the server uses DST settings
     * if current time is DST but the given time isn't then DST is extracted
     * if current time isn't DST but the given time is then DST is added
   - gmdate() is affected, it extracts server GMT & DST on the given timestamp

So for example $timestamp is a GMT based time.
You modify the $timestamp for a "member" his personal timezone and dst.
The member has setup GMT-5 and DST sensitive
You add his GMT-5 to the $timestamp and check if the $timestamp is in DST or not

Then all the above functions  are screwed in normal use.

<?php

$timestamp = 1122814800; // 07/31/05 13:00:00 GMT
$user_gmt = -5;
$user_dst = 1;

$timestamp += ($user_gmt*3600); // to user time
$timestamp += 3600; // user time is in DST

echo date("H:i:s",$timestamp);
echo gmdate("H:i:s",$timestamp);

?>

If server is GMT+0 in summer (DST is on) the above outputs

08:00:00
07:00:00

If server is GMT+0 in winter (DST is off) the above outputs
09:00:00
08:00:00

If server is GMT-5 in winter (DST is off) the above outputs
09:00:00
03:00:00

If I'm reading this right (and I'm not sure I am), using gmdate seems to make it properly DST sensitive


Edit: Muahahaha, this is my 666th post! And I didn't even plan this big_smile

Re: Day Light Savings Time

you can't make it change to DST without having some way of knowing when that timezone changes to DST - http://timeanddate.com/time/dst2005a.html you can obviouly do it on when the server changes to DST but that might not be when other people change if they change at all.

edit: infact punbb probably is affected by the DST on the server atm since it uses date and date is affected by DST since is just uses the current time on the server, question is... is another way better?

edit again:
Daylight Saving Time begins for most of the United States at 2 a.m. on the first Sunday of April. Time reverts to standard time at 2 a.m. on the last Sunday of October. In the U.S., each time zone switches at a different time.

In the European Union, Summer Time begins and ends at 1 am Universal Time (Greenwich Mean Time). It starts the last Sunday in March, and ends the last Sunday in October. In the EU, all time zones change at the same moment.

the EU (its the the european law that they all have to be the same) and the US are easy

then you get
Iran
Start: the first day of Farvardin
End: the first day of Mehr

which is guess is a lunar calendar, and since its not even whole timezones that change its  per country... i don't see how its possible to get all the times perfect

Re: Day Light Savings Time

I think the only way it's going to work is to ask the user, not for timezone, but for locale (country) and calculate based on that. I think if you can get US, Europe, and all the countries that do not use daylight savings right, you'll satisfy 90% of your users. Sounds like a lot of work for little benefit. But still, having to manually adjust for daylights saving is just ridiculous. Why not just blindly use the server's time always? I actually prefer that because then all the times are correct relative to each other.

Re: Day Light Savings Time

well yeh atm it does go to dst if server is in dst, but having every country would be terrible, seen how many countries there are? and they aren't all as simple as USA and europe

Re: Day Light Savings Time

I think I've seen some versions of vBulletin that solve this problem by jsut having a check box for "Currently Daylight Savings Time" which is basically -1 hour to your current time zone. Obviously you'd have to remove the use of the servers DST for this to work though.

15 (edited by bkhl 2005-11-18 04:55)

Re: Day Light Savings Time

kimchi314 wrote:

I think the only way it's going to work is to ask the user, not for timezone, but for locale (country) and calculate based on that. I think if you can get US, Europe, and all the countries that do not use daylight savings right, you'll satisfy 90% of your users. Sounds like a lot of work for little benefit.

Not really. Just using the locale package of the OS solves this problem pretty much automagically. I can't imagine PHP doesn't come with a module for this.

Re: Day Light Savings Time

I know, that topic is too old, but I have an idea.

Why can't we store in profile not timezone, but difference between server time & user's time.
User's time we can get through JS smile

Then to display dates in user's timezone we just have to add difference to server's time.

Re: Day Light Savings Time

Some server are set to strict GMT and doesn't switch to daylight.