php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27719 mktime returns incorrect timestamp for dst days
Submitted: 2004-03-26 11:27 UTC Modified: 2005-10-08 13:34 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: schmidt dot a at rogers dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 4.4.1RC1, 5.0.0RC1 OS: FreeBSD 4.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: schmidt dot a at rogers dot com
New email:
PHP Version: OS:

 

 [2004-03-26 11:27 UTC] schmidt dot a at rogers dot com
Description:
------------
As of php 5.0RC1 mktime returns a negative value when supplied with a date on daylight savings regardless of the is_dst option.

This did not occur in php 5 beta 3, nor in any version of php 4.


Reproduce code:
---------------
echo mktime(0, 0, 0, 4, 4, 2004, 0) . "\n";
echo mktime(0, 0, 0, 4, 4, 2004, 1) . "\n";
echo mktime(0, 0, 0, 4, 4, 2004, -1) . "\n";

Expected result:
----------------
with php 5 beta 3 and php 4:

1081054800
1081051200
1081054800


Actual result:
--------------
with php 5 RC1:

-7262
-7262
-7262


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-26 11:31 UTC] schmidt dot a at rogers dot com
I should mention it worked fine in php 5 beta 4 as well.
 [2004-03-26 11:33 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip

It works fine for me on LInux (with RC2-dev); perhaps you can try the latest PHP 5 snapshot?
 [2004-03-26 11:54 UTC] schmidt dot a at rogers dot com
I tried it out, and still got the same problem:

[as:andrew] ~/public_html (104) # php -v
PHP 5.0.0RC2-dev (cli) (built: Mar 26 2004 12:00:30)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0RC2-dev, Copyright (c) 1998-2004 Zend Technologies
[as:andrew] ~/public_html (105) # php test_mktime.php 
-7262
-7262
-7262
 [2004-03-26 12:13 UTC] schmidt dot a at rogers dot com
I tested it out on FreeBSD 5.2.1 and still had the same problem using the latest snapshot:

[GD:andrew] ~ (1) > uname -a
FreeBSD my.domain 5.2.1-RELEASE FreeBSD 5.2.1-RELEASE #0: Mon Feb 23 20:45:55 GMT 2004     root@wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC  i386
[GD:andrew] ~ (2) > php -v
PHP 5.0.0RC2-dev (cgi) (built: Mar 26 2004 12:19:53)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.0RC2-dev, Copyright (c) 1998-2004 Zend Technologies
[GD:andrew] ~ (3) > php test_mktime.php
Content-type: text/html
X-Powered-By: PHP/5.0.0RC2-dev

-7262
-7262
-7262
 [2004-03-26 13:39 UTC] schmidt dot a at rogers dot com
Ok I've done some more testing,  FreeBSD mktime will return -1 when passed in 2 am for the day when clocks are being moved ahead,  since 2am should never exist.

I'm not sure how linux handles this (maybe returns a 3am timestamp).

This coupled with the change to ext/standard/datetime.c line 192+ which always changes the hour 2am if its 12 or 1 am.  Unfortunatly this has a bad effect of messing up 12am and 1am for daylight savings days which are valid hours.

http://cvs.php.net/diff.php/php-src/ext/standard/datetime.c?r1=1.116&r2=1.117&ty=h

I'm not sure what the best solution is,  but I hope this helps.
 [2004-03-26 14:00 UTC] rasmus@php.net
I made the changed referenced above to address this bug:
http://bugs.php.net/27533

Perhaps the solution here is to offset it to +3 or +4 instead to get the baseline timestamp.
 [2004-03-26 14:25 UTC] rasmus@php.net
I have committed a fix which uses the 4am offset instead of 2 there around line 192 in datetime.c.  Any chance you could test that and let me know if it fixes your problem?
 [2004-03-26 14:50 UTC] schmidt dot a at rogers dot com
problem fixed.  thanks.
 [2004-03-30 07:42 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2005-10-08 11:16 UTC] nohn@php.net
With PHP 4.4.1RC1 i get these results when running the test:

echo mktime(0, 0, 0, 4, 4, 2004, 0) . "\n";
echo mktime(0, 0, 0, 4, 4, 2004, 1) . "\n";
echo mktime(0, 0, 0, 4, 4, 2004, -1) . "\n";

1081033200
1081029600
1081029600

Derick, is that expected behaviour?
 [2005-10-08 13:34 UTC] derick@php.net
Yes, that is correct.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 03 17:01:29 2024 UTC