|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-09-12 20:16 UTC] asutton at sbcglobal dot net
[2002-09-12 22:12 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
When using Date.php, the converttz($tz) function does not properly convert the date if the timezone offset from gmt is negative. The problem appears to be caused by a typo in the converttz function which causes subtractSeconds() to be called with a negative value. In a nutshell, the abs() should be applied to the subtractSeconds() argument, not the addSeconds(). I have included a patch which has completely eliminated the problem, as far as I can test. One could also make a case for ammending subtractSeconds() and addSeconds() to catch negative values. Here's a script which demonstrates the problem: ---Cut Here--- <html> <body> <?php require_once("Date.php"); require_once("Date/TimeZone.php"); $mydate = new Date("2002-05-06 20:21:22"); $mylocaltz = new Date_Timezone("US/Central"); print "UTC: " . $mydate->format("%Y-%m-%d %H:%M:%S") . "<br>\n"; $mydate->converttz($mylocaltz); print "CDT: " . $mydate->format("%Y-%m-%d %H:%M:%S") . "<br>\n"; ?> </body> </html> ---Cut Here--- The output on my system is: UTC: 2002-05-06 20:21:22 CDT: 2002-05-06 25:21:22 Note that it is going the wrong way, and that the hours is greater than 23! This isn't even a valid date. Here's the patch: ---Cut Here--- *** ../Date.php Fri Jun 21 20:58:20 2002 --- Date.php Thu Sep 12 17:16:42 2002 *************** *** 440,452 **** } else { $this->addSeconds(intval(abs($this->tz->getOffset($this)) / 1000)) ; } // convert UTC to new timezone if($tz->getOffset($this) > 0) { ! $this->addSeconds(intval(abs($tz->getOffset($this)) / 1000)); } else { ! $this->subtractSeconds(intval($tz->getOffset($this) / 1000)); } $this->tz = $tz; } /** --- 440,452 ---- } else { $this->addSeconds(intval(abs($this->tz->getOffset($this)) / 1000)) ; } // convert UTC to new timezone if($tz->getOffset($this) > 0) { ! $this->addSeconds(intval($tz->getOffset($this) / 1000)); } else { ! $this->subtractSeconds(intval(abs($tz->getOffset($this)) / 1000)); } $this->tz = $tz; } /** ---Cut Here--- Thanks, Allan -- Allan Sutton asutton@sbcglobal.net