Example #1
0
 /**
  * {@inheritdoc}
  */
 public function setValue($value) : parent
 {
     if ($value instanceof TimeObject) {
         $value = $value->format();
     } elseif (is_string($value) && $value) {
         $date = new TimeObject($value);
         $value = $date->format();
     }
     return parent::setValue($value);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function __invoke($content, Column $column, array $primaryValues, array $data) : string
 {
     if (!$content) {
         return '';
     }
     if (is_string($content)) {
         $content = new Time($content);
     } elseif (is_int($content)) {
         $content = Time::createFromTime(0, 0, 0)->addSeconds($content);
     }
     return $content->display(Time::DISPLAY_DURATION);
 }
Example #3
0
 /**
  * @param Time $time
  *
  * @return $this|self
  */
 public function setTimeFromTime(Time $time)
 {
     return $this->setTimeFromTimeString($time->format());
 }
Example #4
0
 /**
  * @param string $type
  * @param $value
  *
  * @return null|DateTime
  */
 private function parseDate(string $type, $value)
 {
     try {
         switch ($type) {
             case 'datetime':
                 $datetime = DateTime::createFromFormat('Y-m-d\\TH:i:s', $value);
                 break;
             case 'date':
                 $datetime = Date::createFromFormat('Y-m-d', $value);
                 break;
             case 'time':
                 $datetime = Time::createFromFormat('H:i:s', $value);
                 break;
             default:
                 throw new \InvalidArgumentException(sprintf("Invalid parse date type '%s'", $type));
         }
     } catch (\Exception $exception) {
         return null;
     }
     return $datetime;
 }