diff --git a/packages/clock/src/ClockConfig.php b/packages/clock/src/ClockConfig.php index a9c292d..8d0a354 100644 --- a/packages/clock/src/ClockConfig.php +++ b/packages/clock/src/ClockConfig.php @@ -5,34 +5,40 @@ namespace A50\Clock; use DateTimeZone; +use Exception; use Webmozart\Assert\Assert; final class ClockConfig { - private string $timezone; + private DateTimeZone $timezone; + /** + * @throws Exception + */ private function __construct(string $timezone) { Assert::inArray($timezone, DateTimeZone::listIdentifiers(DateTimeZone::ALL)); - $this->timezone = $timezone; + $this->timezone = new DateTimeZone($timezone); } + /** + * @throws Exception + */ public static function withDefaults( string $timezone = 'UTC', ): self { return new self($timezone); } + /** + * @throws Exception + */ public function withTimezoneChanged(string $timezone): self { - Assert::inArray($timezone, DateTimeZone::listIdentifiers(DateTimeZone::ALL)); - $new = clone $this; - $new->timezone = $timezone; - - return $new; + return new self($timezone); } - public function timezone(): string + public function timezone(): DateTimeZone { return $this->timezone; } diff --git a/packages/clock/src/ClockProvider.php b/packages/clock/src/ClockProvider.php index da7152f..6e2dfba 100644 --- a/packages/clock/src/ClockProvider.php +++ b/packages/clock/src/ClockProvider.php @@ -19,7 +19,7 @@ public static function getDefinitions(): array /** @var ClockConfig $config */ $config = $container->get(ClockConfig::class); - return new TimeZoneAwareClock(new DateTimeZone($config->timezone())); + return new TimeZoneAwareClock($config->timezone()); }, ]; }