public function convertToPHPValue($value, AbstractPlatform $platform) { $result = parent::convertToPHPValue($value, $platform); if ($result instanceof \DateTime) { return Date::instance($result); } return $result; }
protected function asDateTime($value) { if (is_numeric($value)) { return Date::createFromTimestamp($value); } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) { return Date::createFromFormat('Y-m-d', $value)->startOfDay(); } elseif (!$value instanceof DateTime) { $format = $this->getDateFormat(); return Date::createFromFormat($format, $value); } return Date::instance($value); }
/** * Return a timestamp as DateTime object. * * @param mixed $value * @return \Jenssegers\Date\Date */ protected function asDateTime($value) { // If this value is an integer, we will assume it is a UNIX timestamp's value // and format a Carbon object from this timestamp. This allows flexibility // when defining your date fields as they might be UNIX timestamps here. if (is_numeric($value)) { return Date::createFromTimestamp($value); } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) { return Date::createFromFormat('Y-m-d', $value)->startOfDay(); } elseif (!$value instanceof DateTime) { $format = $this->getDateFormat(); return Date::createFromFormat($format, $value); } return Date::instance($value); }
/** * Return a timestamp as DateTime object. * * @param mixed $value * @return \Carbon\Carbon */ protected function asDateTime($value) { Date::setLocale('it'); // If the value is already a DateTime instance, we will just skip the rest of // these checks since they will be a waste of time, and hinder performance // when checking the field. We will just return the DateTime right away. if ($value instanceof DateTime) { // } elseif (is_numeric($value)) { return Date::createFromTimestamp($value); } elseif (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) { return Date::createFromFormat('Y-m-d', $value)->startOfDay(); } elseif (!$value instanceof DateTime) { $format = $this->getDateFormat(); return Date::createFromFormat($format, $value); } return Date::instance($value); }