Exemplo n.º 1
0
 public function testCompareMySQLAndPHPTimezoneOffsets()
 {
     if (!$this->isTimeZoneSupported()) {
         return;
     }
     // These tests will only be run if the time_zone tables are populated in MySQL.
     // See http://dev.mysql.com/doc/refman/5.1/en/mysql-tzinfo-to-sql.html
     $config = Config::getInstance();
     // set timezones the same for MySQL and PHP
     $config->setValue('timezone', 'America/Los_Angeles');
     date_default_timezone_set('America/Los_Angeles');
     $timezone = $config->getValue('timezone');
     TestMySQLDAO::destroyPDO();
     $testdao = DAOFactory::getDAO('TestDAO');
     // test time outside of daylight saving time
     $stmt = TestMySQLDAO::$PDO->query('SELECT UNIX_TIMESTAMP("2011-01-01 00:00:00") AS time');
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $mysql_time = $row['time'];
     $php_time = strtotime('2011-01-01 00:00:00');
     $this->assertEqual($mysql_time, $php_time);
     // test time during daylight saving time
     $stmt = TestMySQLDAO::$PDO->query('SELECT UNIX_TIMESTAMP("2011-09-01 00:00:00") AS time');
     $row = $stmt->fetch(PDO::FETCH_ASSOC);
     $mysql_time = $row['time'];
     $php_time = strtotime('2011-09-01 00:00:00');
     $this->assertEqual($mysql_time, $php_time);
 }
Exemplo n.º 2
0
 public function testCompareTimezoneOffsets()
 {
     $config = Config::getInstance();
     $config->setValue('timezone', 'Europe/London');
     $timezone = $config->getValue('timezone');
     $time = new DateTime("now", new DateTimeZone($timezone));
     $tz_config = $time->format('P');
     //destroy the existing PDO connection which gets established in setUp to start with a clean slate
     TestMySQLDAO::destroyPDO();
     // this should return the same timezone offset as the config value
     $test_dao = new TestMySQLDAO();
     $tz_server = $test_dao->getTimezoneOffset();
     $this->assertEqual($tz_config, $tz_server['tz_offset']);
     Config::destroyInstance();
 }