php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30096 gmmktime does not return the corrent time
Submitted: 2004-09-15 16:43 UTC Modified: 2005-07-03 16:37 UTC
Votes:7
Avg. Score:5.0 ± 0.0
Reproduced:7 of 7 (100.0%)
Same Version:3 (42.9%)
Same OS:5 (71.4%)
From: schmidt_florian at f-24 dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.*, 4.* OS: *
Private report: No CVE-ID: None
 [2004-09-15 16:43 UTC] schmidt_florian at f-24 dot com
Description:
------------
i have seen many bugs concerning this problem, but the latest stable php versions (4 and 5) still dont work correct.

echo gmdate("H,i,s, m,d,Y", gmmktime(02,00,01, 03,28,2004));

expected result:                     02,00,01, 03,28,2004
result i got with v4.3.8	     03,00,01, 03,28,2004
result i got with v5.0.1	     03,00,01, 03,28,2004

so it is one hour off the wanted value.

v4.3.8 on a Linux 2.6.7 with libc6 2.3.2.ds1-13
v5.0.1 on a Linux 2.6.7-gentoo-r11 with glibc 2.3.4.20040808

timezone: CEST+DST (GMT+0200)



Reproduce code:
---------------
echo gmdate("H,i,s, m,d,Y", gmmktime(02,00,01, 03,28,2004));


Expected result:
----------------
02,00,01, 03,28,2004

Actual result:
--------------
03,00,01, 03,28,2004

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-15 16:45 UTC] schmidt_florian at f-24 dot com
its called debian...
 [2004-09-15 17:18 UTC] derick@php.net
I'll have a look
 [2004-09-15 19:05 UTC] rasmus@php.net
Looks ok on my Debian laptop:

php -r 'echo phpversion()."\n"; echo gmdate("H,i,s, m,d,Y", gmmktime(02,00,01, 03,28,2004));'
4.3.9RC2-dev
02,00,01, 03,28,2004

Since we are dealing with GMT, your timezone should be irrelevant.
 [2004-09-15 19:11 UTC] schmidt_florian at f-24 dot com
the timezone should!! be irrelevant thats the reason i use gmmktime()... but it dont work?!
 [2004-09-16 08:23 UTC] derick@php.net
Rasmus, I can reproduce it here. No clue why yet. I guess I have something to do on the next plane ;-)
 [2005-04-04 15:48 UTC] gottwald at quantum-hydrometrie dot de
This is still broken for 4.3.10. gmmktime() is correct when changing from DST to non-DST, but incorrect when changing from non-DST to DST:

gmmktime(02, 00, 00, 10, 31, 2004): 1099188000
gmmktime(03, 00, 00, 10, 31, 2004): 1099191600
Diff: 3600, correct

gmmktime(02, 00, 00, 03, 27, 2005): 1111892400
gmmktime(03, 00, 00, 03, 27, 2005): 1111892400
Diff: 0, broken
 [2005-04-05 18:46 UTC] fabian-php at spline dot de
I can reproduce this for debian testing (php 4.3.10) and for gentoo (php 4.3.10).

The problem apears only the day when switching from dst to no dst. On that day all input that is between 02:00:00-02:59:59 ist mapped to a timestamp which is 3600 seconds later (03:00:00-03:50:59).


Here is my script to reproduce the behavoir:

<?php
echo "no dst --> dst<br>";
$ts=-1;
gm_date_check(01,00,00,03,27,2005);
gm_date_check(02,00,00,03,27,2005);
gm_date_check(03,00,00,03,27,2005);
gm_date_check(04,00,00,03,27,2005);
echo "<p>";
echo "dst --> no dst<br>";
$ts=-1;
gm_date_check(01,00,00,10,30,2005);
gm_date_check(02,00,00,10,30,2005);
gm_date_check(03,00,00,10,30,2005);
gm_date_check(04,00,00,10,30,2005);

