Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit f80b096a5e86c2b97cb6332849d3deca0948d475 1 parent 75899ed
@stronk7 stronk7 authored
Showing with 53 additions and 0 deletions.
  1. +53 −0 lib/tests/moodlelib_test.php
View
53 lib/tests/moodlelib_test.php
@@ -1536,6 +1536,59 @@ public function test_get_extra_user_fields_sql() {
$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;
Please sign in to comment.
Something went wrong with that request. Please try again.