From 3b873397e6d13f5e0a86acb81f3ce81acd1c66f7 Mon Sep 17 00:00:00 2001 From: Adrian Greeve Date: Tue, 9 Aug 2016 15:17:45 +0800 Subject: [PATCH] MDL-22183 lib: More unit tests for next day start. --- lib/tests/statslib_test.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index f04f000267a..66089a40644 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -388,6 +388,22 @@ class core_statslib_testcase extends advanced_testcase { public function test_statslib_get_next_day_start() { $this->setTimezone(0); $this->assertEquals(1272758400, stats_get_next_day_start(1272686410)); + + // Try setting timezone to some place in the US. + $this->setTimezone('America/New_York', 'America/New_York'); + // Then set the time for midnight before daylight savings. + // 1425790800 is midnight in New York (2015-03-08) Daylight saving will occur in 2 hours time. + // 1425873600 is midnight the next day. + $this->assertEquals(1425873600, stats_get_next_day_start(1425790800)); + $this->assertEquals(23, ((1425873600 - 1425790800) / 60 ) / 60); + // Then set the time for midnight before daylight savings ends. + // 1446350400 is midnight in New York (2015-11-01) Daylight saving will finish in 2 hours time. + // 1446440400 is midnight the next day. + $this->assertEquals(1446440400, stats_get_next_day_start(1446350400)); + $this->assertEquals(25, ((1446440400 - 1446350400) / 60 ) / 60); + // The next day should be normal. + $this->assertEquals(1446526800, stats_get_next_day_start(1446440400)); + $this->assertEquals(24, ((1446526800 - 1446440400) / 60 ) / 60); } /**