function gm_date_check($hour,$minute,$second,$month,$day,$year) {
	global $ts,$tsold;
	echo "gmmktime($hour,$minute,$second,$month,$day,$year): " ;
	$tsold = $ts;
	$ts = gmmktime($hour,$minute,$second,$month,$day,$year,0) ;
	echo $ts ." | gmdate('r',$ts):".gmdate('r',$ts);
	if ($tsold>0) echo " | Diff: " . ($ts - $tsold);
	echo "<br>";
}

?>

==================OUTPUT==============================
no dst --> dst
gmmktime(0,0,0,3,27,2005): 1111885200 | gmdate('r',1111885200):Sun, 27 Mar 2005 01:00:00 +0000
gmmktime(1,0,0,3,27,2005): 1111888800 | gmdate('r',1111888800):Sun, 27 Mar 2005 02:00:00 +0000 | Diff: 3600
gmmktime(2,0,0,3,27,2005): 1111892400 | gmdate('r',1111892400):Sun, 27 Mar 2005 03:00:00 +0000 | Diff: 3600
gmmktime(3,0,0,3,27,2005): 1111896000 | gmdate('r',1111896000):Sun, 27 Mar 2005 04:00:00 +0000 | Diff: 3600
gmmktime(4,0,0,3,27,2005): 1111899600 | gmdate('r',1111899600):Sun, 27 Mar 2005 05:00:00 +0000 | Diff: 3600

dst --> no dst
gmmktime(0,0,0,10,30,2005): 1130630400 | gmdate('r',1130630400):Sun, 30 Oct 2005 00:00:00 +0000
gmmktime(1,0,0,10,30,2005): 1130634000 | gmdate('r',1130634000):Sun, 30 Oct 2005 01:00:00 +0000 | Diff: 3600
gmmktime(2,0,0,10,30,2005): 1130637600 | gmdate('r',1130637600):Sun, 30 Oct 2005 02:00:00 +0000 | Diff: 3600
gmmktime(3,0,0,10,30,2005): 1130641200 | gmdate('r',1130641200):Sun, 30 Oct 2005 03:00:00 +0000 | Diff: 3600
gmmktime(4,0,0,10,30,2005): 1130644800 | gmdate('r',1130644800):Sun, 30 Oct 2005 04:00:00 +0000 | Diff: 3600
 [2005-04-05 18:52 UTC] fabian-php at spline dot de
Crap!
I posted a wrong version, where the dst parameter of the gmmktime call was set to 0 (which shouldn't make a difference according to the documenation by the way)
To get the output a was talking about one has to remove the 7th parameter from the gmmktime call.

====================OUTPUT=================
no dst --> dst
gmmktime(1,0,0,3,27,2005): 1111885200 | gmdate('r',1111885200):Sun, 27 Mar 2005 01:00:00 +0000
gmmktime(2,0,0,3,27,2005): 1111892400 | gmdate('r',1111892400):Sun, 27 Mar 2005 03:00:00 +0000 | Diff: 7200
gmmktime(3,0,0,3,27,2005): 1111892400 | gmdate('r',1111892400):Sun, 27 Mar 2005 03:00:00 +0000 | Diff: 0
gmmktime(4,0,0,3,27,2005): 1111896000 | gmdate('r',1111896000):Sun, 27 Mar 2005 04:00:00 +0000 | Diff: 3600

dst --> no dst
gmmktime(1,0,0,10,30,2005): 1130634000 | gmdate('r',1130634000):Sun, 30 Oct 2005 01:00:00 +0000
gmmktime(2,0,0,10,30,2005): 1130637600 | gmdate('r',1130637600):Sun, 30 Oct 2005 02:00:00 +0000 | Diff: 3600
gmmktime(3,0,0,10,30,2005): 1130641200 | gmdate('r',1130641200):Sun, 30 Oct 2005 03:00:00 +0000 | Diff: 3600
gmmktime(4,0,0,10,30,2005): 1130644800 | gmdate('r',1130644800):Sun, 30 Oct 2005 04:00:00 +0000 | Diff: 3600
 [2005-07-03 16:37 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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 21:01:28 2024 UTC