php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73138 strtotime miscalculates when exiting DST with relative time
Submitted: 2016-09-21 17:28 UTC Modified: 2021-10-01 16:09 UTC
From: z dot himdi at bita dot nl Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.6.26 OS: Windows 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: z dot himdi at bita dot nl
New email:
PHP Version: OS:

 

 [2016-09-21 17:28 UTC] z dot himdi at bita dot nl
Description:
------------
strtotime does not calculate correctly when adding or subtracting time relatively while exiting DST.



Test script:
---------------
date_default_timezone_set("Europe/Amsterdam");

echo strtotime('+ 1 second', 1477789199);
// exiting DST in October, echoes 1477792800 in stead of 1477789200

echo strtotime('+ 1 second - 1 second', 1477789199);
// exiting and re-entering DST, echoes 1477792799 in stead of 1477789199

echo strtotime('- 1 second', 1459040400);
// exiting DST in March, echoes 1459043999 in stead of 1459040399


Expected result:
----------------
see the comments in the test script

Actual result:
--------------
one hour of unwanted difference

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-21 20:35 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Package: *General Issues +Package: Date/time related -Assigned To: +Assigned To: derick
 [2016-09-21 20:35 UTC] bwoebi@php.net
Related to bug #30532

This bug had been marked as fixed while not being fixed at all; the test (ext/date/tests/bug30532.phpt) is using the *actual* result instead of the *expected* result in the --EXPECT-- section, for some reason?

Most crucially:

echo date('r', strtotime('+ 0 second', 1477789199));

outputs:

Sun, 30 Oct 2016 02:59:59 +0100

which is ... exactly one hour later, while we, in fact, did not change anything to the time. (I very much hope "+ 0 second" is supposed to be a no-op!)
 [2021-10-01 16:09 UTC] cmb@php.net
-Status: Assigned +Status: Duplicate -Assigned To: derick +Assigned To: cmb
 [2021-10-01 16:09 UTC] cmb@php.net
> This bug had been marked as fixed while not being fixed at all;
> the test (ext/date/tests/bug30532.phpt) is using the *actual*
> result instead of the *expected* result in the --EXPECT-- section,
> for some reason?

Yes, because there are *two* 2004-10-31T02:00:00 for
America/New_York; which one should be chosen?  In this case
2004-10-31T02:00:00-0400 would be the preferable choice, but this
is not how ext/date nor Gnu date works:

$ TZ=America/New_York date -d'2004-10-31 +2 hours' -Iseconds
2004-10-31T01:00:00-05:00

Blame that on DST which is the wrong way to address the problem.

Anyhow, there was a related fix for the other report in PHP
5.1.0[1] regarding the first section.

Other than that, this is a duplicate of bug #68549.

[1] <https://3v4l.org/B2S2K>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC