Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/LocalDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ public function withDay(int $day): LocalDate
public function plusPeriod(Period $period): LocalDate
{
return $this
->plusYears($period->getYears())
->plusMonths($period->getMonths())
// Not plusYears()->plusMonths(), which would clamp Feb 29 twice: 2020-02-29 + P1Y1M would give 2021-03-28.
->plusMonths($period->getYears() * 12 + $period->getMonths())
->plusDays($period->getDays());
}

Expand Down
6 changes: 6 additions & 0 deletions tests/LocalDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,12 @@ public static function providerPeriod(): array
[2001, 2, 3, 0, 30, 50, 2003, 9, 22],
[2001, 2, 3, 0, 0, -30, 2001, 1, 4],
[2001, 2, 3, 0, -30, -50, 1998, 6, 14],
[2020, 2, 29, 1, 0, 0, 2021, 2, 28],
[2020, 2, 29, 1, 1, 0, 2021, 3, 29],
[2020, 2, 29, 1, -1, 0, 2021, 1, 29],
[2020, 2, 29, 1, 6, 0, 2021, 8, 29],
[2020, 2, 29, -1, -1, 0, 2019, 1, 29],
[999995, 2, 26, 5, -29, 5, 999997, 10, 1],
];
}

Expand Down
6 changes: 6 additions & 0 deletions tests/LocalDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ public static function providerPeriod(): array
[2001, 2, 3, 0, 30, 50, 2003, 9, 22],
[2001, 2, 3, 0, 0, -30, 2001, 1, 4],
[2001, 2, 3, 0, -30, -50, 1998, 6, 14],
[2020, 2, 29, 1, 0, 0, 2021, 2, 28],
[2020, 2, 29, 1, 1, 0, 2021, 3, 29],
[2020, 2, 29, 1, -1, 0, 2021, 1, 29],
[2020, 2, 29, 1, 6, 0, 2021, 8, 29],
[2020, 2, 29, -1, -1, 0, 2019, 1, 29],
[999995, 2, 26, 5, -29, 5, 999997, 10, 1],
];
}

Expand Down
Loading