Skip to content

Commit

Permalink
Clean up the name of whoever's birthday it is.
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickomeara committed Jan 22, 2024
1 parent 70d1625 commit be7f5e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 16 additions & 16 deletions src/Countries/Australia.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function countryCode(): string
protected function allHolidays(int $year): array
{
return array_merge([
'New Year\'s Day' => '01-01',
"New Year's Day" => '01-01',
'Australia Day' => '01-26',
'Anzac Day' => '04-25',
'Christmas Day' => '12-25',
Expand All @@ -42,15 +42,13 @@ protected function variableHolidays(int $year): array
'Easter Saturday' => $easter->subDay(),
'Easter Sunday' => $easter,
'Reconciliation Day' => CarbonImmutable::create($year, 5, 27)->modify("monday"),
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"),
],
'nsw' => [
'Easter Saturday' => $easter->subDay(),
'Easter Sunday' => $easter,
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"),
],
'nt' => [
Expand All @@ -62,39 +60,33 @@ protected function variableHolidays(int $year): array
'The day after Good Friday' => $easter->subDay(),
'Easter Sunday' => $easter,
'Labour Day' => CarbonImmutable::parse("first monday of may {$year}"),
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("first monday of october {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("first monday of october {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("first monday of october {$year}"),
],
'sa' => [
'Adelaide Cup Day' => $year < 2006
? CarbonImmutable::parse("third monday of may {$year}")
: CarbonImmutable::parse("second monday of march {$year}"),
'The day after Good Friday' => $easter->subDay(),
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
'Labour Day' => CarbonImmutable::parse("first monday of october {$year}"),
],
'tas' => [
'Eight Hours Day' => CarbonImmutable::parse("second monday of march {$year}"),
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
],
'vic' => [
'Labour Day' => CarbonImmutable::parse("second monday of march {$year}"),
'Saturday before Easter Sunday' => $easter->subDay(),
'Easter Sunday' => $easter,
'King\'s Birthday' => $year >= 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
'Queen\'s Birthday' => $year < 2023 ? CarbonImmutable::parse("second monday of june {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("second monday of june {$year}"),
'Friday before AFL Grand Final' => $this->fridayBeforeAflGrandFinal($year),
'Melbourne Cup' => CarbonImmutable::parse("first tuesday of november {$year}"),
],
'wa' => [
'Labour Day' => CarbonImmutable::parse("first monday of march {$year}"),
'Easter Sunday' => $easter,
'Western Australia Day' => CarbonImmutable::parse("first monday of june {$year}"),
// https://www.abc.net.au/news/2022-09-22/queens-birthday-public-holiday-becomes-kings-birthday/101453408
'King\'s Birthday' => $year >= 2022 ? CarbonImmutable::parse("last monday of september {$year}") : null,
'Queen\'s Birthday' => $year < 2022 ? CarbonImmutable::parse("last monday of september {$year}") : null,
$this->sovereignBirthdayKey($year) => CarbonImmutable::parse("last monday of september {$year}"),
],
default => [],
}),
Expand All @@ -116,4 +108,12 @@ protected function fridayBeforeAflGrandFinal(int $year): ?CarbonImmutable
default => CarbonImmutable::parse("last friday of september {$year}"),
};
}

protected function sovereignBirthdayKey(int $year): string
{
// https://www.abc.net.au/news/2022-09-22/queens-birthday-public-holiday-becomes-kings-birthday/101453408
$changeYear = $this->region === 'wa' ? 2022 : 2023;

return $year >= $changeYear ? "King's Birthday" : "Queen's Birthday";
}
}
12 changes: 6 additions & 6 deletions tests/Countries/AustraliaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,27 @@
->toBeNull();
});

it('returns queen\'s birthday before her death', function () {
it("returns queen's birthday before her death", function () {
CarbonImmutable::setTestNowAndTimezone('2021-01-22', 'Australia/Perth');

$holidays = Holidays::for(Australia::make('wa'))->get();

expect(findDate($holidays, 'Queen\'s Birthday'))
expect(findDate($holidays, "Queen's Birthday"))
->toEqual(CarbonImmutable::create(2021, 9, 27));

expect(findDate($holidays, 'King\'s Birthday'))
expect(findDate($holidays, "King's Birthday"))
->toBeNull();
});

it('returns king\'s birthday after her death', function () {
it("returns king's birthday after her death", function () {
CarbonImmutable::setTestNowAndTimezone('2022-01-22', 'Australia/Perth');

$holidays = Holidays::for(Australia::make('wa'))->get();

expect(findDate($holidays, 'Queen\'s Birthday'))
expect(findDate($holidays, "Queen's Birthday"))
->toBeNull();

expect(findDate($holidays, 'King\'s Birthday'))
expect(findDate($holidays, "King's Birthday"))
->toEqual(CarbonImmutable::create(2022, 9, 26));
});

Expand Down

0 comments on commit be7f5e6

Please sign in to comment.