php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54145 DateTime->add is not affected by DST changes
Submitted: 2011-03-03 01:51 UTC Modified: 2011-03-03 15:31 UTC
From: giorgio dot liscio at email dot it Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.5 OS: all?
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: giorgio dot liscio at email dot it
New email:
PHP Version: OS:

 

 [2011-03-03 01:51 UTC] giorgio dot liscio at email dot it
Description:
------------
hi
when dateinterval walks across a dst change 

$a = DateTime::createFromFormat
(
"d/m/Y H:i:s e",
"03/03/2011 01:38:25 europe/rome"
);

$a = $a->add(new DateInterval("P1M")); // now we have DST in italy

should add +1 hour too, I think, but it doesn't

thank you


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-03 02:03 UTC] giorgio dot liscio at email dot it
proposed solution:
->add and ->sub methods should internally convert to UTC before add or sub the interval, then should re-set the original timezone
 [2011-03-03 05:28 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2011-03-03 05:28 UTC] dtajchreber@php.net
david@copenhagen:~/test$ php -v
PHP 5.3.6-dev (cli) (built: Feb 26 2011 23:29:38) (DEBUG)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
david@copenhagen:~/test$ cat t.php 
<?php

date_default_timezone_set('America/Chicago');

$d = new DateTime('03-march-2011');
var_dump($d->format('c'));
$d->add(new DateInterval('P1M'));
var_dump($d->format('c'));

date_default_timezone_set('Europe/Rome');

$d = new DateTime('03-march-2011');
var_dump($d->format('c'));
$d->add(new DateInterval('P1M'));
var_dump($d->format('c'));

david@copenhagen:~/test$ php t.php 
string(25) "2011-03-03T00:00:00-06:00"
string(25) "2011-04-03T00:00:00-05:00"
string(25) "2011-03-03T00:00:00+01:00"
string(25) "2011-04-03T00:00:00+02:00"
david@copenhagen:~/test$
 [2011-03-03 15:05 UTC] giorgio dot liscio at email dot it
so what? in your code this is working, right?
in this case i will investigate on the mine
 [2011-03-03 15:23 UTC] giorgio dot liscio at email dot it
here is it

with your testcase, using time  too in the constructor, the time itself is not update


date_default_timezone_set('America/Chicago');

$d = new \DateTime('03-march-2011 10:10:10');
var_dump($d->format('c'));
$d->add(new \DateInterval('P1M'));
var_dump($d->format('c'));

date_default_timezone_set('Europe/Rome');

$d = new \DateTime('03-march-2011 10:10:10');
var_dump($d->format('c'));
$d->add(new \DateInterval('P1M'));
var_dump($d->format('c'));
 [2011-03-03 15:31 UTC] derick@php.net
The time is not supposed to update. One month is a month, not 31 (or 30) * 86400 seconds. You will also see that "P1D" adds one to the day, and does not bother with the hours. A day at the DST change over is simply 25 hours (or 23 hours).
 [2011-03-03 15:49 UTC] giorgio dot liscio at email dot it
ok, this is right, now I understand
thank you, i'm sorry for bogus!
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC