NYCPHP Meetup

NYPHP.org

gmmktime weirdness

Lance Lovette lance.listserv at optimost.com
Wed Apr 2 15:46:13 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





More information about the talk mailing list