Bug #73255 [Com]: strtotime -1 day across DST change adds extra hour

From: Date: Mon, 16 Jan 2017 17:19:12 +0000
Subject: Bug #73255 [Com]: strtotime -1 day across DST change adds extra hour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-206689@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
 Comment by:         heiglandreas@php.net
 Reported by:        mcasey at pegasustech dot com dot au
 Summary:            strtotime -1 day across DST change adds extra hour
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.0Git-2016-10-06 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

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…


Previous Comments:
------------------------------------------------------------------------
[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


Thread (1 message)

  • heiglandreas@php.net
  • Unknown Message
    • heiglandreas@php.net
« previous php.bugs (#206689) next »