note 94347 deleted from function.date by danbrown
| From: | danbrown@php.net | Date: | Thu, 29 Oct 2009 17:37:02 +0000 |
| Subject: | note 94347 deleted from function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162259@lists.php.net to get a copy of this message | ||
Note Submitter: profix at cms-studio dot net
----
Hallo, I thing that Corey's note (http://cz2.php.net/manual/en/function.date.php#69221) have a
mistake. Please correct me if it is not true. If date("g") returns 1 as hour and DST is
set (in that example), than intval(date("g")) - 1 returns 0 and it is not good because
than you have 0..12=13 hours per half day in result with this method of DST correction :)
I thing that correct algorithm for formating timestamp with DST is:
function dstdate($format,$timestamp=0)
{
if ($timestamp==0) $timestamp=time();
return date($format,date("I",$timestamp) ? $timestamp : $timestamp-3600);
}
Comment: If DST is *not* set (==0) in given $timestamp, than we subtract one hour from source
timestamp and then we format timestamp to string. We assume that PHP date function returns time with
no DST correction, so we correct it before it is processed by PHP date. If DST is *not* set (winter
time) and there is 1:00 we have 12:00 as result if we have hours formated by "g" not 0:00
as in Corey's code.