public function test_timezones() {
        global $CFG, $USER;

        // The timezones used in this test are chosen because they do not use DST - that would break the test.

        $currenttimezonephp = date_default_timezone_get();
        $currenttimezonecfg = null;
        if (!empty($CFG->timezone)) {
            $currenttimezonecfg = $CFG->timezone;
        }
        $userstimezone = null;
        if (!empty($USER->timezone)) {
            $userstimezone = $USER->timezone;
        }

        // We are testing a difference between $CFG->timezone and the php.ini timezone.
        // GMT+8.
        date_default_timezone_set('Australia/Perth');
        // GMT-04:30.
        $CFG->timezone = 'America/Caracas';

        $testclass = new \core\task\scheduled_test_task();

        // Scheduled tasks should always use servertime - so this is 03:30 GMT.
        $testclass->set_hour('1');
        $testclass->set_minute('0');

        // Next valid time should be 1am of the next day.
        $nexttime = $testclass->get_next_scheduled_time();

        // GMT+05:45.
        $USER->timezone = 'Asia/Kathmandu';
        $userdate = userdate($nexttime);

        // Should be displayed in user timezone.
        // I used http://www.timeanddate.com/worldclock/fixedtime.html?msg=Moodle+Test&iso=20140314T01&p1=58
        // to verify this time.
        $this->assertContains('11:15 AM', core_text::strtoupper($userdate));

        $CFG->timezone = $currenttimezonecfg;
        date_default_timezone_set($currenttimezonephp);
    }
Beispiel #2
0
 public function test_timezones()
 {
     global $CFG, $USER;
     // The timezones used in this test are chosen because they do not use DST - that would break the test.
     $this->resetAfterTest();
     $this->setTimezone('Asia/Kabul');
     $testclass = new \core\task\scheduled_test_task();
     // Scheduled tasks should always use servertime - so this is 03:30 GMT.
     $testclass->set_hour('1');
     $testclass->set_minute('0');
     // Next valid time should be 1am of the next day.
     $nexttime = $testclass->get_next_scheduled_time();
     // GMT+05:45.
     $USER->timezone = 'Asia/Kathmandu';
     $userdate = userdate($nexttime);
     // Should be displayed in user timezone.
     // I used http://www.timeanddate.com/worldclock/fixedtime.html?msg=Moodle+Test&iso=20160502T01&p1=113
     // setting my location to Kathmandu to verify this time.
     $this->assertContains('2:15 AM', core_text::strtoupper($userdate));
 }