php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74374 DateTime::sub doesn't work
Submitted: 2017-04-05 11:16 UTC Modified: 2017-04-05 11:48 UTC
From: dualsword at mail dot ru Assigned:
Status: Duplicate Package: Date/time related
PHP Version: 7.1.3 OS: ubuntu 16.04 Desktop
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dualsword at mail dot ru
New email:
PHP Version: OS:

 

 [2017-04-05 11:16 UTC] dualsword at mail dot ru
Description:
------------
---
Its work with date '2011-03-27 03:59:59'
---


Test script:
---------------
$d = new DateTime('2011-03-27 03:59:59');
var_dump(['$d is' => $d]);
$d_new = $d->sub(new DateInterval('PT1H'));
var_dump(['$d_new is' => $d_new]);

Expected result:
----------------
array (size=1)
  '$d_new is' => 
    object(DateTime)[1]
      public 'date' => string '2011-03-27 02:59:59.000000' (length=26)
      public 'timezone_type' => int 3
      public 'timezone' => string 'Europe/Moscow' (length=13)

Actual result:
--------------
array (size=1)
  '$d_new is' => 
    object(DateTime)[1]
      public 'date' => string '2011-03-27 03:59:59.000000' (length=26)
      public 'timezone_type' => int 3
      public 'timezone' => string 'Europe/Moscow' (length=13)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-04-05 11:32 UTC] derick@php.net
-Summary: DateTime::sub dosnt work +Summary: DateTime::sub doesn't work -Status: Open +Status: Not a bug
 [2017-04-05 11:32 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

'2011-03-27 02:59:59.000000' does not exist, due to a change in timezone rules:

Europe/Moscow  Sat Mar 26 22:59:59 2011 UT = Sun Mar 27 01:59:59 2011 MSK isdst=0 gmtoff=10800
Europe/Moscow  Sat Mar 26 23:00:00 2011 UT = Sun Mar 27 03:00:00 2011 MSK isdst=0 gmtoff=14400


And because of that, PHP overflows to the next hour.
 [2017-04-05 11:48 UTC] requinix@php.net
-Status: Not a bug +Status: Duplicate
 [2017-04-05 11:48 UTC] requinix@php.net
03:59 UTC+4 -1h should result in 01:59 UTC+3, so I think that makes this an example of the DST transition problem and a duplicate of @heiglandreas's bug #74274.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC