From 65fd251ec6ff43969deade7342d981ceaeb14b77 Mon Sep 17 00:00:00 2001 From: tigitz Date: Wed, 27 Apr 2022 11:32:02 +0200 Subject: [PATCH] Make TimeZoneRegion::utc() return a TimeZoneRegion not an TimeZoneOffset --- src/Instant.php | 2 +- src/LocalDateTime.php | 2 +- src/TimeZone.php | 4 ---- src/TimeZoneRegion.php | 5 +++++ tests/InstantTest.php | 4 ++-- tests/TimeZoneOffsetTest.php | 1 + tests/TimeZoneRegionTest.php | 7 +++++++ tests/TimeZoneTest.php | 9 +++------ tests/ZonedDateTimeTest.php | 2 +- 9 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Instant.php b/src/Instant.php index 8282eeb..e06db94 100644 --- a/src/Instant.php +++ b/src/Instant.php @@ -363,7 +363,7 @@ public function jsonSerialize(): string */ public function toISOString(): string { - return (string) ZonedDateTime::ofInstant($this, TimeZone::utc()); + return (string) ZonedDateTime::ofInstant($this, TimeZoneOffset::utc()); } /** diff --git a/src/LocalDateTime.php b/src/LocalDateTime.php index c16f72a..df9f887 100644 --- a/src/LocalDateTime.php +++ b/src/LocalDateTime.php @@ -715,7 +715,7 @@ public function isPast(TimeZone $timeZone, ?Clock $clock = null): bool */ public function toNativeDateTime(): DateTime { - return $this->atTimeZone(TimeZone::utc())->toNativeDateTime(); + return $this->atTimeZone(TimeZoneOffset::utc())->toNativeDateTime(); } /** diff --git a/src/TimeZone.php b/src/TimeZone.php index 915e8d2..84b740b 100644 --- a/src/TimeZone.php +++ b/src/TimeZone.php @@ -41,10 +41,6 @@ public static function parse(string $text): TimeZone return TimeZoneRegion::parse($text); } - public static function utc(): TimeZoneOffset - { - return TimeZoneOffset::utc(); - } /** * Returns the unique time-zone ID. diff --git a/src/TimeZoneRegion.php b/src/TimeZoneRegion.php index 7f232f4..39f9350 100644 --- a/src/TimeZoneRegion.php +++ b/src/TimeZoneRegion.php @@ -55,6 +55,11 @@ public static function from(DateTimeParseResult $result): TimeZoneRegion return TimeZoneRegion::of($region); } + public static function utc() : TimeZoneRegion + { + return TimeZoneRegion::of('UTC'); + } + /** * Returns all the available time-zone identifiers. * diff --git a/tests/InstantTest.php b/tests/InstantTest.php index 1e3a042..ca971aa 100644 --- a/tests/InstantTest.php +++ b/tests/InstantTest.php @@ -8,7 +8,7 @@ use Brick\DateTime\DateTimeException; use Brick\DateTime\Duration; use Brick\DateTime\Instant; -use Brick\DateTime\TimeZone; +use Brick\DateTime\TimeZoneOffset; use PHPUnit\Framework\Attributes\DataProvider; use function json_encode; @@ -658,7 +658,7 @@ public static function providerToString(): array public function testAtTimeZone(): void { - $timeZone = TimeZone::utc(); + $timeZone = TimeZoneOffset::utc(); $instant = Instant::of(1000000000); $result = $instant->atTimeZone($timeZone); self::assertSame(1000000000, $result->getInstant()->getEpochSecond()); diff --git a/tests/TimeZoneOffsetTest.php b/tests/TimeZoneOffsetTest.php index ad8fb38..5f3562f 100644 --- a/tests/TimeZoneOffsetTest.php +++ b/tests/TimeZoneOffsetTest.php @@ -10,6 +10,7 @@ use Brick\DateTime\TimeZoneOffset; use DateTimeImmutable; use PHPUnit\Framework\Attributes\DataProvider; +use Brick\DateTime\TimeZoneRegion; use const PHP_VERSION_ID; diff --git a/tests/TimeZoneRegionTest.php b/tests/TimeZoneRegionTest.php index ce6219e..668fd9b 100644 --- a/tests/TimeZoneRegionTest.php +++ b/tests/TimeZoneRegionTest.php @@ -163,4 +163,11 @@ public function testToString(): void { self::assertSame('America/Los_Angeles', (string) TimeZoneRegion::of('America/Los_Angeles')); } + + public function testUTC(): void + { + $utcTimeZoneRegion = TimeZoneRegion::utc(); + $this->assertInstanceOf(TimeZoneRegion::class, $utcTimeZoneRegion); + $this->assertSame('UTC', $utcTimeZoneRegion->getId()); + } } diff --git a/tests/TimeZoneTest.php b/tests/TimeZoneTest.php index 227aead..d60aef6 100644 --- a/tests/TimeZoneTest.php +++ b/tests/TimeZoneTest.php @@ -66,16 +66,13 @@ public static function providerParseInvalidStringThrowsException(): array public function testUtc(): void { - $utc = TimeZone::utc(); - - self::assertTimeZoneOffsetIs(0, $utc); - self::assertSame($utc, TimeZone::utc()); + $this->assertTimeZoneOffsetIs(0, TimeZoneOffset::utc()); } public function testIsEqualTo(): void { - self::assertTrue(TimeZone::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(0))); - self::assertFalse(TimeZone::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(3600))); + self::assertTrue(TimeZoneOffset::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(0))); + self::assertFalse(TimeZoneOffset::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(3600))); } /** diff --git a/tests/ZonedDateTimeTest.php b/tests/ZonedDateTimeTest.php index 8d3d069..027ec09 100644 --- a/tests/ZonedDateTimeTest.php +++ b/tests/ZonedDateTimeTest.php @@ -520,7 +520,7 @@ public function testGetMonth(int $monthValue, Month $month): void { $zonedDateTime = ZonedDateTime::of( LocalDateTime::of(2000, $monthValue, 1), - TimeZone::utc(), + TimeZoneOffset::utc(), ); self::assertSame($month, $zonedDateTime->getMonth());