Skip to content

Commit

Permalink
fixes on easter calculation and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Jan 12, 2024
1 parent 5c8dcef commit 4f4bf96
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 84 deletions.
16 changes: 9 additions & 7 deletions src/Actions/Belgium.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Belgium implements Executable
{
protected int $year;

/** @return array<string, CarbonImmutable> */
public function execute(int $year): array
{
$this->year = $year;
Expand All @@ -32,7 +33,7 @@ protected function ensureYearCanBeCalculated(): void
}
}

/** @return array<string, string> */
/** @return array<string, CarbonImmutable> */
protected function fixedHolidays(): array
{
$dates = [
Expand All @@ -46,21 +47,22 @@ protected function fixedHolidays(): array
];

foreach ($dates as $name => $date) {
$dates[$name] = "{$date}-{$this->year}";
$dates[$name] = CarbonImmutable::createFromFormat('d-m-Y', "{$date}-{$this->year}");
}

return $dates;
}

/** @return array<string, string> */
/** @return array<string, CarbonImmutable> */
protected function variableHolidays(): array
{
$easter = CarbonImmutable::createFromTimestampUTC(easter_date($this->year));
$easter = CarbonImmutable::createFromTimestamp(easter_date($this->year))
->setTimezone('Europe/Brussels');

return [
'Paasmaandag' => $easter->addDay()->format('d-m-Y'),
'OH Hemelvaart' => $easter->addDays(39)->format('d-m-Y'),
'Pinkstermaandag' => $easter->addDays(50)->format('d-m-Y'),
'Paasmaandag' => $easter->addDay(),
'OH Hemelvaart' => $easter->addDays(39),
'Pinkstermaandag' => $easter->addDays(50),
];
}
}
8 changes: 4 additions & 4 deletions src/Holidays.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Holidays
{
/** @return array<string, string> */
/** @return array<string, CarbonImmutable> */
protected array $holidays = [];

protected int $year;
Expand Down Expand Up @@ -63,13 +63,13 @@ protected function calculate(): self

$this->holidays = $action->execute($this->year);

asort($this->holidays);
uasort($this->holidays, fn (CarbonImmutable $a, CarbonImmutable $b) => $a->timestamp <=> $b->timestamp);

return $this;
}

