Skip to content

Commit

Permalink
Fix a bug in YearMonth::__toString().
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Oct 3, 2023
1 parent 5b6044c commit 0c94b40
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/YearMonth.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ public function jsonSerialize(): string
*/
public function __toString(): string
{
return sprintf('%02u-%02u', $this->year, $this->month);
$pattern = ($this->year < 0 ? '%05d' : '%04d') . '-%02d';

return sprintf($pattern, $this->year, $this->month);
}
}

0 comments on commit 0c94b40

Please sign in to comment.