Пример #1
0
 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})([. -] *(?P<yyyy>\\d{4})?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime(0, 0, 0);
         return $value;
     };
 }
Пример #2
0
 protected function getDefaultParser()
 {
     return function ($value) {
         if (!preg_match('#^(?P<dd>\\d{1,2})[. -] *(?P<mm>\\d{1,2})(?:[. -] *(?P<yyyy>\\d{4})?)?(?: *[ -@] *(?P<hh>\\d{1,2})[:.](?P<ii>\\d{1,2})(?:[:.](?P<ss>\\d{1,2}))?)?$#', $value, $matches)) {
             return NULL;
         }
         $dd = $matches['dd'];
         $mm = $matches['mm'];
         $yyyy = isset($matches['yyyy']) ? $matches['yyyy'] : date('Y');
         $hh = isset($matches['hh']) ? $matches['hh'] : 0;
         $ii = isset($matches['ii']) ? $matches['ii'] : 0;
         $ss = isset($matches['ss']) ? $matches['ss'] : 0;
         if (!($hh >= 0 && $hh < 24 && $ii >= 0 && $ii <= 59 && $ss >= 0 && $ss <= 59)) {
             $hh = $ii = $ss = 0;
         }
         if (!checkdate($mm, $dd, $yyyy)) {
             return NULL;
         }
         $value = new Nette\DateTime();
         $value->setDate($yyyy, $mm, $dd);
         $value->setTime($hh, $ii, $ss);
         return $value;
     };
 }