MDL-38999 timezones: add some TZ/stamps know to be problematic to tests.

This commit is contained in:
Eloy Lafuente (stronk7)
2013-04-08 16:33:01 +02:00
parent 75899ed480
commit f80b096a5e
+53
View File
@@ -1536,6 +1536,59 @@ class moodlelib_testcase extends advanced_testcase {
$USER = $olduser;
}
/**
* Test some critical TZ/DST.
*
* This method tests some special TZ/DST combinations that were fixed
* by MDL-38999. The tests are done by comparing the results of the
* output using Moodle TZ/DST support and PHP native one.
*
* Note: If you don't trust PHP TZ/DST support, can verify the
* harcoded expectations below with:
* http://www.tools4noobs.com/online_tools/unix_timestamp_to_datetime/
*/
public function test_some_moodle_special_dst() {
$stamp = 1365386400; // 2013/04/08 02:00:00 GMT/UTC.
// In Europe/Tallinn it was 2013/04/08 05:00:00.
$expectation = '2013/04/08 05:00:00';
$phpdt = DateTime::createFromFormat('U', $stamp, new DateTimeZone('UTC'));
$phpdt->setTimezone(new DateTimeZone('Europe/Tallinn'));
$phpres = $phpdt->format('Y/m/d H:i:s'); // PHP result.
$moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'Europe/Tallinn', false); // Moodle result.
$this->assertSame($expectation, $phpres);
$this->assertSame($expectation, $moodleres);
// In St. Johns it was 2013/04/07 23:30:00.
$expectation = '2013/04/07 23:30:00';
$phpdt = DateTime::createFromFormat('U', $stamp, new DateTimeZone('UTC'));
$phpdt->setTimezone(new DateTimeZone('America/St_Johns'));
$phpres = $phpdt->format('Y/m/d H:i:s'); // PHP result.
$moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'America/St_Johns', false); // Moodle result.
$this->assertSame($expectation, $phpres);
$this->assertSame($expectation, $moodleres);
$stamp = 1383876000; // 2013/11/08 02:00:00 GMT/UTC.
// In Europe/Tallinn it was 2013/11/08 04:00:00.
$expectation = '2013/11/08 04:00:00';
$phpdt = DateTime::createFromFormat('U', $stamp, new DateTimeZone('UTC'));
$phpdt->setTimezone(new DateTimeZone('Europe/Tallinn'));
$phpres = $phpdt->format('Y/m/d H:i:s'); // PHP result.
$moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'Europe/Tallinn', false); // Moodle result.
$this->assertSame($expectation, $phpres);
$this->assertSame($expectation, $moodleres);
// In St. Johns it was 2013/11/07 22:30:00.
$expectation = '2013/11/07 22:30:00';
$phpdt = DateTime::createFromFormat('U', $stamp, new DateTimeZone('UTC'));
$phpdt->setTimezone(new DateTimeZone('America/St_Johns'));
$phpres = $phpdt->format('Y/m/d H:i:s'); // PHP result.
$moodleres = userdate($stamp, '%Y/%m/%d %H:%M:%S', 'America/St_Johns', false); // Moodle result.
$this->assertSame($expectation, $phpres);
$this->assertSame($expectation, $moodleres);
}
public function test_userdate() {
global $USER, $CFG, $DB;