mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
Merge branch 'MDL-81894-404' of https://github.com/andrewnicols/moodle into MOODLE_404_STABLE
This commit is contained in:
commit
64f1fd7d7b
@ -24,10 +24,15 @@ namespace core;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class system_clock implements clock {
|
||||
#[\Override]
|
||||
public function now(): \DateTimeImmutable {
|
||||
return new \DateTimeImmutable();
|
||||
return new \DateTimeImmutable(
|
||||
datetime: "now",
|
||||
timezone: \core_date::get_server_timezone_object(),
|
||||
);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function time(): int {
|
||||
return $this->now()->getTimestamp();
|
||||
}
|
||||
|
@ -26,6 +26,9 @@ namespace core;
|
||||
* @covers \core\system_clock
|
||||
*/
|
||||
final class system_clock_test extends \advanced_testcase {
|
||||
/**
|
||||
* Test that the now method returns a DateTimeImmutable object.
|
||||
*/
|
||||
public function test_now(): void {
|
||||
$starttime = time();
|
||||
|
||||
@ -34,4 +37,45 @@ final class system_clock_test extends \advanced_testcase {
|
||||
$this->assertInstanceOf(\DateTimeImmutable::class, $now);
|
||||
$this->assertGreaterThanOrEqual($starttime, $now->getTimestamp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the time method returns a timestamp.
|
||||
*/
|
||||
public function test_time(): void {
|
||||
$starttime = time();
|
||||
|
||||
$clock = new system_clock();
|
||||
$time = $clock->time();
|
||||
$this->assertGreaterThanOrEqual($starttime, $time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the now method returns a DateTimeImmutable object in the server timezone.
|
||||
*
|
||||
* @dataProvider timezone_provider
|
||||
* @param string $timezone
|
||||
*/
|
||||
public function test_now_timezone(string $timezone): void {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$CFG->timezone = $timezone;
|
||||
|
||||
$clock = new system_clock();
|
||||
$now = $clock->now();
|
||||
$this->assertEquals(\core_date::normalise_timezone($CFG->timezone), $now->getTimezone()->getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for the test_now_timezone method.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function timezone_provider(): array {
|
||||
return [
|
||||
['UTC'],
|
||||
['Europe/London'],
|
||||
['America/New_York'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
This files describes API changes in core libraries and APIs,
|
||||
information provided here is intended especially for developers.
|
||||
|
||||
=== 4.4.1 ===
|
||||
|
||||
* Use server timezone when constructing `\DateTimeImmutable` for the system `\core\clock` implementation.
|
||||
|
||||
=== 4.4 ===
|
||||
|
||||
* New modinfo methods related to delegated sections (sections controlled by a component):
|
||||
|
Loading…
x
Reference in New Issue
Block a user