/**
  * Format the value.
  *
  * @param null $format
  * @return null|string
  */
 public function format($format = 'm/d/Y')
 {
     $value = $this->object->getValue();
     if ($value && $value instanceof Carbon) {
         return $value->format($format);
     }
     return null;
 }
 /**
  * Restore the value.
  *
  * @param $value
  * @return Carbon
  */
 public function restore($value)
 {
     if (!$value) {
         return null;
     }
     if ($value instanceof Carbon) {
         return $value;
     }
     if (is_string($value)) {
         return (new Carbon())->createFromTimestamp(strtotime($value));
     }
     return (new Carbon())->createFromFormat($this->fieldType->getStorageFormat(), $value);
 }
 /**
  * Return the "time ago" formatted string.
  *
  * @return null|string
  */
 public function timeAgo()
 {
     $value = $this->object->getValue();
     if ($value instanceof Carbon) {
         return $value->setTimezone(config('app.timezone'))->diffForHumans();
     }
     return null;
 }
 /**
  * Return a carbon instance
  * based on the value.
  *
  * @param      $value
  * @param null $timezone
  * @return Carbon|null
  * @throws \Exception
  */
 protected function toCarbon($value, $timezone = null)
 {
     if (!$value) {
         return null;
     }
     if ($value instanceof Carbon) {
         return $value;
     }
     if (is_numeric($value)) {
         return (new Carbon())->createFromTimestamp($value, $timezone);
     }
     if ($timestamp = strtotime($value)) {
         return (new Carbon())->createFromTimestamp($timestamp, $timezone);
     }
     return (new Carbon())->createFromFormat($this->fieldType->getStorageFormat(), $value, $timezone);
 }