Ejemplo n.º 1
0
 /**
  * @covers Fuel\Common\Date::createFromFormat
  * @covers Fuel\Common\Date::getTimezone
  * @covers Fuel\Common\Date::getTimestamp
  * @group Common
  */
 public function testCreateFromFormat()
 {
     // no match between input time format and format string
     $result = $this->instance->createFromFormat('mysql', time());
     $this->assertFalse($result);
     // no match between input time format and format string
     $time = time();
     $expected = date('D M d H:i:s Y', $time);
     $result = $this->instance->createFromFormat('mysql', date('Y-m-d H:i:s', $time));
     $this->assertEquals((string) $result, $expected);
     $this->assertTrue($result instanceof Date);
     $this->assertEquals($result->getTimestamp(), $time);
     $timezone = $result->getTimezone();
     $this->assertTrue($timezone instanceof \DateTimeZone);
     $this->assertEquals($timezone->getName(), 'Europe/Amsterdam');
     // Input New York time, output Amsterdam time
     $time = time();
     $expected = date('D M d H:i:s Y', $time + 6 * 3600);
     $result = $this->instance->createFromFormat('mysql', date('Y-m-d H:i:s', $time), 'America/New_York');
     $this->assertEquals((string) $result, $expected);
     $expected = array('warning_count' => 0, 'warnings' => array(), 'error_count' => 1, 'errors' => array(1 => "Data missing"));
     $this->instance->createFromFormat('*&(*(*&$', '0');
     $this->assertEquals(Date::getLastErrors(), $expected);
 }
Ejemplo n.º 2
0
 /**
  * Returns the warnings and errors from the last parsing operation
  *
  * @return  array  array of warnings and errors found while parsing a date/time string.
  */
 public static function getLastErrors()
 {
     return CommonDate::getLastErrors();
 }