Exemplo n.º 1
0
 public function testDate()
 {
     $date = Date::fromFormat('y-m-d', '99-01-01');
     $this->assertEquals(1999, $date->y);
     $date = Date::fromFormat('Y-m-d', '2001-01-01');
     $this->assertEquals(2001, $date->y);
     $date = Date::fromFormat('y-m-d', '30-01-01');
     $this->assertEquals(2030, $date->y);
     $date = Date::fromFormat('y-m-d', '69-01-01');
     $this->assertEquals(2069, $date->y);
     $date = Date::fromFormat('y-m-d', '70-01-01');
     $this->assertEquals(1970, $date->y);
     $this->assertEquals('1970-01-01', (string) $date);
 }
Exemplo n.º 2
0
 public function toPhp($value)
 {
     if (in_array($value, $this->empty_values, true)) {
         return '';
     }
     if (is_object($value) && 'photon\\datetime\\Date' === get_class($value)) {
         return $value;
     }
     foreach (explode('||', $this->input_formats) as $format) {
         if (false !== ($date = \photon\datetime\Date::fromFormat($format, $value))) {
             return $date;
         }
     }
     throw new Invalid($this->error_messages['invalid']);
 }