feat: all-season assignments

This commit is contained in:
Björn Fromme authored and Björn Fromme committed 2026-09-26 12:13:16 +02:00
1 parent 675cec1b69
commit cf876ed224
119 files changed
+6194 -294

No files matched your search

+46
View File
@@ -71,6 +71,52 @@ class SeasonCalendarTest extends TestCase
(new SeasonCalendar('xx-yy', '04-01'))->seasonYearFor(new \DateTimeImmutable('2025-01-01'));
}
/**
* @dataProvider currentOrUpcomingDates
*/
public function testCurrentOrUpcomingSeasonYear(string $date, int $expected): void
{
$this->assertSame(
$expected,
$this->winter()->currentOrUpcomingSeasonYear(new \DateTimeImmutable($date))
);
}
public static function currentOrUpcomingDates(): iterable
{
yield 'inside the season' => ['2024-12-20', 2024];
yield 'last day of the season' => ['2025-04-01', 2024];
yield 'day after the season ends falls forward' => ['2025-04-02', 2025];
yield 'high summer falls forward' => ['2025-07-15', 2025];
yield 'day before the next season starts' => ['2025-10-31', 2025];
yield 'first day of the next season' => ['2025-11-01', 2025];
yield 'off-season in january is impossible for this window' => ['2025-01-05', 2024];
}
public function testCurrentOrUpcomingSeasonYearFallsForwardAcrossTheTurnOfTheYear(): void
{
// A window that ends before it starts in the same calendar year is the wrapping case;
// one that does not wrap has its off-season on both sides of the window instead.
$summer = new SeasonCalendar('05-01', '09-30');
$this->assertSame(2025, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-03-01')));
$this->assertSame(2025, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-06-01')));
$this->assertSame(2026, $summer->currentOrUpcomingSeasonYear(new \DateTimeImmutable('2025-11-20')));
}
public function testWindowFor(): void
{
[$start, $end] = $this->winter()->windowFor(2024);
$this->assertSame('2024-11-01', $start->format('Y-m-d'));
$this->assertSame('2025-04-01', $end->format('Y-m-d'));
[$start, $end] = (new SeasonCalendar('05-01', '09-30'))->windowFor(2025);
$this->assertSame('2025-05-01', $start->format('Y-m-d'));
$this->assertSame('2025-09-30', $end->format('Y-m-d'));
}
/**
* @dataProvider provideUpcomingSeasonDates
*/