date('r') on windows gets wrong timezone
| From: | Chuck Hagenbuch | Date: | Mon, 04 Dec 2000 21:16:41 +0000 |
| Subject: | date('r') on windows gets wrong timezone | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-40042@lists.php.net to get a copy of this message | ||
On Windows (2000 Pro), the 'r' argument to date() (to get an RFC822 compliant
date) gets the wrong sign for the timezone offset - I'm in Eastern Standard
Time, which should be -0500, but for some reason it comes up with +0500. I
looked at ext/standard/datetime.c, and there's a line there to choose the + or -
, but I don't know enough about the underlying code to fix it.
Here's a script that will show the problem - run on unix the two times match,
on windows the signs for the tz offset is off.
<?php
function gm_offset () {
$date = date('H');
$gmdate = gmdate('H');
/* Adjust for wrap-around, the difference can't be more than 12 hours.
* AFAIK, -1200 is invalid, the correct one is +1200 (ie: at New Zealand).
*
* CHANGED Oct 18 2000 (Submitted by <demian@coretech.co.nz>) to handle
* New Zealand daylight savings time.
*/
if ($gmdate + 13 < $date) {
$gmdate += 24;
} else if ($date + 11 <= $gmdate) {
$date += 24;
}
$offset = $date - $gmdate;
if ($offset >= 0) {
return sprintf("+%02d", $offset) . "00";
} else {
return sprintf("-%02d", -$offset) . "00";
}
}
echo date('r');
echo '<hr>';
echo date('D, d M Y H:i:s ') . gm_offset() . ' (' . strftime('%Z') .
')';
?>
-chuck
--
Charles Hagenbuch, <chuck@horde.org>
"If you can't stand the heat, get out of the chicken!" - Baby Blues