From 09c1a4caa72f9b535f22af5ee6612aac0d9436c5 Mon Sep 17 00:00:00 2001 From: David Woloszyn Date: Thu, 23 Nov 2023 18:13:38 +1100 Subject: [PATCH] MDL-80229 core: Add tolerance to min_get_minimum_revision --- lib/configonlylib.php | 5 ++++- lib/tests/configonlylib_test.php | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/configonlylib.php b/lib/configonlylib.php index bcdfa9bee90..cddb3653110 100644 --- a/lib/configonlylib.php +++ b/lib/configonlylib.php @@ -215,6 +215,9 @@ function min_get_slash_argument($clean = true) { */ function min_get_minimum_revision(): int { static $timestamp = null; + // Days that will be deducted. + // Avoids errors when date comparisons are made at time of packaging for next release. + $tolerancedays = 2; if ($timestamp === null) { global $CFG; @@ -224,7 +227,7 @@ function min_get_minimum_revision(): int { // Parse the date components. $year = intval(substr($datestring, 0, 4)); $month = intval(substr($datestring, 4, 2)); - $day = intval(substr($datestring, 6, 2)); + $day = intval(substr($datestring, 6, 2)) - $tolerancedays; // Return converted GMT Unix timestamp. $timestamp = gmmktime(0, 0, 0, $month, $day, $year); } diff --git a/lib/tests/configonlylib_test.php b/lib/tests/configonlylib_test.php index 01d8215aca1..3532e7a3a2a 100644 --- a/lib/tests/configonlylib_test.php +++ b/lib/tests/configonlylib_test.php @@ -153,6 +153,8 @@ class configonlylib_test extends \advanced_testcase { // This is fairly hard to write a test for, but we can at least check that it returns a number // greater than the version when the feature was first introduced. $firstintroduced = 1693612800; // Equivalent to 20230902 00:00:00 GMT. + // Deduct our two day tolerance. + $firstintroduced = $firstintroduced - (DAYSECS * 2); $this->assertGreaterThanOrEqual($firstintroduced, min_get_minimum_revision()); }