Last active
May 23, 2018 23:11
-
-
Save artoodetoo/2915dc07d1904a173e76f0bf5966e00f to your computer and use it in GitHub Desktop.
DST problem demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For timezone 'Australia/Melbourne': | |
2018-03-31 10:00:00 | |
+ 24*60*60 == 2018-04-01 09:00:00 | |
strtotime(+1 day) == 2018-04-01 10:00:00 | |
DateTime->add(1d) == 2018-04-01 10:00:00 | |
2018-10-06 10:00:00 | |
+ 24*60*60 == 2018-10-07 11:00:00 | |
strtotime(+1 day) == 2018-10-07 10:00:00 | |
DateTime->add(1d) == 2018-10-07 10:00:00 | |
For timezone 'Europe/Moscow': | |
2018-03-31 10:00:00 | |
+ 24*60*60 == 2018-04-01 10:00:00 | |
strtotime(+1 day) == 2018-04-01 10:00:00 | |
DateTime->add(1d) == 2018-04-01 10:00:00 | |
2018-10-06 10:00:00 | |
+ 24*60*60 == 2018-10-07 10:00:00 | |
strtotime(+1 day) == 2018-10-07 10:00:00 | |
DateTime->add(1d) == 2018-10-07 10:00:00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// According to https://www.timeanddate.com/time/change/australia | |
// DST events are on | |
// 1 April 2018, 03:00:00 and | |
// 7 October 2018, 02:00:00 | |
// | |
function test($timezone) | |
{ | |
date_default_timezone_set($timezone); // affects both ts and DateTime funcs | |
echo "\nFor timezone '{$timezone}':\n"; | |
addAndShow(strtotime('2018-03-31 10:00:00')); | |
addAndShow(strtotime('2018-10-06 10:00:00')); | |
} | |
function addAndShow($ts) | |
{ | |
echo date('Y-m-d H:i:s', $ts)."\n"; | |
echo '+ 24*60*60 == '.date('Y-m-d H:i:s', $ts + 86400)."\n"; | |
echo 'strtotime(+1 day) == '.date('Y-m-d H:i:s', strtotime('+1 day', $ts))."\n"; | |
$o = (new DateTime)->setTimestamp($ts)->add(new DateInterval('P1D')); | |
echo 'DateTime->add(1d) == '.$o->format('Y-m-d H:i:s')."\n"; | |
} | |
test('Australia/Melbourne'); | |
test('Europe/Moscow'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment