Skip to content

Commit

Permalink
Align Chronos::getTimezone() return type with DateTimeImmutable::getT…
Browse files Browse the repository at this point in the history
…imezone()
  • Loading branch information
othercorey committed Sep 23, 2023
1 parent e1a5d70 commit 1cc8f25
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Chronos.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use DateTimeInterface;
use DateTimeZone;
use InvalidArgumentException;
use ReturnTypeWillChange;
use RuntimeException;

/**
* An Immutable extension on the native DateTime object.
Expand Down Expand Up @@ -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.');

Check warning on line 1018 in src/Chronos.php

View check run for this annotation

Codecov / codecov/patch

src/Chronos.php#L1018

Added line #L1018 was not covered by tests
}

return $tz;
}

/**
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1cc8f25

Please sign in to comment.