From 1cc8f2594a61b975b2b34d6c9902848def73aec5 Mon Sep 17 00:00:00 2001 From: Corey Taylor Date: Sat, 23 Sep 2023 18:40:09 -0500 Subject: [PATCH] Align Chronos::getTimezone() return type with DateTimeImmutable::getTimezone() --- src/Chronos.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Chronos.php b/src/Chronos.php index afdd138..3cc8bad 100644 --- a/src/Chronos.php +++ b/src/Chronos.php @@ -20,7 +20,7 @@ use DateTimeInterface; use DateTimeZone; use InvalidArgumentException; -use ReturnTypeWillChange; +use RuntimeException; /** * An Immutable extension on the native DateTime object. @@ -1009,12 +1009,16 @@ public function setTimezone(DateTimeZone|string $value): static /** * Return time zone set for this instance. * - * @return \DateTimeZone|null + * @return \DateTimeZone */ - #[ReturnTypeWillChange] - public function getTimezone(): ?DateTimeZone + public function getTimezone(): DateTimeZone { - return parent::getTimezone() ?: null; + $tz = parent::getTimezone(); + if ($tz === false) { + throw new RuntimeException('Time zone could not be retrieved.'); + } + + return $tz; } /** @@ -2628,13 +2632,9 @@ public function __get(string $name): string|float|int|bool|DateTimeZone return $this->offset === 0; case $name === 'timezone' || $name === 'tz': - assert($this->getTimezone() !== null, 'Timezone is not set'); - return $this->getTimezone(); case $name === 'timezoneName' || $name === 'tzName': - assert($this->getTimezone() !== null, 'Timezone is not set'); - return $this->getTimezone()->getName(); default: