MDL-80229 core: Add tolerance to min_get_minimum_revision

This commit is contained in:
David Woloszyn 2023-11-23 18:13:38 +11:00
parent 94ad185d09
commit 3fe8dbd027
2 changed files with 6 additions and 1 deletions

View File

@ -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);
}

View File

@ -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 = 1669593600; // Equivalent to 20221128 00:00:00 GMT.
// Deduct our two day tolerance.
$firstintroduced = $firstintroduced - (DAYSECS * 2);
$this->assertGreaterThanOrEqual($firstintroduced, min_get_minimum_revision());
}