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 Apr 27, 2022
1 parent 2d3e3cd commit 00df54d
Show file tree
Hide file tree
Showing 8 changed files with 21 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 @@ -333,6 +333,6 @@ public function jsonSerialize() : string

public function __toString() : string
{
return (string) ZonedDateTime::ofInstant($this, TimeZone::utc());
return (string) ZonedDateTime::ofInstant($this, TimeZoneOffset::utc());
}
}
2 changes: 1 addition & 1 deletion src/LocalDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public function isPast(TimeZone $timeZone, ?Clock $clock = null) : bool
*/
public function toDateTime() : \DateTime
{
return $this->atTimeZone(TimeZone::utc())->toDateTime();
return $this->atTimeZone(TimeZoneOffset::utc())->toDateTime();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/TimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public static function parse(string $text) : TimeZone
return TimeZoneRegion::parse($text);
}

public static function utc() : TimeZoneOffset
{
return TimeZoneOffset::utc();
}
abstract public static function utc(): self;

/**
* Returns the unique time-zone ID.
Expand Down
5 changes: 5 additions & 0 deletions src/TimeZoneRegion.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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.
*
Expand Down
3 changes: 2 additions & 1 deletion tests/InstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Brick\DateTime\Duration;
use Brick\DateTime\Instant;
use Brick\DateTime\TimeZone;
use Brick\DateTime\TimeZoneOffset;

/**
* Unit tests for class Instant.
Expand Down Expand Up @@ -641,7 +642,7 @@ public function providerToString() : array

public function testAtTimeZone(): void
{
$timeZone = TimeZone::utc();
$timeZone = TimeZoneOffset::utc();
$instant = Instant::of(1000000000);
$result = $instant->atTimeZone($timeZone);
$this->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 @@ -8,6 +8,7 @@
use Brick\DateTime\Instant;
use Brick\DateTime\Parser\DateTimeParseException;
use Brick\DateTime\TimeZoneOffset;
use Brick\DateTime\TimeZoneRegion;

/**
* Units tests for class TimeZoneOffset.
Expand Down
7 changes: 7 additions & 0 deletions tests/TimeZoneRegionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,11 @@ public function testToString(): void
{
$this->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());
}
}
6 changes: 3 additions & 3 deletions tests/TimeZoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public function providerParseInvalidStringThrowsException() : array

public function testUtc(): void
{
$this->assertTimeZoneOffsetIs(0, TimeZone::utc());
$this->assertTimeZoneOffsetIs(0, TimeZoneOffset::utc());
}

public function testIsEqualTo(): void
{
$this->assertTrue(TimeZone::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(0)));
$this->assertFalse(TimeZone::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(3600)));
$this->assertTrue(TimeZoneOffset::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(0)));
$this->assertFalse(TimeZoneOffset::utc()->isEqualTo(TimeZoneOffset::ofTotalSeconds(3600)));
}

/**
Expand Down

0 comments on commit 00df54d

Please sign in to comment.