Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function resolve(&$value)
 {
     if (is_numeric($value) && strlen($value) > 0) {
         $dateTime = new \Vegas\Util\DateTime();
         $dateTime->setTimestamp($value);
         $value = $dateTime;
     } else {
         if (\Vegas\Util\DateTime::isValid($value)) {
             $dateTime = new \Vegas\Util\DateTime($value);
             $value = $dateTime;
         }
     }
     return $value;
 }
Beispiel #2
0
 /**
  * Default \DateTime method creates parent classtype object.
  * This implementation overrides this behavior.
  * {@inheritdoc}
  */
 public static function createFromFormat($format, $time, $object = NULL)
 {
     $date = $object ? \DateTime::createFromFormat($format, $time, $object) : \DateTime::createFromFormat($format, $time);
     return $date !== false ? new self($date->format('Y-m-d H:i:s'), $date->getTimezone()) : false;
 }
Beispiel #3
0
 public function testShouldResolveDateTime()
 {
     $mappingManager = new MappingManager();
     $mappingManager->add(new DateTimeMapping());
     $now = new \DateTime('now');
     $fake = new FakeDate();
     $fake->createdAt = time();
     $this->assertEquals($now->format(DateTime::$globalDefaultFormat), $fake->readMapped('createdAt'));
     $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt'));
     $this->assertSame($fake->createdAt, (int) $fake->readMapped('createdAt')->format('U'));
     $fake->createdAt = $now->format('m/d/Y');
     $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt'));
     $this->assertEquals($now->format('m/d/Y'), $fake->readMapped('createdAt')->format('m/d/Y'));
     $this->assertSame($fake->createdAt, $fake->readMapped('createdAt')->format('m/d/Y'));
     $fake->createdAt = $now->format('d/m/Y');
     if ($now->format('j') > 12) {
         $this->assertNotInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt'));
         $this->assertEquals($now->format('d/m/Y'), $fake->readMapped('createdAt'));
         $this->assertInternalType('string', $fake->readMapped('createdAt'));
     } else {
         $this->assertInstanceOf('\\Vegas\\Util\\DateTime', $fake->readMapped('createdAt'));
         $this->assertNotEquals($now->format('d/m/Y'), $fake->readMapped('createdAt')->format('d/m/Y'));
     }
 }
Beispiel #4
0
 public function testShouldSerializeDateTimeObjectToJson()
 {
     $now = new \DateTime('now');
     $dateTime = DateTime::createFromFormat('Y-m-d H:i:s', $now->format('Y-m-d H:i:s'));
     $this->assertEquals(json_encode($now->format(\DateTime::ISO8601)), json_encode($dateTime));
 }