Example #1
0
 public function testDateTime()
 {
     $validator = new Rule\DateTime('Y-m-d');
     $this->assertTrue($validator('2015-01-01'));
     $this->assertTrue($validator(new \DateTime('now')));
     $this->assertFalse($validator('2015-01-40'));
     $this->assertEquals($validator->format(), 'Y-m-d');
 }
Example #2
0
 protected function _validate($value)
 {
     if ($value instanceof \DateTime) {
         return;
     }
     $date = \DateTime::createFromFormat($this->_format, $value);
     $errors = \DateTime::getLastErrors();
     if ($errors['warning_count'] || $errors['error_count']) {
         $this->error();
     }
 }