php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75790 DateTimeZone::getTransitions(start,end)[0] is incorrect
Submitted: 2018-01-10 08:15 UTC Modified: 2018-01-11 01:57 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: z dot dacto at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 5.6.33 OS: Linux debian 3.16.0-4-amd64
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: z dot dacto at gmail dot com
New email:
PHP Version: OS:

 

 [2018-01-10 08:15 UTC] z dot dacto at gmail dot com
Description:
------------
When optional argument `$timestamp_begin` is provided to `DateTimeZone::getTransitions` the first transition returned assumes a `ts` value of `$timestamp_begin` and a `time` value formatted from `$timestamp_begin`.

The first transition should instead be the one active during `$timestamp_begin`.

Test script:
---------------
<!DOCTYPE html>
<html>
<body>
<pre>
<?php

$tz = new DateTimeZone('America/Los_Angeles');

# 1509872300 = 11-05-2017T8:58:20+0000
# 1515570270 = 01-10-2018T7:44:30+0000

$transition = $tz->getTransitions(1509872300, 1515570270);
print_r($transition);

?>
</pre>
</body>
</html>

Expected result:
----------------
Array
(
    [0] => Array
        (
            [ts] => 1489312800
            [time] => 2017-03-12T10:00:00+0000
            [offset] => -25200
            [isdst] => 1
            [abbr] => PDT
        )

    [1] => Array
        (
            [ts] => 1509872400
            [time] => 2017-11-05T09:00:00+0000
            [offset] => -28800
            [isdst] => 
            [abbr] => PST
        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [ts] => 1509872300
            [time] => 2017-11-05T08:58:20+0000
            [offset] => -25200
            [isdst] => 1
            [abbr] => PDT
        )

    [1] => Array
        (
            [ts] => 1509872400
            [time] => 2017-11-05T09:00:00+0000
            [offset] => -28800
            [isdst] => 
            [abbr] => PST
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-10 10:14 UTC] derick@php.net
-Type: Bug +Type: Documentation Problem
 [2018-01-10 10:14 UTC] derick@php.net
This is by design, but it does not seem documented. Marking it as a "Documentation Problem".
 [2018-01-11 01:57 UTC] z dot dacto at gmail dot com
-Summary: DateTimeZone::getTransitions(start,end)->ts is incorrect +Summary: DateTimeZone::getTransitions(start,end)[0] is incorrect
 [2018-01-11 01:57 UTC] z dot dacto at gmail dot com
While it is by design, is this the correct behavior since the first element isn't actually a valid timezone transition?

Aside from the what I mentioned in the original description, an alternative interpretation for DateTimeZone::getTransitions(start,end) would be such that only timezone transitions that happen between start and end would be included in the resulting array. Applied to the Test SCript, this should then result in:

Array
(
    [0] => Array
        (
            [ts] => 1509872400
            [time] => 2017-11-05T09:00:00+0000
            [offset] => -28800
            [isdst] => 
            [abbr] => PST
        )

)
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Dec 12 14:01:26 2018 UTC