php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69186 Unexpected behavior using 'back of' or 'front of' with timezone specification
Submitted: 2015-03-04 16:35 UTC Modified: 2021-10-01 14:36 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: ryosuke_i_628 at yahoo dot co dot jp Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
 [2015-03-04 16:35 UTC] ryosuke_i_628 at yahoo dot co dot jp
Description:
------------
The following formats cause strange time difference of 12 hours.

- 'back of 1 Asia/Tokyo'
- 'first of 1 Asia/Tokyo'

The test script was executed on 2015-03-05 01:34:00 +0900.

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

// Set PHP default timezone into UTC.
date_default_timezone_set('UTC');

// Checked items.
$list = [
    'now' => [
        'now' => null,
        'now Asia/Tokyo' => null,
        'Asia/Tokyo now' => null,
        'now +0900' => null,
        '+0900 now' => null,
    ],
    'next hour' => [
        'next hour' => null,
        'next hour Asia/Tokyo' => null,
        'Asia/Tokyo next hour' => null,
        'next hour +0900' => null,
        '+0900 next hour' => null,
    ],
    'front of 1' => [
        'front of 1' => null,
        'front of 1 Asia/Tokyo' => null,
        'Asia/Tokyo front of 1' => null,
        'front of 1 +0900' => null,
        '+0900 front of 1' => null,
    ],
    'back of 1' => [
        'back of 1' => null,
        'back of 1 Asia/Tokyo' => null,
        'Asia/Tokyo back of 1' => null,
        'back of 1 +0900' => null,
        '+0900 back of 1' => null,
    ],
];

// Temporarily Change computer time into 23:30:00 UTC.
exec('net start w32time');
exec('tzutil /s "UTC"');
exec('time 23:30:00');

// Test it.
array_walk_recursive($list, function (&$v, $k) {
    $v = (new \DateTime($k))->format('Y-m-d H:i:s e');
});

// Recover computer time.
exec('tzutil /s "Tokyo Standard Time"');
exec('w32tm /resync');
exec('net stop w32time');

// Output results.
print_r($list);

?>

Expected result:
----------------
Array
(
    [now] => Array
        (
            [now] => 2015-03-04 23:30:00 UTC
            [now Asia/Tokyo] => 2015-03-05 08:30:00 Asia/Tokyo
            [Asia/Tokyo now] => 2015-03-05 08:30:00 Asia/Tokyo
            [now +0900] => 2015-03-04 23:30:00 +09:00
            [+0900 now] => 2015-03-04 23:30:00 +09:00
        )

    [next hour] => Array
        (
            [next hour] => 2015-03-05 00:30:00 UTC
            [next hour Asia/Tokyo] => 2015-03-05 09:30:00 Asia/Tokyo
            [Asia/Tokyo next hour] => 2015-03-05 09:30:00 Asia/Tokyo
            [next hour +0900] => 2015-03-05 00:30:00 +09:00
            [+0900 next hour] => 2015-03-05 00:30:00 +09:00
        )

    [front of 1] => Array
        (
            [front of 1] => 2015-03-04 00:45:00 UTC
            [front of 1 Asia/Tokyo] => 2015-03-05 00:45:00 Asia/Tokyo
            [Asia/Tokyo front of 1] => 2015-03-05 00:45:00 Asia/Tokyo
            [front of 1 +0900] => 2015-03-04 00:45:00 +09:00
            [+0900 front of 1] => 2015-03-04 00:45:00 +09:00
        )

    [back of 1] => Array
        (
            [back of 1] => 2015-03-04 01:15:00 UTC
            [back of 1 Asia/Tokyo] => 2015-03-05 01:15:00 Asia/Tokyo
            [Asia/Tokyo back of 1] => 2015-03-05 01:15:00 Asia/Tokyo
            [back of 1 +0900] => 2015-03-04 01:15:00 +09:00
            [+0900 back of 1] => 2015-03-04 01:15:00 +09:00
        )

)

Actual result:
--------------
Array
(
    [now] => Array
        (
            [now] => 2015-03-04 23:30:00 UTC
            [now Asia/Tokyo] => 2015-03-05 08:30:00 Asia/Tokyo
            [Asia/Tokyo now] => 2015-03-05 08:30:00 Asia/Tokyo
            [now +0900] => 2015-03-04 23:30:00 +09:00
            [+0900 now] => 2015-03-04 23:30:00 +09:00
        )

    [next hour] => Array
        (
            [next hour] => 2015-03-05 00:30:00 UTC
            [next hour Asia/Tokyo] => 2015-03-05 09:30:00 Asia/Tokyo
            [Asia/Tokyo next hour] => 2015-03-05 09:30:00 Asia/Tokyo
            [next hour +0900] => 2015-03-05 00:30:00 +09:00
            [+0900 next hour] => 2015-03-05 00:30:00 +09:00
        )

    [front of 1] => Array
        (
            [front of 1] => 2015-03-04 00:45:00 UTC
            [front of 1 Asia/Tokyo] => 2015-03-05 12:45:00 Asia/Tokyo # Bug
            [Asia/Tokyo front of 1] => 2015-03-05 00:45:00 Asia/Tokyo
            [front of 1 +0900] => 2015-03-04 12:45:00 +09:00          # Bug
            [+0900 front of 1] => 2015-03-04 00:45:00 +09:00
        )

    [back of 1] => Array
        (
            [back of 1] => 2015-03-04 01:15:00 UTC
            [back of 1 Asia/Tokyo] => 2015-03-05 13:15:00 Asia/Tokyo  # Bug
            [Asia/Tokyo back of 1] => 2015-03-05 01:15:00 Asia/Tokyo
            [back of 1 +0900] => 2015-03-04 13:15:00 +09:00           # Bug
            [+0900 back of 1] => 2015-03-04 01:15:00 +09:00
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-01 14:36 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-10-01 14:36 UTC] cmb@php.net
This issue is fixed as of PHP 5.6.32[1].

[1] <https://3v4l.org/s3HtM>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 16:01:30 2024 UTC