Bug->Doc #72470 [Opn]: modify() doesn't take into account DST changes
| From: | requinix@php.net | Date: | Wed, 22 Jun 2016 20:10:36 +0000 |
| Subject: | Bug->Doc #72470 [Opn]: modify() doesn't take into account DST changes | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-13589@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72470&edit=1
ID: 72470
Updated by: requinix@php.net
Reported by: matthieux dot dekamen at gmail dot com
Summary: modify() doesn't take into account DST changes
Status: Open
-Type: Bug
+Type: Documentation Problem
Package: Date/time related
PHP Version: 7.1.0alpha1
Block user comment: N
Private report: N
New Comment:
add() and modify() have different meanings. After all, two methods that did the same thing would be
a bit odd.
modify() will literally alter the date/time according to what you tell it. If you say "+23
hours" then it will add 23 to the "hour" value and adjust for overflow. 1000 + 23
hours = 3300 -> 0900 the next day.
add() does what you are expecting: add an interval of time. It's generally the same thing,
except during a DST transition the interval will be appear shorter or longer on the clock. 23 hours
after 1000 = 0900 the next day - 1 hour "lost" due to the DST transition = 0800 the next
day.
Which gives me an idea for a bug report.
Previous Comments:
------------------------------------------------------------------------
[2016-06-22 19:58:33] matthieux dot dekamen at gmail dot com
Description:
------------
modify() doesn't take into account DST changes.
For example, if I add 23 hours with DateInterval where a DST change occurs:
echo date_default_timezone_get(); // prints Europe/Amsterdam
$dateTime = new DateTime('2016-10-29 10:00:00');
$dateTime->add(new DateInterval('PT23H'));
I get the expected result: 2016-10-30T08:00:00+01:00 (clock went backwards for 1 hour)
But if I add 23 hours with the modify() function on the same date:
$dateTime = new DateTime('2016-10-29 10:00:00');
$dateTime->modify('+ 23 hours');
I get: 2016-10-30T09:00:00+01:00
As you see the result here is different. modify() seems to not take into account DST changes.
https://3v4l.org/4fncr
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72470&edit=1