/**
* @param array<string, string> $dates
* @param array<string, CarbonImmutable> $dates
* @return array<array{name: string, date: string}>
*/
protected function format(array $dates): array
Expand All @@ -79,7 +79,7 @@ protected function format(array $dates): array
foreach ($dates as $name => $date) {
$response[] = [
'name' => $name,
'date' => $date,
'date' => $date->format('d-m-Y'),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@
"name": "Nieuwjaar",
"date": "01-01-2022"
},
{
"name": "Paasmaandag",
"date": "18-04-2022"
},
{
"name": "Dag van de Arbeid",
"date": "01-01-2022"
"date": "01-05-2022"
},
{
"name": "Allerheiligen",
"date": "01-11-2022"
"name": "OH Hemelvaart",
"date": "26-05-2022"
},
{
"name": "Pinkstermaandag",
"date": "05-06-2022"
"date": "06-06-2022"
},
{
"name": "Wapenstilstand",
"date": "11-11-2022"
"name": "Nationale Feestdag",
"date": "21-07-2022"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2022"
},
{
"name": "Paasmaandag",
"date": "17-04-2022"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2022"
"name": "Allerheiligen",
"date": "01-11-2022"
},
{
"name": "OH Hemelvaart",
"date": "25-05-2022"
"name": "Wapenstilstand",
"date": "11-11-2022"
},
{
"name": "Kerstmis",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
"name": "Nieuwjaar",
"date": "01-01-2023"
},
{
"name": "Paasmaandag",
"date": "10-04-2023"
},
{
"name": "Dag van de Arbeid",
"date": "01-01-2023"
"date": "01-05-2023"
},
{
"name": "Allerheiligen",
"date": "01-11-2023"
"name": "OH Hemelvaart",
"date": "18-05-2023"
},
{
"name": "Paasmaandag",
"date": "09-04-2023"
"name": "Pinkstermaandag",
"date": "29-05-2023"
},
{
"name": "Wapenstilstand",
"date": "11-11-2023"
"name": "Nationale Feestdag",
"date": "21-07-2023"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2023"
},
{
"name": "OH Hemelvaart",
"date": "17-05-2023"
"name": "Allerheiligen",
"date": "01-11-2023"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2023"
"name": "Wapenstilstand",
"date": "11-11-2023"
},
{
"name": "Kerstmis",
"date": "25-12-2023"
},
{
"name": "Pinkstermaandag",
"date": "28-05-2023"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
"name": "Nieuwjaar",
"date": "01-01-2025"
},
{
"name": "Paasmaandag",
"date": "21-04-2025"
},
{
"name": "Dag van de Arbeid",
"date": "01-01-2025"
"date": "01-05-2025"
},
{
"name": "Allerheiligen",
"date": "01-11-2025"
"name": "OH Hemelvaart",
"date": "29-05-2025"
},
{
"name": "Pinkstermaandag",
"date": "08-06-2025"
"date": "09-06-2025"
},
{
"name": "Wapenstilstand",
"date": "11-11-2025"
"name": "Nationale Feestdag",
"date": "21-07-2025"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2025"
},
{
"name": "Paasmaandag",
"date": "20-04-2025"
"name": "Allerheiligen",
"date": "01-11-2025"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2025"
"name": "Wapenstilstand",
"date": "11-11-2025"
},
{
"name": "Kerstmis",
"date": "25-12-2025"
},
{
"name": "OH Hemelvaart",
"date": "28-05-2025"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
"date": "01-01-2024"
},
{
"name": "Dag van de Arbeid",
"date": "01-01-2024"
"name": "Paasmaandag",
"date": "01-04-2024"
},
{
"name": "Allerheiligen",
"date": "01-11-2024"
"name": "Dag van de Arbeid",
"date": "01-05-2024"
},
{
"name": "OH Hemelvaart",
"date": "08-05-2024"
"date": "09-05-2024"
},
{
"name": "Wapenstilstand",
"date": "11-11-2024"
"name": "Pinkstermaandag",
"date": "20-05-2024"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2024"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2024"
},
{
"name": "Pinkstermaandag",
"date": "19-05-2024"
"name": "Allerheiligen",
"date": "01-11-2024"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2024"
"name": "Wapenstilstand",
"date": "11-11-2024"
},
{
"name": "Kerstmis",
"date": "25-12-2024"
},
{
"name": "Paasmaandag",
"date": "31-03-2024"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@
"date": "01-01-2024"
},
{
"name": "Dag van de Arbeid",
"date": "01-01-2024"
"name": "Paasmaandag",
"date": "01-04-2024"
},
{
"name": "Allerheiligen",
"date": "01-11-2024"
"name": "Dag van de Arbeid",
"date": "01-05-2024"
},
{
"name": "OH Hemelvaart",
"date": "08-05-2024"
"date": "09-05-2024"
},
{
"name": "Wapenstilstand",
"date": "11-11-2024"
"name": "Pinkstermaandag",
"date": "20-05-2024"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2024"
},
{
"name": "OLV Hemelvaart",
"date": "15-08-2024"
},
{
"name": "Pinkstermaandag",
"date": "19-05-2024"
"name": "Allerheiligen",
"date": "01-11-2024"
},
{
"name": "Nationale Feestdag",
"date": "21-07-2024"
"name": "Wapenstilstand",
"date": "11-11-2024"
},
{
"name": "Kerstmis",
"date": "25-12-2024"
},
{
"name": "Paasmaandag",
"date": "31-03-2024"
}
]

0 comments on commit 4f4bf96

Please sign in to comment.