note 51328 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 11 Jun 2006 11:34:00 +0000 |
| Subject: | note 51328 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114225@lists.php.net to get a copy of this message | ||
Note Submitter: djmaze(AT)cpgnuke(.)com
----
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
So if you work with local times and the server isn't GMT based be carefull how you output the
times to your members.