Bug #74691 [Nab]: Novosibirsk Data Time Anomaly

From: Date: Sun, 04 Jun 2017 07:53:35 +0000
Subject: Bug #74691 [Nab]: Novosibirsk Data Time Anomaly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209380@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74691&edit=1

 ID:                 74691
 Updated by:         heiglandreas@php.net
 Reported by:        karpulix at ya dot ru
 Summary:            Novosibirsk Data Time Anomaly
 Status:             Not a bug
 Type:               Bug
 Package:            Date/time related
 Operating System:   All
 PHP Version:        7.1.5
 Block user comment: N
 Private report:     N

 New Comment:

The diff method works pretty well, you are only looking at a fraction of the result though.

When you look at https://3v4l.org/6eiD6 you will notice that
the difference is 1 year, 11 months, 30 days and 23 hours. Due to the DST-change it's 1 hour
short of being two years!


Previous Comments:
------------------------------------------------------------------------
[2017-06-02 12:14:36] karpulix at ya dot ru

Because of this, the method works incorrectly "diff" from "DateTime class"
-----
Из-за этого неверно работает
метод "diff" класса DateTime


//correct:
$dataTimeZone = new DateTimeZone("Europe/Moscow");
    $datetime = new DateTime('02.06.2015',$dataTimeZone);
    $now = new DateTime('02.06.2017',$dataTimeZone);
    $interval = $datetime->diff($now);
    $fullYear = (int)$interval->format("%Y");
echo $fullYear;
// 2 - its correct

//incorrect
$dataTimeZone = new DateTimeZone("Asia/Novosibirsk");
    $datetime = new DateTime('02.06.2015',$dataTimeZone);
    $now = new DateTime('02.06.2017',$dataTimeZone);
    $interval = $datetime->diff($now);
    $fullYear = (int)$interval->format("%Y");
echo $fullYear;
// 1 - its incorrect

------------------------------------------------------------------------
[2017-06-02 11:33:26] derick@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

Actually, I see what happens.

There is no bug.

Unlike Moscow and New_York, Novosibirsk changed GMT offsets between June 2nd,2015 and June 2nd,
2017.

Moscow:
Europe/Moscow  Sat Mar 26 23:00:00 2011 UT = Sun Mar 27 03:00:00 2011 MSK isdst=0 gmtoff=14400
Europe/Moscow  Sat Oct 25 21:59:59 2014 UT = Sun Oct 26 01:59:59 2014 MSK isdst=0 gmtoff=14400
Europe/Moscow  Sat Oct 25 22:00:00 2014 UT = Sun Oct 26 01:00:00 2014 MSK isdst=0 gmtoff=10800

(Last change was in 2014 to UTC+3)

New York
UTC+3

Novosibirsk:

Asia/Novosibirsk  Sat Mar 26 20:00:00 2011 UT = Sun Mar 27 03:00:00 2011 +07 isdst=0 gmtoff=25200
Asia/Novosibirsk  Sat Oct 25 18:59:59 2014 UT = Sun Oct 26 01:59:59 2014 +07 isdst=0 gmtoff=25200
Asia/Novosibirsk  Sat Oct 25 19:00:00 2014 UT = Sun Oct 26 01:00:00 2014 +06 isdst=0 gmtoff=21600
Asia/Novosibirsk  Sat Jul 23 19:59:59 2016 UT = Sun Jul 24 01:59:59 2016 +06 isdst=0 gmtoff=21600
Asia/Novosibirsk  Sat Jul 23 20:00:00 2016 UT = Sun Jul 24 03:00:00 2016 +07 isdst=0 gmtoff=25200

UTC+6 in 2015, and UTC+7 in 2017. That's why you get the 3600 seconds difference.

------------------------------------------------------------------------
[2017-06-02 11:29:10] derick@php.net

Can you add the Actual and Expected output please?

------------------------------------------------------------------------
[2017-06-02 11:20:34] karpulix at ya dot ru

Description:
------------
Incorrect time interval in the Novosibirsk time zone. The problem is easy to reproduce on any server
----------------------
Некорректный интервал
времени Новосибирском
часовом поясе. Проблему
легко воспроизвести на
любом сервере

Test script:
---------------
$datetime_start = new DateTime('02.06.2015',new DateTimeZone("Europe/Moscow"));
$datetime_end = new DateTime('02.06.2017',new DateTimeZone("Europe/Moscow"));
print_r($datetime_end->getTimestamp() - $datetime_start->getTimestamp());
echo PHP_EOL;
$datetime_start = new DateTime('02.06.2015',new
DateTimeZone("America/New_York"));
$datetime_end = new DateTime('02.06.2017',new DateTimeZone("America/New_York"));
print_r($datetime_end->getTimestamp() - $datetime_start->getTimestamp());
echo PHP_EOL;
$datetime_start = new DateTime('02.06.2015',new
DateTimeZone("Asia/Novosibirsk"));
$datetime_end = new DateTime('02.06.2017',new DateTimeZone("Asia/Novosibirsk"));
print_r($datetime_end->getTimestamp() - $datetime_start->getTimestamp());
echo PHP_EOL;



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=74691&edit=1


Thread (9 messages)

« previous php.bugs (#209380) next »