ID: 42645
Comment by: fkl at tfu dot jgfi
Reported By: carstenklein at yahoo dot de
Status: Assigned
Bug Type: Date/time related
Operating System: Linux Ubuntu Feisty Fawn
PHP Version: 5.2.4
Assigned To: derick
New Comment:
http://www.meta-fx.com
http://www.forex.co.ir
forexÝÇÑÓ
Previous Comments:
[2007-09-13 08:09:47] [EMAIL PROTECTED]
Assigned to the ext/date maintainer. :)
[2007-09-12 18:04:30] carstenklein at yahoo dot de
Small err on my behalf, where it reads:
result often are non reproducible and may seem quite random
it must read:
result are reproducible but may seem quite random
and
Therefore I urge you to at least provide a timezone offset less
version of mktime in order to at least get some reproducible results.
it should read
Therefore I urge you to at least provide a timezone offset less
version of mktime and let the user do the rest.
A provable solution would be to take the seventh, now deprecated
parameter to mktime and make it a flag indicating wether or not offsets
will be applied to the resulting date/time.
[2007-09-12 16:06:37] carstenklein at yahoo dot de
Description:
getdate() a/o mktime() do not always add/subtract the currently valid
dst offset. Actually, they do only add the dst offset under certain
conditions, but not always and not to all possible normal time/summer
time, summer time/normal time transitions.
see below code for an example on how to reprocude the erroneous
behaviour. the lines being marked with good/failure represent the
lines where the dst offset has been added. As you can see, it happens
not for all possible dates since 1970-1-1, at least in the local
configuration being set to CET/CEST.
BTW: opposed to what is expected, CEST to CET transitions do not seem
to work at all, I was unable to setup a scenario where the dst offset
would have been subtracted from the resulting timestamp. It seems as if
the mktime() or timelib functions do not take dst into account when
transitioning a date from summer time to normal time.
I would therefore like mktime and the timelib to no longer try to guess
the actual current time and automatically add the required dst offsets
to either date and time as it is prone to error as one can clearly see
in the below example outputs of below program fragment. Additionally,
the results often are non reproducible and may seem quite random. If you
don't believe, go and try for yourself, change the number of days to be
added to the start date from 20 to for example 10 or other reasonable
values. Furthermore, try to play with the starting date, make it some
date in February instead of for example March, but make sure that you
transition the date beyond the last Sunday in March, 1:00am. As you can
see, the results will vary greatly.
Of course one could always double check the results returned by mktime,
however, this is a lot of special casing etc. Therefore I urge you to at
least provide a timezone offset less version of mktime in order to at
least get some reproducible results.
And, using the seventh optional parameter to mktime() makes no
difference at all, besides that, it is considered deprecated.
similar bug reports, all having been closed so far:
http://bugs.php.net/bug.php?id=245
http://bugs.php.net/bug.php?id=741
Reproduce code:
---
?php
function addDuration( $date, $durationArray ) {
$t = getdate( $date ); $t[ year ] += $durationArray[ years
]; $t[ mon ] += $durationArray[ months ]; $t[ mday ] +=
$durationArray[ days ];
$t[ hours ] += $durationArray[ hours ]; $t[ minutes ] +=
$durationArray[ minutes ]; $t[ seconds ] += $durationArray[
seconds ];
return mktime( $t[ hours ], $t[ minutes ], $t[ seconds ],
$t[ mon ], $t[ mday ], $t[ year ] );
}
function durationToString( $durationArray ) {
return P . $durationArray[ years ] . Y . $durationArray[
months ] . M . $durationArray[ days ] . D . T .
$durationArray[ hours ] . : . $durationArray[ minutes ] . : .
$durationArray[ seconds ];
}
echo Testing Normal Time to DST Transition:\n;
for( $y = 1902; $y 2038; $y++ ) {
for( $x = 14; $x 32; $x++ ) {
$d = strtotime( $y-03-$x 02:30:30 ); echo ( date(
Y-m-d H:i:s, $d ) ) . \t;
$durationArray = array( years = 0, months = 0,
days = 20, hours = 0, minutes = 0, seconds = 0 ); echo +\t
. durationToString( $durationArray ) . \t+\t;
$t = addDuration( $d, $durationArray ); $td = getdate(
$t ); echo date( Y-m-d H:i:s, $t ) . ( $td[ hours ] == 3 ? -
FAILURE : ) . \n;
} }
echo Testing DST to Normal Time Transition:\n;
for( $y = 2037; $y 1901; $y-- ) {
for( $x = 24; $x 32; $x++ ) {
$d = strtotime( $y-10-$x