NYCPHP Meetup

NYPHP.org

[nycphp-talk] gmmktime weirdness

Hans Zaunere hans at nyu.edu
Wed Apr 2 16:31:54 EST 2003


Lance Lovette wrote:

>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.
>
http://hans.newyorkphp.com/gmmktime.tmp.php

Probably not what you wanted to see.  That's on a FreeBSD 4.7 system, 
and there are significant bugs (that I think some of the PHP folks are 
trying to skirt :) in relation to DST, mktime() and BSD.

http://bugs.php.net/bug.php?id=22163

is just one of them.  Search for mktime and gmmktime at bugs.php.net as 
well.

H





More information about the talk mailing list