Exemplo n.º 1
0
 public function testSerializeDeserialize()
 {
     $dateStr = '2014-01-09 19:20:30';
     $date = EBDateTime::createFromFormat(EBDateTime::getDateTimeFormat(), $dateStr);
     $dateJson = $this->serializer->serialize($date, 'json');
     $this->assertEquals('"2014-01-09 19:20:30"', $dateJson);
     $dateXml = $this->serializer->serialize($date, 'xml');
     $this->assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<result><![CDATA[2014-01-09 19:20:30]]></result>\n", $dateXml);
     /** @var EBDateTime $dateFromJson */
     $dateFromJson = $this->serializer->deserialize($dateJson, 'EBT\\EBDate\\EBDateTime', 'json');
     $this->assertEquals($dateStr, $dateFromJson->formatAsString());
     /** @var EBDateTime $dateFromXml */
     $dateFromXml = $this->serializer->deserialize($dateXml, 'EBT\\EBDate\\EBDateTime', 'xml');
     $this->assertEquals($dateStr, $dateFromXml->formatAsString());
 }
Exemplo n.º 2
0
 /**
  * Creates a new EBDateTime using the default date time format.
  *
  * @param $time
  * @return EBDateTime
  */
 public static function createFromDateTimeFormat($time)
 {
     return static::createFromFormat(EBDateTime::getDateTimeFormat(), $time);
 }