NYCPHP Meetup

NYPHP.org

gmmktime weirdness

Lance Lovette lance at optimost.com
Wed Apr 2 15:03:20 EST 2003


Can someone do me a favor and run this script with the latest release of PHP
and tell me what the output is for them?
 
<?php
$t = gmmktime(2, 0, 0, 4, 6, 2003);
printf('%d = %s expected 2:00 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
$t = gmmktime(2, 30, 0, 4, 6, 2003);
printf('%d = %s expected 2:30 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
$t = gmmktime(3, 0, 0, 4, 6, 2003);
printf('%d = %s expected 3:00 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
 
gmmktime(0, 0, 0, 1, 1, 1970); // causes later calls to gmmktime to be wrong
 
$t = gmmktime(2, 0, 0, 4, 6, 2003);
printf('%d = %s expected 2:00 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
$t = gmmktime(2, 30, 0, 4, 6, 2003);
printf('%d = %s expected 2:30 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
$t = gmmktime(3, 0, 0, 4, 6, 2003);
printf('%d = %s expected 3:00 AM<br>', $t, gmdate('D, d M Y H:i:s T', $t));
?>
 
I'm running version 4.2.1 and the output makes no sense to me.
 
1049590800 = Sun, 06 Apr 2003 01:00:00 GMT expected 2:00 AM
1049592600 = Sun, 06 Apr 2003 01:30:00 GMT expected 2:30 AM
1049598000 = Sun, 06 Apr 2003 03:00:00 GMT expected 3:00 AM
1049598000 = Sun, 06 Apr 2003 03:00:00 GMT expected 2:00 AM
1049599800 = Sun, 06 Apr 2003 03:30:00 GMT expected 2:30 AM
1049598000 = Sun, 06 Apr 2003 03:00:00 GMT expected 3:00 AM

First off, calling gmmktime in the middle of the script changes the return
value of later gmmktime calls even though they are identical to the first
set of calls. Second, I figured gmmktime(2, 0, 0, 4, 6, 2003) would always
return 2 AM even though that's when the time "Springs forward" for me.
 
Thanks!
Lance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030402/597a17ba/attachment.html>


More information about the talk mailing list