Skip to content

Commit

Permalink
MDL-38999 timezones: add some TZ/stamps know to be problematic to tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 8, 2013
1 parent 75899ed commit f80b096
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lib/tests/moodlelib_test.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1536,6 +1536,59 @@ public function test_get_extra_user_fields_sql() {
$USER = $olduser; $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() { public function test_userdate() {
global $USER, $CFG, $DB; global $USER, $CFG, $DB;


Expand Down

0 comments on commit f80b096

Please sign in to comment.