diff --git a/src/Countries/Australia.php b/src/Countries/Australia.php index 42511f516..ac572f858 100644 --- a/src/Countries/Australia.php +++ b/src/Countries/Australia.php @@ -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', @@ -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' => [ @@ -62,29 +60,25 @@ 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}"), ], @@ -92,9 +86,7 @@ protected function variableHolidays(int $year): array '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 => [], }), @@ -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"; + } } diff --git a/tests/Countries/AustraliaTest.php b/tests/Countries/AustraliaTest.php index 27f8a8b76..e274579df 100644 --- a/tests/Countries/AustraliaTest.php +++ b/tests/Countries/AustraliaTest.php @@ -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)); });