php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61530 DateTimeInterval subtracting wrong on summertime Threshold
Submitted: 2012-03-27 16:31 UTC Modified: 2014-01-17 14:57 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: nicolas dot douillet at gmail dot com Assigned: derick
Status: Assigned Package: Date/time related
PHP Version: 5.3.10 OS: Debian / Linux
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-03-27 16:31 UTC] nicolas dot douillet at gmail dot com
Description:
------------
If you're using a timezone, like Europe/Paris, with summer and winter times, you 
will obtain a wrong result when adding and subtracting a time interval on a date 
at summertime threshold.

I fixed that issue by making all operations on GMT timezone.

Test script:
---------------
date_default_timezone_set('Europe/Paris');

/*
   Get a time just on the threshold
*/

$d = new DateTime("2012-03-25 03:00:00");
echo $d->format(DateTime::RFC2822) . "\n";

/*
    Substract one hour
*/

$i = new DateInterval("PT1H");
$d->sub($i);
echo $d->format(DateTime::RFC2822) . "\n";

Expected result:
----------------
Sun, 25 Mar 2012 03:00:00 +0200
Sun, 25 Mar 2012 01:00:00 +0100

Actual result:
--------------
Sun, 25 Mar 2012 03:00:00 +0200
Sun, 25 Mar 2012 03:00:00 +0200

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-16 23:51 UTC] kavi at postpro dot net
We can verify on 5.3.3 if that's worth anything.  This is a problem, please fix 
it.
 [2014-01-17 13:59 UTC] jimmyraynor at gmail dot com
Ran into this issue with PHP 5.4.17 (cli) (built: Aug 25 2013 02:03:38) 
TZ: date.timezone => America/Santiago
Between dates 2013-09-08 and 2014-01-15
Using OS: Mac Os 10.9

Funny fact is that I have three servers doing the same operation and only my mac returns different.
 [2014-01-17 14:57 UTC] derick@php.net
-Assigned To: +Assigned To: derick
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 20:02:01 2014 UTC