Skip to content

Commit

Permalink
Make TimeZoneRegion::utc() return a TimeZoneRegion not an TimeZoneOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
tigitz committed Aug 5, 2024
1 parent 727a192 commit a3c2a40
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Instant.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/LocalDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/TimeZoneRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static function from(DateTimeParseResult $result): TimeZoneRegion
return TimeZoneRegion::of($region);
}

public static function utc() : TimeZoneRegion

Check failure on line 58 in src/TimeZoneRegion.php

View workflow job for this annotation

GitHub Actions / Psalm

MethodSignatureMismatch

src/TimeZoneRegion.php:58:5: MethodSignatureMismatch: Method Brick\DateTime\TimeZoneRegion::utc with return type 'Brick\DateTime\TimeZoneRegion' is different to return type 'Brick\DateTime\TimeZoneOffset' of inherited method Brick\DateTime\TimeZone::utc (see https://psalm.dev/042)
{
return TimeZoneRegion::of('UTC');
}

/**
* Returns all the available time-zone identifiers.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/InstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions tests/TimeZoneOffsetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Brick\DateTime\TimeZoneOffset;
use DateTimeImmutable;
use PHPUnit\Framework\Attributes\DataProvider;
use Brick\DateTime\TimeZoneRegion;

use const PHP_VERSION_ID;

Expand Down
7 changes: 7 additions & 0 deletions tests/TimeZoneRegionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
9 changes: 3 additions & 6 deletions tests/TimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

/**
Expand Down

0 comments on commit a3c2a40

Please sign in to comment.