public function testTimesync() { // @todo: when the Zend_TimeSync adapter moves out of the incubator, // the following hack to allow it to be loaded should be removed. // see also ZF-954 $incubator = dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'incubator' . DIRECTORY_SEPARATOR . 'library'; $include_path = get_include_path(); set_include_path($include_path . PATH_SEPARATOR . $incubator); try { Zend_Loader::loadClass('Zend_TimeSync'); Zend_Loader::loadClass('Zend_TimeSync_Ntp'); } catch (Zend_Exception $e) { $this->markTestIncomplete($e->getMessage()); } set_include_path($include_path); // @todo: end of hack try { $server = new Zend_TimeSync('ntp://pool.ntp.org', 'alias'); $date1 = $server->getDate(); // need to use the proxy class to simulate time() returning wrong value $date2 = new Zend_Date_TestHelper(time()); $info = $server->getInfo(); if ($info['offset'] != 0) { $this->assertFalse($date1->getTimestamp() == $date2->getTimestamp()); } else { $this->assertSame($date1->getTimestamp(), $date2->getTimestamp()); } } catch (Zend_TimeSync_Exception $e) { $this->markTestIncomplete('NTP timeserver not available.'); } }
public function testTimesync() { try { $server = new Zend_TimeSync('ntp://pool.ntp.org', 'alias'); $date1 = $server->getDate(); // need to use the proxy class to simulate time() returning wrong value $date2 = new Zend_Date_TestHelper(time()); $info = $server->getInfo(); if ($info['offset'] >= 0.5 || $info['offset'] <= -0.52) { $this->assertFalse($date1->getTimestamp() == $date2->getTimestamp()); } else { $this->assertEquals($date1->getTimestamp(), $date2->getTimestamp()); } } catch (Zend_TimeSync_Exception $e) { $this->markTestIncomplete('NTP timeserver not available.'); } }
/** * test isToday(), isTomorrow(), and isYesterday() for cases other than time() = "now" */ public function testIsDay() { date_default_timezone_set('Europe/Vienna'); // should have DST $locale = new Zend_Locale('de_AT'); $date = new Zend_Date_TestHelper('01.01.2006', Zend_Date::DATES, $locale); $date->_setTime($date->mktime(0, 0, 0, 1, 1, 2006)); $this->assertTrue($date->isToday()); $this->assertFalse($date->isTomorrow()); $date->_setTime($date->mktime(0, 0, 0, 1, 1, 2006)); $this->assertFalse($date->isYesterday()); $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2005)); $this->assertTrue($date->isTomorrow()); $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2005)); $this->assertFalse($date->isYesterday()); $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2006)); $this->assertFalse($date->isTomorrow()); $date->_setTime($date->mktime(0, 0, 0, 12, 31, 2006)); $this->assertFalse($date->isYesterday()); $date->_setTime($date->mktime(0, 0, 0, 1, 0, 2006)); $this->assertTrue($date->isTomorrow()); $date->_setTime($date->mktime(0, 0, 0, 1, 0, 2006)); $this->assertFalse($date->isYesterday()); $date->_setTime($date->mktime(0, 0, 0, 1, 2, 2006)); $this->assertFalse($date->isTomorrow()); $date->_setTime($date->mktime(0, 0, 0, 1, 2, 2006)); $this->assertTrue($date->isYesterday()); }