Does strtotime () have an error?

Consider this code where we want to add or subtract one second:

date_default_timezone_set("Europe/Amsterdam");

$time = 1477789199;
echo $time . '  -  ' . date('r', $time) . "\n";
// 1477789199  -  Sun, 30 Oct 2016 02:59:59 +0200

This is correct since this timestamp is still within the DST (daylight saving time / daylight saving time).

But now add one second to the integer timestamp and exit DST:

$new = $time + 1;
echo $new . '  -  ' . date('r', $new);
// 1477789200  -  Sun, 30 Oct 2016 02:00:00 +0100

Hooray! PHP sees that after one second there is no more DST and shows the correct time line.

But what if we did not add a second to the integer timestamp, but we used strtotime()to add this second:

$new = strtotime('+1 second', $time);
echo $new . '  -  ' . date('r', $new);
// 1477792800  -  Sun, 30 Oct 2016 03:00:00 +0100

! . , , , , . , , , DST, , ,

DST , ...

. , DST, , .


, ?! ...?

echo strtotime('+ 1 second - 1 second', 1477789199); // echoes 1477792799

Whoa...


. " "? - , - , ?

+4
1

" ".... :

. https://bugs.php.net/bug.php?id=30532 ( , ) ( , ) https://github.com/php/php-src/blob/master/ext/date/tests/bug30532.phpt

<?php date_default_timezone_set("America/New_York");

echo date('Y-m-d H:i:s T', strtotime('2004-10-31 EDT +1 hour'))."\n";
echo date('Y-m-d H:i:s T', strtotime('2004-10-31 EDT +2 hours'))."\n";
echo date('Y-m-d H:i:s T', strtotime('2004-10-31 EDT +3 hours'))."\n";
/* 2004-10-31 01:00:00 EDT
   2004-10-31 01:00:00 EST
   2004-10-31 02:00:00 EST */

echo date('Y-m-d H:i:s T', strtotime('2004-10-31 +1 hour'))."\n";
echo date('Y-m-d H:i:s T', strtotime('2004-10-31 +2 hours'))."\n";
echo date('Y-m-d H:i:s T', strtotime('2004-10-31 +3 hours'))."\n";
/* 2004-10-31 01:00:00 EDT
   2004-10-31 02:00:00 EST
   2004-10-31 03:00:00 EST */

, (: EDT) , .

strtotime (.. 2004-10-31 - : ), , DST (.. , , , , , ..), , .

:

echo date('r', strtotime('+ 0 second', 1477789199));
#> Sun, 30 Oct 2016 02:59:59 +0100

strtotime() , ..

Sun, 30 Oct 2016 02:59:59

(.. Europe/Amsterdam), CET (primary!) - CEST, .

, , .

, , , :

echo date('r', strtotime('CEST', 1477789199));
#> Sun, 30 Oct 2016 02:59:59 +0200
echo date('r', strtotime('CEST + 1 second', 1477789199));
#> Sun, 30 Oct 2016 02:00:00 +0100

, 'CEST ' ( CET, CEST , CETCEST).

+1

Source: https://habr.com/ru/post/1655366/


All Articles