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: -
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:
Status: Open Package: Date/time related
PHP Version: Irrelevant OS: Windows 7
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: ryosuke_i_628 at yahoo dot co dot jp
New email:
PHP Version: OS:

 

 [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

 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 04:01:23 2020 UTC