diff --git a/src/Entity/Field/DateImmutable.php b/src/Entity/Field/DateImmutable.php new file mode 100644 index 0000000..5f45a40 --- /dev/null +++ b/src/Entity/Field/DateImmutable.php @@ -0,0 +1,8 @@ +getMessage()), $ex->getCode(), $ex); - } - - return $obj; - } - - public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTime - { - $fromParent = parent::setTime($hour, $minute, $second, $microsecond); - - return new static($fromParent); - } - - public function save() - { - return $this->__toString(); - } - - public function __toString() - { - return $this->format($this->format); - } - - #[\Deprecated] - public function formatLocale(string $format) : string - { - return strftime($format, $this->getTimestamp()); - } - - public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string - { - $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern); - - return $formatter->format($this->getTimestamp()); - } - - public function ageAt(null|\DateTime $dateTime) : int - { - return (int) ( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000; - } - - public function jsonSerialize(): mixed - { - return $this; - } + use DatetimeTrait; } + diff --git a/src/Entity/Field/DatetimeImmutable.php b/src/Entity/Field/DatetimeImmutable.php new file mode 100644 index 0000000..ef83482 --- /dev/null +++ b/src/Entity/Field/DatetimeImmutable.php @@ -0,0 +1,9 @@ +getMessage()), $ex->getCode(), $ex); + } + + return $obj; + } + + public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTimeInterface + { + $fromParent = parent::setTime($hour, $minute, $second, $microsecond); + + return new static($fromParent); + } + + public function save() + { + return $this->__toString(); + } + + public function __toString() + { + return $this->format($this->format); + } + + #[\Deprecated] + public function formatLocale(string $format) : string + { + return strftime($format, $this->getTimestamp()); + } + + public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string + { + $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern); + + return $formatter->format($this->getTimestamp()); + } + + public function ageAt(null|\DateTime $dateTime) : int + { + return (int) ( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000; + } + + public function jsonSerialize(): mixed + { + return $this; + } +} \ No newline at end of file diff --git a/src/Entity/Field/TimeImmutable.php b/src/Entity/Field/TimeImmutable.php new file mode 100644 index 0000000..2389bb6 --- /dev/null +++ b/src/Entity/Field/TimeImmutable.php @@ -0,0 +1,8 @@ +