php-src icon indicating copy to clipboard operation
php-src copied to clipboard

DateTimeZone::getTransitions() returns insufficient data

Open mvorisek opened this issue 4 years ago • 11 comments

Description

The following code:

var_dump(
    (new \DateTime('2203-10-05 15:05:37.180157', new \DateTimeZone('America/Los_Angeles')))
    ->getTimestamp()
);

https://3v4l.org/HpVAr

produces different result on PHP 8.1 vs PHP 7.4/8.0

it is from our failing unit test, what result is correct and any plain to bugfix in either PHP 8.1 or the PHP 8.0 and lower?

PHP Version

PHP 8.1.0

Operating System

linux

mvorisek avatar Dec 10 '21 16:12 mvorisek

It seems the bug starts with 2100-03-14 03:00:00 while 2100-03-14 02:59:59 works fine.

On PHP 8.1 2100-03-14 03:00:00 under the America/Los_Angeles time zone has the same timestamp as2100-03-14 02:00:00.

jellynoone avatar Dec 10 '21 17:12 jellynoone

It seems that transitions are not tracked far in the future, and that neither version is totally correct; apparently, prior to PHP 8.1.0 DST was always assumed, while as of PHP 8.1.0 standard time is assumed (what would make more sense).

@derickr, can you please clarify?

cmb69 avatar Dec 10 '21 17:12 cmb69

https://3v4l.org/1Oe8V

All transitions in the future except for the next seem to be gone. (might be by design, not sure)

iluuu1994 avatar Dec 10 '21 18:12 iluuu1994

I'm going to have to check this, as the new code should definitely handle this correctly.

derickr avatar Dec 10 '21 18:12 derickr

Can some one tell when this issue will be fixed? We added now hacks in our code base for getting now the correct timestamp.

DevSysEngineer avatar Feb 17 '22 16:02 DevSysEngineer

There is apparently something wrong with reading the timezone DB in PHP 8.1. Although both have identical timezonedb.h files, for America/Los_Angeles, PHP 8.0 reads timelib_tzinfo->64bit.timecnt == 186, while PHP 8.1 reads timelib_tzinfo->64bit.timecnt == 125.

@derickr, any idea what change in timelib may have caused this?

cmb69 avatar Feb 18 '22 13:02 cmb69

I'm going to have to check this, as the new code should definitely handle this correctly.

https://bugs.php.net/bug.php?id=80963 It's broken. @cmb @derickr without if !isset($is_dst) || !$is_dst https://3v4l.org/es6E4

hormus avatar Mar 24 '22 21:03 hormus

Interestingly, I'm seeing different results with different installations. Consider the following command:

php -r "var_dump((new \DateTimeZone('Europe/Amsterdam'))->getTransitions(1593186495, 1711813695));"

It returns 7 records on:

  • php:8.0 (docker)
  • 8.1.4 sury debian install

It returns 1 record on:

  • php:8.1 (docker)

bobvandevijver avatar Mar 28 '22 16:03 bobvandevijver

Hi, there are bunch of things going on here.

  • First of all, the PHP 8.1.x result is correct in @mvorisek example.
  • Before PHP 8.1, transitions were only tracked until 2100. Anything after that, used the last rule. For Los_Angeles, that would have been UTC-8 (incorrectly).
  • In PHP 8.1 and later, timelib has implemented support for POSIX TZ strings, which allow to calculate transitions with the existing rules.
  • Operating Systems changed their tzdata format from "fat" to "small", and the latter only includes transitions up until the last change in DST rules. For anything beyond that, POSIX TZ strings must now be used. (This explains the discrepancies between different distributions of the same PHP version)
  • This means that it can now knows about DST in 2203, where UTC-7 applies: string(25) "2203-10-05T15:05:37-07:00"
  • @iluuu1994's comment (https://github.com/php/php-src/issues/7752#issuecomment-991181138) is indeed a bug, in where transitions were not returned if an initial timestamp was passed to getTransions, which lay after the last transition (from the slim files). It is likely the same issue as in #8108.

derickr avatar Apr 01 '22 11:04 derickr

How many years left for the 8.2.6 release including this important bug fix for date/time?

UTC->Europe/Berlin 7.4 date correct (5.5.2023) 7.4 -> 8.1.5 = date wrong (6.5.2023) 7.4 -> 8.0.25 = date correct (6.5.2023)

You are producing so many headaches, work and money lost by not releasing the fix for over a year for many companies.

reloxx13 avatar May 05 '23 09:05 reloxx13

@reloxx13 The bug reported here was fixed. If you think you have a new bug then create a new issue for it.

damianwadley avatar May 05 '23 15:05 damianwadley