Skip to content

Commit

Permalink
[BUGFIX] Simplify date range on identical years in copyright range
Browse files Browse the repository at this point in the history
  • Loading branch information
eliashaeussler committed Apr 2, 2024
1 parent d79fdae commit deaefa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Package/CopyrightRange.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static function since(int $year): self

public function __toString(): string
{
if ($this->from === $this->to) {
return (string) $this->to;
}

if (null !== $this->from && null !== $this->to) {
return sprintf('%d-%d', $this->from, $this->to);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/src/Package/CopyrightRangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public function sinceUsesGivenYear(): void
self::assertSame('since 2021', (string) $subject);
}

#[Framework\Attributes\Test]
public function stringRepresentationDoesNotShowRangeOnIdenticalStartAndEndYear(): void
{
$subject = Src\Package\CopyrightRange::from(2024, 2024);

self::assertSame('2024', (string) $subject);
}

private static function getCurrentYear(): int
{
return (int) date('Y');
Expand Down

0 comments on commit deaefa3

Please sign in to comment.