php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81660 DateTimeZone::getTransitions() returns invalid data
Submitted: 2021-11-26 06:49 UTC Modified: 2021-12-14 12:47 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: kenji dot uui at gmail dot com Assigned: derick (profile)
Status: Duplicate Package: Date/time related
PHP Version: 8.1.0 OS: macOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
29 - 2 = ?
Subscribe to this entry?

 
 [2021-11-26 06:49 UTC] kenji dot uui at gmail dot com
Description:
------------
DateTimeZone::getTransitions() changed between PHP 8.0.13 and 8.1.0. 


Test script:
---------------
<?php

$tz = new DateTimeZone('America/Chicago');
$start = 1293861600;
$end = 1357020000;
$transitions = $tz->getTransitions($start, $end);
var_dump($transitions);

Expected result:
----------------
array(5) {
  [0]=>
  array(5) {
    ["ts"]=>
    int(1293861600)
    ["time"]=>
    string(24) "2011-01-01T06:00:00+0000"
    ["offset"]=>
    int(-21600)
    ["isdst"]=>
    bool(false)
    ["abbr"]=>
    string(3) "CST"
  }
  [1]=>
  array(5) {
    ["ts"]=>
    int(1300003200)
    ["time"]=>
    string(24) "2011-03-13T08:00:00+0000"
    ["offset"]=>
    int(-18000)
    ["isdst"]=>
    bool(true)
    ["abbr"]=>
    string(3) "CDT"
  }
  [2]=>
  array(5) {
    ["ts"]=>
    int(1320562800)
    ["time"]=>
    string(24) "2011-11-06T07:00:00+0000"
    ["offset"]=>
    int(-21600)
    ["isdst"]=>
    bool(false)
    ["abbr"]=>
    string(3) "CST"
  }
  [3]=>
  array(5) {
    ["ts"]=>
    int(1331452800)
    ["time"]=>
    string(24) "2012-03-11T08:00:00+0000"
    ["offset"]=>
    int(-18000)
    ["isdst"]=>
    bool(true)
    ["abbr"]=>
    string(3) "CDT"
  }
  [4]=>
  array(5) {
    ["ts"]=>
    int(1352012400)
    ["time"]=>
    string(24) "2012-11-04T07:00:00+0000"
    ["offset"]=>
    int(-21600)
    ["isdst"]=>
    bool(false)
    ["abbr"]=>
    string(3) "CST"
  }
}


Actual result:
--------------
array(1) {
  [0]=>
  array(5) {
    ["ts"]=>
    int(1293861600)
    ["time"]=>
    string(24) "2011-01-01T06:00:00+0000"
    ["offset"]=>
    int(-18000)
    ["isdst"]=>
    bool(true)
    ["abbr"]=>
    string(3) "CDT"
  }
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-26 09:46 UTC] patrickallaert@php.net
-Assigned To: +Assigned To: derick
 [2021-11-26 10:00 UTC] cmb@php.net
Confirmed: <https://3v4l.org/MtJ2X>.

<https://www.timeanddate.com/time/zone/usa/chicago> agrees with
behavior prior to PHP 8.1.0.
 [2021-11-26 14:23 UTC] antonino dot spampinato86 at gmail dot com
Currently @derick's patch from php> = 8.1.0beta3 without parameters returns from one (if it has never used transition) or more transition arrays.
Otherwise with parameter it returns the last transition period of the year UTC which is different from its local timezone if different from UTC. 2010-12-31 00:00:00 America/Chicago and 2011-01-01 06:00:00 UTC.
Do you want to calculate the time of the year between two dates?
that is to say:

array(5) {
    ["ts"]=>
    int(1300003200)
    ["time"]=>
    string(24) "2011-03-13T08:00:00+0000"
    ["offset"]=>
    int(-18000)
    ["isdst"]=>
    bool(true)
    ["abbr"]=>
    string(3) "CDT"
  }

relative to fix bug 80963
 [2021-12-08 00:38 UTC] kenji dot uui at gmail dot com
> Do you want to calculate the time of the year between two dates?

No. 

Our use case is just wanting to know it is daylight saving time or not.
We use DateTime::format('I').
 [2021-12-14 12:47 UTC] cmb@php.net
-Status: Assigned +Status: Duplicate
 [2021-12-14 12:47 UTC] cmb@php.net
I'm closing this as duplicate of <https://github.com/php/php-src/issues/7752>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC