|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-06-02 11:20 UTC] 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;
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 10:00:01 2026 UTC |
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