Example #1
0
 public function testVisitDurationDateTime()
 {
     $visitor = new ValidationVisitor();
     $property = Property::getDuration('test');
     $this->assertTrue($visitor->visitDuration(new \DateInterval('P1Y'), $property, ''));
 }
Example #2
0
 public function visitDuration($data, Property\DurationType $property, $path)
 {
     if ($this->validate) {
         parent::visitDuration($data, $property, $path);
     } else {
         $this->assertRequired($data, $property, $path);
     }
     if ($data instanceof \DateInterval) {
         return $this->createSimpleProperty(Duration::fromDateInterval($data), $property);
     }
     try {
         return $this->createSimpleProperty(new Duration($data), $property);
     } catch (\Exception $e) {
         throw new ValidationException($path . ' must be an valid duration format [ISO8601]');
     }
 }