Bug #73255 [Opn->Nab]: strtotime -1 day across DST change adds extra hour
| From: | cmb@php.net | Date: | Fri, 01 Oct 2021 12:25:39 +0000 |
| Subject: | Bug #73255 [Opn->Nab]: strtotime -1 day across DST change adds extra hour | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236953@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=73255&edit=1
ID: 73255
Updated by: cmb@php.net
Reported by: mcasey at pegasustech dot com dot au
Summary: strtotime -1 day across DST change adds extra hour
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.0Git-2016-10-06 (Git)
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
The point is that 2016-10-01 23:00:00 is AEST (UTC+10)[1],
not the "expected" AEDT. Gnu date behaves identically:
$ TZ=Australia/Sydney date --date='2016-10-03T00:00:00+1100 - 1 day' -Iseconds
2016-10-01T23:00:00+10:00
So this is actually not a bug.
[1] <https://3v4l.org/p8UvW>
Previous Comments:
------------------------------------------------------------------------
[2017-03-09 17:43:54] guilherme dot passero at unifebe dot edu dot br
I'm having the same issue. Mine occurs when I add 1 day to a date. It seems to add 24 hours
instead, causing problems to me when I deal with dates on and off summer time.
Example code to reproduce the error:
$dates = null;
$start = strtotime('2016-08-10 00:00:00');
$date = $start;
while ($data <= strtotime('2016-10-17')) { //It works if I change it to
'2016-10-17 01:00:00'
$dates[] = date('Y-m-d', $date);
$date = strtotime('+1 day', $date);
}
------------------------------------------------------------------------
[2017-01-16 17:19:09] heiglandreas@php.net
Looks like the "midnight -1 day" doesn't subtract 1 day but 24 hours. As DST was
introduced on the 2nd of Okt. 2016 in Sydney the 2nd of Okt. only had 23 hours so subtracting 24
hours will result in the 1st of Oct 23:00:00.
DateTime-objects seem at first glance to be correct in that:
$time_now= strtotime( "02-10-2016 00:30:00");
$end_time = new DateTime(date('c',$time_now)." midnight - 1 day");
var_Dump($end_time->format('c'));
// string(25) "2016-10-02T00:00:00+11:00"
But looking in more detail it's also a mess here, as the 2nd of October 00:00:00 should be with
a time-offset of 10 hours and not 11 hoursâ¦
------------------------------------------------------------------------
[2016-10-06 02:37:04] mcasey at pegasustech dot com dot au
Description:
------------
It seems that strtotime is incorrectly calculating time adjustments across a DST change point.
I have tried this on 5.2.14 and 7.0.6 - same failure in both cases
The results of the code below, the start time should be 00:00:00 of the day before.
In Sydney Australia, time went forward at 2 am on the 2nd of October.
Using the -1 days feature of strtotime from the 3rd October at 00:00:00 returns
1st October 23:00:00 but should be 2 October 00:00:00
See results of program below.
Line 2 of the result shows Start: 2016-10-01 23:00:00 when it should be Start: 2016-10-02 00:00:00
Test script:
---------------
<?php
date_default_timezone_set ('Australia/Sydney');
#date_default_timezone_set ('America/Los_Angeles');
$time_now= strtotime( "02-10-2016 00:30:00");
$end_time = strtotime(date('c',$time_now)." midnight");
$start_time = strtotime(date('c',$time_now)." midnight -1 days");
echo "\nNow: ".date('Y-m-d H:i:s',$time_now)."< Start:
".date('Y-m-d H:i:s' ,$start_time)."< End: ".date('Y-m-d
H:i:s' ,$end_time)."<\n\n";
$time_now= strtotime( "03-10-2016 00:30:00");
$end_time = strtotime(date('c',$time_now)." midnight");
$start_time = strtotime(date('c',$time_now)." midnight -1 days");
echo "Now: ".date('Y-m-d H:i:s',$time_now)."< Start:
".date('Y-m-d H:i:s' ,$start_time)."< End: ".date('Y-m-d
H:i:s' ,$end_time)."<\n\n";
$time_now= strtotime( "04-10-2016 00:30:00");
$end_time = strtotime(date('c',$time_now)." midnight");
$start_time = strtotime(date('c',$time_now)." midnight -1 days");
echo "Now: ".date('Y-m-d H:i:s',$time_now)."< Start:
".date('Y-m-d H:i:s' ,$start_time)."< End: ".date('Y-m-d
H:i:s' ,$end_time)."<\n\n";
?>
Expected result:
----------------
Now: 2016-10-02 00:30:00< Start: 2016-10-01 00:00:00< End: 2016-10-02 00:00:00<
Now: 2016-10-03 00:30:00< Start: 2016-10-02 00:00:00< End: 2016-10-03 00:00:00<
Now: 2016-10-04 00:30:00< Start: 2016-10-03 00:00:00< End: 2016-10-04 00:00:00<
Actual result:
--------------
Now: 2016-10-02 00:30:00< Start: 2016-10-01 00:00:00< End: 2016-10-02 00:00:00<
Now: 2016-10-03 00:30:00< Start: 2016-10-01 23:00:00< End: 2016-10-03 00:00:00<
Now: 2016-10-04 00:30:00< Start: 2016-10-03 00:00:00< End: 2016-10-04 00:00:00<
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=73255&edit=1