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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: kenji dot uui at gmail dot com
New email:
PHP Version: OS:

 

 [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: Thu Mar 28 13:01:28 2024 UTC