php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80963 DateTimeZone::getTransitions() truncated
Submitted: 2021-04-17 15:16 UTC Modified: 2021-04-18 13:52 UTC
From: thekid@php.net Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: master-Git-2021-04-17 (Git) OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thekid@php.net
New email:
PHP Version: OS:

 

 [2021-04-17 15:16 UTC] thekid@php.net
Description:
------------
DateTimeZone::getTransitions() changed between PHP 8.0.3 and current PHP 8.1.0-dev. Most probably related to https://github.com/php/php-src/commit/091c0920b9db057a54dc43ece6e864bce6818d5e

Test script:
---------------
php -r '$tz= new DateTimeZone("Europe/London"); $t= $tz->getTransitions(); var_dump(sizeof($t), end($t));'

Expected result:
----------------
int(243)
array(5) {
  ["ts"]=>
  int(2140045200)
  ["time"]=>
  string(24) "2037-10-25T01:00:00+0000"
  ["offset"]=>
  int(0)
  ["isdst"]=>
  bool(false)
  ["abbr"]=>
  string(3) "GMT"
}

Actual result:
--------------
int(160)
array(5) {
  ["ts"]=>
  int(828234000)
  ["time"]=>
  string(24) "1996-03-31T01:00:00+0000"
  ["offset"]=>
  int(3600)
  ["isdst"]=>
  bool(true)
  ["abbr"]=>
  string(3) "BST"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-17 15:45 UTC] thekid@php.net
-Assigned To: +Assigned To: derick
 [2021-04-17 15:45 UTC] thekid@php.net
For Europe/Berlin and Europe/London, the array returned "stops" at 1996
For America/New_York, the latest transition returned is from 2007

# PHP 8.1-dev
$ php -r '$tz= new DateTimeZone("America/New_York"); $t= $tz->getTransitions(); var_dump($t);' | grep 'string(24)' | sort -r | head -5
    string(24) "2007-03-11T07:00:00+0000"
    string(24) "2006-10-29T06:00:00+0000"
    string(24) "2006-04-02T07:00:00+0000"
    string(24) "2005-10-30T06:00:00+0000"
    string(24) "2005-04-03T07:00:00+0000"

# PHP 8.0.3
$ php -r '$tz= new DateTimeZone("America/New_York"); $t= $tz->getTransitions(); var_dump($t);' | grep 'string(24)' | sort -r | head -5
    string(24) "2037-11-01T06:00:00+0000"
    string(24) "2037-03-08T07:00:00+0000"
    string(24) "2036-11-02T06:00:00+0000"
    string(24) "2036-03-09T07:00:00+0000"
    string(24) "2035-11-04T06:00:00+0000"
 [2021-04-17 15:54 UTC] thekid@php.net
When given min and max timestamps, we simply get the passed-in timestamp back in UTC

# PHP 8.1-dev
php-r '$tz= new DateTimeZone("America/Los_Angeles"); $t= $tz->getTransitions(time(), time() + 31536000); var_dump($t);' | grep 'string(24)'
    string(24) "2021-04-17T15:50:22+0000"

# PHP 8.0.3
php-r '$tz= new DateTimeZone("America/Los_Angeles"); $t= $tz->getTransitions(time(), time() + 31536000); var_dump($t);' | grep 'string(24)'
    string(24) "2021-04-17T15:52:43+0000"
    string(24) "2021-11-07T09:00:00+0000"
    string(24) "2022-03-13T10:00:00+0000"
 [2021-04-18 13:52 UTC] derick@php.net
This is a tricky one. The data format that the library uses has changed, and will now only contain a list of transitions up until the last time the *rules* changed.

For America/New_York, that was in 2007, and Europe/London, in 1996. Beyond that, the timelib library now can calculate the offset for a specific timestamp: https://github.com/derickr/timelib/blob/master/parse_tz.c#L777 and also from this new POSIX  string format through https://github.com/derickr/timelib/blob/master/parse_posix.c — What is no longer available is a list with ever single utc-offset change, which is what powered this getTransitions function.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Aug 01 08:01:24 2021 UTC