Bug #75685 [NEW]: DatePeriod returns incorrect iterator count when DST ends
| From: | markus dot weiland at mapudo dot com | Date: | Thu, 14 Dec 2017 10:00:14 +0000 |
| Subject: | Bug #75685 [NEW]: DatePeriod returns incorrect iterator count when DST ends | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-213092@lists.php.net to get a copy of this message | ||
From: markus dot weiland at mapudo dot com
Operating system: Linux
PHP version: 7.1.12
Package: Date/time related
Bug Type: Bug
Bug description:DatePeriod returns incorrect iterator count when DST ends
Description:
------------
DatePeriod allows calculating the number of occurrences of a given
interval in the specified period (from start to end).
For example, we can obtain the number of hours for each calendar day in
the year with
iterator_count() and print out the number if it is not
24.
Using the example code, we can determine that one hour is missing in
2017 when using this method of calculation and a timezone other than
UTC.
Test script:
---------------
$interval = new \DateInterval('PT1H'); // plus time one hour
$i = 0;
while ($i < 366) {
$start = new \DateTime('2017-01-01 00:00:00', new
\DateTimeZone('Europe/Berlin'));
$start->add(new \DateInterval('P'.$i.'D'));
$end = new \DateTime('2017-01-02 00:00:00', new
\DateTimeZone('Europe/Berlin'));
$end->add(new \DateInterval('P'.$i.'D'));
$period = new \DatePeriod($start, $interval, $end);
$diff = iterator_count($period);
if ($diff != 24) {
echo sprintf('%s, %d', $start->format(\DateTime::ISO8601),
$diff);
}
$i++;
}
Expected result:
----------------
We expect to have two values printed to console (i.e. there is one
iterator with 23 counts and one with 25 counts):
2017-03-26T00:00:00+0100, 23
2017-10-29T00:00:00+0100, 25
The first, when daylight savings time (DST) starts, the second when DST
ends.
This means that the total number of hours in 2017 is 8760 which is
equivalent to 365 days of 24 hours.
Actual result:
--------------
Only one value is printed to console:
2017-03-26T00:00:00+0100, 23
This means that the total number of hours in 2017 is 8759 which is _not_
equivalent to 365 days of 24 hours. In other words, one hour is missing,
even though 2017 is a "regular" year without leap days, leap seconds,
etc..
In contrast, when using UTC as timezone in the example code, the year
has 8760 hours as expected.
Double-checking with DateTimeZone::getTransitions() for
Europe/Berlin shows that a transition on 2017-10-29 is correctly
defined.
--
Edit bug report at https://bugs.php.net/bug.php?id=75685&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75685&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75685&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75685&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75685&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75685&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75685&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75685&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75685&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75685&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75685&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75685&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75685&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75685&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75685&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75685&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75685&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75685&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75685&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75685&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75685&r=mysqlcfg