From 143f410a2f9b3537ea7faa0f1bb4cf4e99005cef Mon Sep 17 00:00:00 2001 From: David Monllao Date: Tue, 3 May 2016 13:59:29 +0800 Subject: [PATCH] MDL-54008 tz: Unexisting tz with decimals fallback to rounded down integer --- lib/classes/date.php | 2 +- lib/tests/date_legacy_test.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/classes/date.php b/lib/classes/date.php index 6026bb91e72..3685809eb4f 100644 --- a/lib/classes/date.php +++ b/lib/classes/date.php @@ -134,7 +134,7 @@ class core_date { // Convert to known zone. $tz = self::$badzones[$tz]; $fixed = true; - } else if (is_number($tz)) { + } else if (is_numeric($tz)) { // Half hour numeric offsets were already tested, try rounding to integers here. $roundedtz = (string)(int)$tz; if (isset(self::$badzones[$roundedtz])) { diff --git a/lib/tests/date_legacy_test.php b/lib/tests/date_legacy_test.php index 09ddf026a84..758416373a9 100644 --- a/lib/tests/date_legacy_test.php +++ b/lib/tests/date_legacy_test.php @@ -339,5 +339,9 @@ class core_date_legacy_testcase extends advanced_testcase { $USER->timezone = 'Europe/Prague'; $this->assertSame('Europe/Prague', usertimezone('99')); + + // Checking fallback with an unexisting timezone. + $USER->timezone = '-9.23'; + $this->assertSame('UTC-9', usertimezone('99')); } }