Skip to content

Commit

Permalink
Merge pull request #24 from ergebnis/feature/current
Browse files Browse the repository at this point in the history
Enhancement: Allow creation of Year from current UTC time
  • Loading branch information
localheinz committed Jan 2, 2020
2 parents 00caf0b + c3a7059 commit aa2ed34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Header/Year.php
Expand Up @@ -44,6 +44,16 @@ public static function fromString(string $value): self
return new self($value);
}

public static function current(): self
{
$value = new \DateTimeImmutable(
'now',
new \DateTimeZone('UTC')
);

return self::fromString($value->format('Y'));
}

public function toString(): string
{
return $this->value;
Expand Down
12 changes: 12 additions & 0 deletions test/Unit/Header/YearTest.php
Expand Up @@ -92,6 +92,18 @@ public function provideValidValue(): \Generator
}
}

public function testCurrentReturnsYearWithUtcValue(): void
{
$value = new \DateTimeImmutable(
'now',
new \DateTimeZone('UTC')
);

$year = Year::current();

self::assertSame($value->format('Y'), $year->toString());
}

public function testEqualsReturnsFalseWhenValueIsDifferent(): void
{
$one = Year::fromString('2020');
Expand Down

0 comments on commit aa2ed34

Please sign in to comment.