Bug #54145 [Com]: DateTime->add is not affected by DST changes

From: Date: Thu, 03 Mar 2011 14:49:49 +0000
Subject: Bug #54145 [Com]: DateTime->add is not affected by DST changes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159200@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54145&edit=1

 ID:                 54145
 Comment by:         giorgio dot liscio at email dot it
 Reported by:        giorgio dot liscio at email dot it
 Summary:            DateTime->add is not affected by DST changes
 Status:             Bogus
 Type:               Bug
 Package:            Date/time related
 Operating System:   all?
 PHP Version:        5.3.5
 Block user comment: N
 Private report:     N

 New Comment:

ok, this is right, now I understand
thank you, i'm sorry for bogus!


Previous Comments:
------------------------------------------------------------------------
[2011-03-03 15:31:57] 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:23:59] 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:05:18] 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 05:28:52] 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 02:03:27] 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

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=54145


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54145&edit=1


Thread (7 messages)

« previous php.bugs (#159200) next »