diff --git a/src/Yasumi/Provider/Australia.php b/src/Yasumi/Provider/Australia.php index 2f2cdbc03..0a17fbfa6 100644 --- a/src/Yasumi/Provider/Australia.php +++ b/src/Yasumi/Provider/Australia.php @@ -35,6 +35,8 @@ class Australia extends AbstractProvider */ public const ID = 'AU'; + protected const MONARCHY_CHANGE_YEAR = 2023; + public string $timezone = 'Australia/Melbourne'; /** @@ -234,6 +236,35 @@ protected function calculateNationalDayOfMourning(): void )); } + /** + * Monarch's Birthday. + * + * @throws \Exception + */ + protected function addMonarchsBirthdayHoliday(\DateTimeInterface $date): void + { + $name = $this->year >= self::MONARCHY_CHANGE_YEAR ? 'King’s Birthday' : 'Queen’s Birthday'; + + $holiday = new Holiday( + 'monarchsBirthday', + ['en' => $name], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + ); + + $this->addHoliday($holiday); + + // Deprecated alias retained for downstream consumers using the former holiday key. + $this->addHoliday(new Holiday( + 'queensBirthday', + ['en' => $name], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + /** * Christmas Day / Boxing Day. * diff --git a/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php index 2156e8cf3..ef465c133 100644 --- a/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php +++ b/src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php @@ -33,7 +33,7 @@ class AustralianCapitalTerritory extends Australia */ public const ID = 'AU-ACT'; - public string $timezone = 'Australia/ACT'; + public string $timezone = 'Australia/Sydney'; /** * Initialize holidays for Australian Capital Territory (Australia). @@ -48,10 +48,48 @@ public function initialize(): void $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); + $this->calculateMonarchsBirthday(); $this->calculateLabourDay(); $this->calculateCanberraDay(); $this->calculateReconciliationDay(); + $this->calculateAnzacDayMonday(); + } + + /** + * ANZAC Day Monday substitute. + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is an additional public holiday + * in this state/territory. + * + * @see https://en.wikipedia.org/wiki/Anzac_Day + * @see https://www.timeanddate.com/holidays/australia/anzac-day + * + * @throws \Exception + */ + protected function calculateAnzacDayMonday(): void + { + if ($this->year < 2020) { + return; + } + + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $dow = (int) $date->format('w'); + + if (6 === $dow) { // Saturday → Monday + $date->add(new \DateInterval('P2D')); + } elseif (0 === $dow) { // Sunday → Monday + $date->add(new \DateInterval('P1D')); + } else { + return; + } + + $this->addHoliday(new Holiday( + 'anzacDayMonday', + ['en' => 'ANZAC Day'], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** @@ -125,9 +163,9 @@ protected function easterSaturday( } /** - * Queens Birthday. + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -139,15 +177,11 @@ protected function easterSaturday( * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/Provider/Australia/NewSouthWales.php b/src/Yasumi/Provider/Australia/NewSouthWales.php index b2c8c6a56..ec168685c 100644 --- a/src/Yasumi/Provider/Australia/NewSouthWales.php +++ b/src/Yasumi/Provider/Australia/NewSouthWales.php @@ -33,7 +33,7 @@ class NewSouthWales extends Australia */ public const ID = 'AU-NSW'; - public string $timezone = 'Australia/NSW'; + public string $timezone = 'Australia/Sydney'; /** * Initialize holidays for New South Wales (Australia). @@ -48,9 +48,47 @@ public function initialize(): void $this->addHoliday(new Holiday('easter', [], $this->calculateEaster($this->year, $this->timezone), $this->locale)); $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); + $this->calculateMonarchsBirthday(); $this->calculateLabourDay(); $this->calculateBankHoliday(); + $this->calculateAnzacDayMonday(); + } + + /** + * ANZAC Day Monday substitute. + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is an additional public holiday + * in this state/territory. + * + * @see https://en.wikipedia.org/wiki/Anzac_Day + * @see https://www.timeanddate.com/holidays/australia/anzac-day + * + * @throws \Exception + */ + protected function calculateAnzacDayMonday(): void + { + if ($this->year < 2026 || $this->year > 2027) { + return; + } + + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $dow = (int) $date->format('w'); + + if (6 === $dow) { // Saturday → Monday + $date->add(new \DateInterval('P2D')); + } elseif (0 === $dow) { // Sunday → Monday + $date->add(new \DateInterval('P1D')); + } else { + return; + } + + $this->addHoliday(new Holiday( + 'anzacDayMonday', + ['en' => 'ANZAC Day'], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); } /** @@ -92,9 +130,9 @@ protected function easterSaturday( } /** - * Queens Birthday. + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -106,15 +144,11 @@ protected function easterSaturday( * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/Provider/Australia/NorthernTerritory.php b/src/Yasumi/Provider/Australia/NorthernTerritory.php index 1b3b1291c..2dc623288 100644 --- a/src/Yasumi/Provider/Australia/NorthernTerritory.php +++ b/src/Yasumi/Provider/Australia/NorthernTerritory.php @@ -33,7 +33,7 @@ class NorthernTerritory extends Australia */ public const ID = 'AU-NT'; - public string $timezone = 'Australia/North'; + public string $timezone = 'Australia/Darwin'; /** * Initialize holidays for Northern Territory (Australia). @@ -47,7 +47,9 @@ public function initialize(): void parent::initialize(); $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); + $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); + $this->calculateAnzacDayMonday(); + $this->calculateMonarchsBirthday(); $this->calculateMayDay(); $this->calculatePicnicDay(); } @@ -91,9 +93,69 @@ protected function easterSaturday( } /** - * Queens Birthday. + * Easter Sunday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * + * @param int $year the year for which Easter Sunday need to be created + * @param string $timezone the timezone in which Easter Sunday is celebrated + * @param string $locale the locale for which Easter Sunday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + return new Holiday( + 'easter', + ['en' => 'Easter Sunday'], + $this->calculateEaster($year, $timezone), + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * ANZAC Day Monday substitute. + * + * In the Northern Territory, a substitute public holiday is observed on the following Monday + * when ANZAC Day falls on a Sunday. + * + * @see https://nt.gov.au/nt-public-holidays + * + * @throws \Exception + */ + protected function calculateAnzacDayMonday(): void + { + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + if ('0' !== $date->format('w')) { + return; + } + + $date->add(new \DateInterval('P1D')); + + $this->addHoliday(new Holiday( + 'anzacDayMonday', + ['en' => 'ANZAC Day'], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Monarch's Birthday. + * + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -105,15 +167,11 @@ protected function easterSaturday( * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/Provider/Australia/Queensland.php b/src/Yasumi/Provider/Australia/Queensland.php index f77c57949..e60042d4c 100644 --- a/src/Yasumi/Provider/Australia/Queensland.php +++ b/src/Yasumi/Provider/Australia/Queensland.php @@ -33,7 +33,7 @@ class Queensland extends Australia */ public const ID = 'AU-QLD'; - public string $timezone = 'Australia/Queensland'; + public string $timezone = 'Australia/Brisbane'; /** * Initialize holidays for Queensland (Australia). @@ -46,14 +46,91 @@ public function initialize(): void { parent::initialize(); - $this->calculateQueensBirthday(); + $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); + + if ($this->year >= 2017) { + $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); + } + + $this->calculateMonarchsBirthday(); $this->calculateLabourDay(); } /** - * Queens Birthday. + * Easter Saturday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * + * @param int $year the year for which Easter Saturday need to be created + * @param string $timezone the timezone in which Easter Saturday is celebrated + * @param string $locale the locale for which Easter Saturday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSaturday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + $date = $this->calculateEaster($year, $timezone)->sub(new \DateInterval('P1D')); + + if (! $date instanceof \DateTime) { + throw new \RuntimeException(sprintf('unable to perform a date subtraction for %s:%s', self::class, 'easterSaturday')); + } + + return new Holiday( + 'easterSaturday', + ['en' => 'Easter Saturday'], + $date, + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Easter Sunday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * @see https://www.qld.gov.au/recreation/travel/holidays/public + * + * @param int $year the year for which Easter Sunday need to be created + * @param string $timezone the timezone in which Easter Sunday is celebrated + * @param string $locale the locale for which Easter Sunday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + return new Holiday( + 'easter', + ['en' => 'Easter Sunday'], + $this->calculateEaster($year, $timezone), + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -65,7 +142,7 @@ public function initialize(): void * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { $birthDay = "first monday of october {$this->year}"; @@ -73,13 +150,9 @@ protected function calculateQueensBirthday(): void $birthDay = "second monday of june {$this->year}"; } - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/Provider/Australia/SouthAustralia.php b/src/Yasumi/Provider/Australia/SouthAustralia.php index 7c4854639..484e3e995 100644 --- a/src/Yasumi/Provider/Australia/SouthAustralia.php +++ b/src/Yasumi/Provider/Australia/SouthAustralia.php @@ -21,6 +21,7 @@ use Yasumi\Holiday; use Yasumi\Provider\Australia; use Yasumi\Provider\DateTimeZoneFactory; +use Yasumi\SubstituteHoliday; /** * Provider for all holidays in South Australia (Australia). @@ -33,7 +34,11 @@ class SouthAustralia extends Australia */ public const ID = 'AU-SA'; - public string $timezone = 'Australia/South'; + private const EASTER_SUNDAY_ESTABLISHMENT_YEAR = 2024; + + private const PROCLAMATION_DAY_SUBSTITUTE_YEAR = 2024; + + public string $timezone = 'Australia/Adelaide'; /** * Initialize holidays for South Australia (Australia). @@ -47,7 +52,12 @@ public function initialize(): void parent::initialize(); $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); - $this->calculateQueensBirthday(); + + if ($this->year >= self::EASTER_SUNDAY_ESTABLISHMENT_YEAR) { + $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); + } + + $this->calculateMonarchsBirthday(); $this->calculateLabourDay(); $this->calculateAdelaideCupDay(); @@ -99,9 +109,44 @@ protected function easterSaturday( } /** - * Queens Birthday. + * Easter Sunday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * Only a public holiday from 2024 onwards (via Public Holidays Act 2023). + * + * @see https://en.wikipedia.org/wiki/Easter + * @see https://www.safework.sa.gov.au/resources/public-holidays + * + * @param int $year the year for which Easter Sunday need to be created + * @param string $timezone the timezone in which Easter Sunday is celebrated + * @param string $locale the locale for which Easter Sunday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + return new Holiday( + 'easter', + ['en' => 'Easter Sunday'], + $this->calculateEaster($year, $timezone), + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); + } + + /** + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -113,15 +158,11 @@ protected function easterSaturday( * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** @@ -171,6 +212,7 @@ protected function calculateAdelaideCupDay(): void protected function calculateProclamationDay(): void { $christmasDay = new \DateTime("{$this->year}-12-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $proclamationDay = new \DateTime("{$this->year}-12-26", DateTimeZoneFactory::getDateTimeZone($this->timezone)); $this->addHoliday(new Holiday( 'christmasDay', @@ -180,6 +222,29 @@ protected function calculateProclamationDay(): void Holiday::TYPE_OFFICIAL )); + if ($this->year >= self::PROCLAMATION_DAY_SUBSTITUTE_YEAR && 5 === (int) $christmasDay->format('w')) { + $holiday = new Holiday( + 'proclamationDay', + ['en' => 'Proclamation Day'], + $proclamationDay, + $this->locale, + Holiday::TYPE_OFFICIAL + ); + + $this->addHoliday($holiday); + + $proclamationDay->add(new \DateInterval('P2D')); + $this->addHoliday(new SubstituteHoliday( + $holiday, + [], + $proclamationDay, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + + return; + } + switch ($christmasDay->format('w')) { case 0: // sunday $christmasDay->add(new \DateInterval('P1D')); diff --git a/src/Yasumi/Provider/Australia/Tasmania.php b/src/Yasumi/Provider/Australia/Tasmania.php index e23a3994d..bbcc5e4cd 100644 --- a/src/Yasumi/Provider/Australia/Tasmania.php +++ b/src/Yasumi/Provider/Australia/Tasmania.php @@ -33,7 +33,7 @@ class Tasmania extends Australia */ public const ID = 'AU-TAS'; - public string $timezone = 'Australia/Tasmania'; + public string $timezone = 'Australia/Hobart'; /** * Initialize holidays for Tasmania (Australia). @@ -47,7 +47,7 @@ public function initialize(): void parent::initialize(); $this->calculateEightHoursDay(); - $this->calculateQueensBirthday(); + $this->calculateMonarchsBirthday(); $this->calculateRecreationDay(); } @@ -64,9 +64,9 @@ protected function calculateEightHoursDay(): void } /** - * Queens Birthday. + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -78,15 +78,11 @@ protected function calculateEightHoursDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/Provider/Australia/Victoria.php b/src/Yasumi/Provider/Australia/Victoria.php index 4b66dd0f2..94e67b43e 100644 --- a/src/Yasumi/Provider/Australia/Victoria.php +++ b/src/Yasumi/Provider/Australia/Victoria.php @@ -33,7 +33,7 @@ class Victoria extends Australia */ public const ID = 'AU-VIC'; - public string $timezone = 'Australia/Victoria'; + public string $timezone = 'Australia/Melbourne'; /** * Initialize holidays for Victoria (Australia). @@ -49,7 +49,7 @@ public function initialize(): void $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); $this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale)); $this->calculateLabourDay(); - $this->calculateQueensBirthday(); + $this->calculateMonarchsBirthday(); $this->calculateMelbourneCupDay(); $this->calculateAFLGrandFinalDay(); } @@ -137,9 +137,9 @@ protected function calculateLabourDay(): void } /** - * Queens Birthday. + * Monarch's Birthday. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -151,15 +151,11 @@ protected function calculateLabourDay(): void * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + $this->addMonarchsBirthdayHoliday( + new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** @@ -177,39 +173,35 @@ protected function calculateMelbourneCupDay(): void /** * AFL Grand Final Day. * + * The Friday before the AFL Grand Final is a public holiday in Victoria. The date varies each year + * depending on the AFL schedule. + * * @throws \Exception */ protected function calculateAFLGrandFinalDay(): void { - switch ($this->year) { - case 2015: - $aflGrandFinalFriday = '2015-10-02'; - break; - case 2016: - $aflGrandFinalFriday = '2016-09-30'; - break; - case 2017: - $aflGrandFinalFriday = '2017-09-29'; - break; - case 2018: - $aflGrandFinalFriday = '2018-09-28'; - break; - case 2019: - $aflGrandFinalFriday = '2019-09-27'; - break; - case 2020: - $aflGrandFinalFriday = '2020-09-25'; - break; - default: - return; + $dates = [ + 2015 => '2015-10-02', + 2016 => '2016-09-30', + 2017 => '2017-09-29', + 2018 => '2018-09-28', + 2019 => '2019-09-27', + 2020 => '2020-09-25', + 2021 => '2021-09-24', + 2022 => '2022-09-23', + 2023 => '2023-09-29', + 2024 => '2024-09-27', + 2025 => '2025-09-26', + ]; + + if (! isset($dates[$this->year])) { + return; } - $date = new \DateTime($aflGrandFinalFriday, DateTimeZoneFactory::getDateTimeZone($this->timezone)); - $this->addHoliday(new Holiday( 'aflGrandFinalFriday', ['en' => 'AFL Grand Final Friday'], - $date, + new \DateTime($dates[$this->year], DateTimeZoneFactory::getDateTimeZone($this->timezone)), $this->locale )); } diff --git a/src/Yasumi/Provider/Australia/WesternAustralia.php b/src/Yasumi/Provider/Australia/WesternAustralia.php index b0cd462ea..3694763be 100644 --- a/src/Yasumi/Provider/Australia/WesternAustralia.php +++ b/src/Yasumi/Provider/Australia/WesternAustralia.php @@ -33,7 +33,7 @@ class WesternAustralia extends Australia */ public const ID = 'AU-WA'; - public string $timezone = 'Australia/West'; + public string $timezone = 'Australia/Perth'; /** * Initialize holidays for Western Australia (Australia). @@ -46,15 +46,90 @@ public function initialize(): void { parent::initialize(); - $this->calculateQueensBirthday(); + if ($this->year >= 2022) { + $this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale)); + } + + $this->calculateMonarchsBirthday(); $this->calculateLabourDay(); $this->calculateWesternAustraliaDay(); + $this->calculateAnzacDayMonday(); + } + + /** + * Easter Sunday. + * + * Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated + * on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council + * of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox. + * + * @see https://en.wikipedia.org/wiki/Easter + * @see https://www.wa.gov.au/service/employment/workplace-arrangements/public-holidays-western-australia + * + * @param int $year the year for which Easter Sunday need to be created + * @param string $timezone the timezone in which Easter Sunday is celebrated + * @param string $locale the locale for which Easter Sunday need to be displayed in + * @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE, + * TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered. + * + * @throws \Exception + */ + protected function easterSunday( + int $year, + string $timezone, + string $locale, + ?string $type = null, + ): Holiday { + return new Holiday( + 'easter', + ['en' => 'Easter Sunday'], + $this->calculateEaster($year, $timezone), + $locale, + $type ?? Holiday::TYPE_OFFICIAL + ); } /** - * Queens Birthday. + * ANZAC Day Monday substitute. + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is an additional public holiday + * in this state/territory. * - * The Queen's Birthday is an Australian public holiday but the date varies across + * @see https://en.wikipedia.org/wiki/Anzac_Day + * @see https://www.timeanddate.com/holidays/australia/anzac-day + * + * @throws \Exception + */ + protected function calculateAnzacDayMonday(): void + { + if ($this->year < 1972) { + return; + } + + $date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone)); + $dow = (int) $date->format('w'); + + if (6 === $dow) { // Saturday → Monday + $date->add(new \DateInterval('P2D')); + } elseif (0 === $dow) { // Sunday → Monday + $date->add(new \DateInterval('P1D')); + } else { + return; + } + + $this->addHoliday(new Holiday( + 'anzacDayMonday', + ['en' => 'ANZAC Day'], + $date, + $this->locale, + Holiday::TYPE_OFFICIAL + )); + } + + /** + * Monarch's Birthday. + * + * The Monarch's Birthday is an Australian public holiday but the date varies across * states and territories. Australia celebrates this holiday because it is a constitutional * monarchy, with the English monarch as head of state. * @@ -66,7 +141,7 @@ public function initialize(): void * @throws \InvalidArgumentException * @throws \Exception */ - protected function calculateQueensBirthday(): void + protected function calculateMonarchsBirthday(): void { $birthDay = "last monday of september {$this->year}"; if (2011 === $this->year) { @@ -77,13 +152,13 @@ protected function calculateQueensBirthday(): void $birthDay = '2012-10-01'; } - $this->addHoliday(new Holiday( - 'queensBirthday', - [], - new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)), - $this->locale, - Holiday::TYPE_OFFICIAL - )); + if (2024 === $this->year) { + $birthDay = '2024-09-23'; + } + + $this->addMonarchsBirthdayHoliday( + new \DateTime($birthDay, DateTimeZoneFactory::getDateTimeZone($this->timezone)) + ); } /** diff --git a/src/Yasumi/data/translations/monarchsBirthday.php b/src/Yasumi/data/translations/monarchsBirthday.php new file mode 100644 index 000000000..d23f5b7e8 --- /dev/null +++ b/src/Yasumi/data/translations/monarchsBirthday.php @@ -0,0 +1,25 @@ + + */ + +// Translations for Monarch's Birthday +return [ + 'da' => 'Dronningens fødselsdag', + 'en' => 'Monarch’s Birthday', + 'fr' => 'Anniversaire officiel de la reine', + 'pt' => 'Aniversário da Rainha', + 'ru' => 'Официальный день рождения королевы', +]; diff --git a/tests/Australia/AustralianCapitalTerritory/AnzacDayMondayTest.php b/tests/Australia/AustralianCapitalTerritory/AnzacDayMondayTest.php new file mode 100644 index 000000000..e2aaaf00c --- /dev/null +++ b/tests/Australia/AustralianCapitalTerritory/AnzacDayMondayTest.php @@ -0,0 +1,103 @@ + + */ + +namespace Yasumi\tests\Australia\AustralianCapitalTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing ANZAC Day Monday substitute in Australian Capital Territory (Australia). + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is a public holiday. + */ +class AnzacDayMondayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'anzacDayMonday'; + + /** + * Tests ANZAC Day Monday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2020, '2020-04-27'], // April 25 = Saturday → Monday 27th + [2021, '2021-04-26'], // April 25 = Sunday → Monday 26th + [2026, '2026-04-27'], // April 25 = Saturday → Monday 27th + ]; + } + + /** + * Tests that ANZAC Day Monday is NOT a holiday when April 25 is a weekday. + * + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2019); + $this->assertNotHoliday($this->region, self::HOLIDAY, 2022); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + 2026, + [self::LOCALE => 'ANZAC Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, 2026, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php index b92905446..096458691 100644 --- a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php +++ b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryBaseTestCase.php @@ -28,10 +28,10 @@ abstract class AustralianCapitalTerritoryBaseTestCase extends AustraliaBaseTestC use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/ACT'; + public const TIMEZONE = 'Australia/Sydney'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\AustralianCapitalTerritory'; - public string $timezone = 'Australia/ACT'; + public string $timezone = 'Australia/Sydney'; } diff --git a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php index fd4717c6c..4c0776fae 100644 --- a/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php +++ b/tests/Australia/AustralianCapitalTerritory/AustralianCapitalTerritoryTest.php @@ -55,7 +55,7 @@ public function testOfficialHolidays(): void 'anzacDay', 'easter', 'easterSaturday', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', 'canberraDay', 'reconciliationDay', @@ -65,6 +65,11 @@ public function testOfficialHolidays(): void $expectedHolidays[] = 'nationalDayOfMourning'; } + $anzacDay = new \DateTime("{$this->year}-04-25", new \DateTimeZone(self::TIMEZONE)); + if ($this->year >= 2020 && in_array((int) $anzacDay->format('w'), [0, 6], true)) { + $expectedHolidays[] = 'anzacDayMonday'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } diff --git a/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php b/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php index b945dcf3f..c15bd3040 100644 --- a/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php +++ b/tests/Australia/AustralianCapitalTerritory/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\AustralianCapitalTerritory; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Australian Capital Territory (Australia).. + * Class for testing Monarch's Birthday in Australian Capital Territory (Australia).. */ class QueensBirthdayTest extends AustralianCapitalTerritoryBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends AustralianCapitalTerritoryBaseTestCase implemen public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/MonarchsBirthdayTransitionTestTrait.php b/tests/Australia/MonarchsBirthdayTransitionTestTrait.php new file mode 100644 index 000000000..c7d1551dd --- /dev/null +++ b/tests/Australia/MonarchsBirthdayTransitionTestTrait.php @@ -0,0 +1,75 @@ + + */ + +namespace Yasumi\tests\Australia; + +use Yasumi\Holiday; +use Yasumi\Yasumi; + +trait MonarchsBirthdayTransitionTestTrait +{ + /** + * Tests the 2022 to 2023 monarchy transition and deprecated holiday alias. + * + * @throws \Exception + */ + public function testMonarchsBirthdayNameTransition(): void + { + $this->assertTranslatedHolidayName( + $this->region, + 'monarchsBirthday', + 2022, + ['en_AU' => 'Queen’s Birthday'] + ); + $this->assertTranslatedHolidayName( + $this->region, + 'monarchsBirthday', + 2023, + ['en_AU' => 'King’s Birthday'] + ); + $this->assertTranslatedHolidayName( + $this->region, + 'queensBirthday', + 2022, + ['en_AU' => 'Queen’s Birthday'] + ); + $this->assertTranslatedHolidayName( + $this->region, + 'queensBirthday', + 2023, + ['en_AU' => 'King’s Birthday'] + ); + } + + /** + * Tests the deprecated Queen's Birthday key aliases the Monarch's Birthday date. + * + * @throws \Exception + */ + public function testQueensBirthdayAliasMatchesMonarchsBirthday(): void + { + foreach ([2022, 2023] as $year) { + $holidays = Yasumi::create($this->region, $year); + $monarchsBirthday = $holidays->getHoliday('monarchsBirthday'); + $queensBirthday = $holidays->getHoliday('queensBirthday'); + + self::assertInstanceOf(Holiday::class, $monarchsBirthday); + self::assertInstanceOf(Holiday::class, $queensBirthday); + self::assertSame($monarchsBirthday->format('Y-m-d'), $queensBirthday->format('Y-m-d')); + } + } +} diff --git a/tests/Australia/NewSouthWales/AnzacDayMondayTest.php b/tests/Australia/NewSouthWales/AnzacDayMondayTest.php new file mode 100644 index 000000000..cca952027 --- /dev/null +++ b/tests/Australia/NewSouthWales/AnzacDayMondayTest.php @@ -0,0 +1,103 @@ + + */ + +namespace Yasumi\tests\Australia\NewSouthWales; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing ANZAC Day Monday substitute in New South Wales (Australia). + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is a public holiday. + */ +class AnzacDayMondayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'anzacDayMonday'; + + /** + * Tests ANZAC Day Monday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2026, '2026-04-27'], // April 25 = Saturday → Monday 27th + [2027, '2027-04-26'], // April 25 = Sunday → Monday 26th + ]; + } + + /** + * Tests that ANZAC Day Monday is NOT a holiday when April 25 is a weekday. + * + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2021); + $this->assertNotHoliday($this->region, self::HOLIDAY, 2025); + $this->assertNotHoliday($this->region, self::HOLIDAY, 2022); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + 2027, + [self::LOCALE => 'ANZAC Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, 2027, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php b/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php index a2e8f801a..60c265d47 100644 --- a/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php +++ b/tests/Australia/NewSouthWales/NewSouthWalesBaseTestCase.php @@ -28,10 +28,10 @@ abstract class NewSouthWalesBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/NSW'; + public const TIMEZONE = 'Australia/Sydney'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\NewSouthWales'; - public string $timezone = 'Australia/NSW'; + public string $timezone = 'Australia/Sydney'; } diff --git a/tests/Australia/NewSouthWales/NewSouthWalesTest.php b/tests/Australia/NewSouthWales/NewSouthWalesTest.php index 995eec31f..e21214105 100644 --- a/tests/Australia/NewSouthWales/NewSouthWalesTest.php +++ b/tests/Australia/NewSouthWales/NewSouthWalesTest.php @@ -55,7 +55,7 @@ public function testOfficialHolidays(): void 'anzacDay', 'easter', 'easterSaturday', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', ]; @@ -63,6 +63,10 @@ public function testOfficialHolidays(): void $holidays[] = 'nationalDayOfMourning'; } + if (2026 === $this->year || 2027 === $this->year) { + $holidays[] = 'anzacDayMonday'; + } + $this->assertDefinedHolidays($holidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } diff --git a/tests/Australia/NewSouthWales/QueensBirthdayTest.php b/tests/Australia/NewSouthWales/QueensBirthdayTest.php index a81507681..226526981 100644 --- a/tests/Australia/NewSouthWales/QueensBirthdayTest.php +++ b/tests/Australia/NewSouthWales/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\NewSouthWales; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in New South Wales (Australia).. + * Class for testing Monarch's Birthday in New South Wales (Australia).. */ class QueensBirthdayTest extends NewSouthWalesBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends NewSouthWalesBaseTestCase implements HolidayTes public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/NorthernTerritory/AnzacDayMondayTest.php b/tests/Australia/NorthernTerritory/AnzacDayMondayTest.php new file mode 100644 index 000000000..83bc654a7 --- /dev/null +++ b/tests/Australia/NorthernTerritory/AnzacDayMondayTest.php @@ -0,0 +1,100 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing ANZAC Day Monday substitute in Northern Territory (Australia). + */ +class AnzacDayMondayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'anzacDayMonday'; + + /** + * Tests ANZAC Day Monday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2027, '2027-04-26'], + [2032, '2032-04-26'], + ]; + } + + /** + * Tests that ANZAC Day Monday is not defined when April 25 is not a Sunday. + * + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2026); + $this->assertNotHoliday($this->region, self::HOLIDAY, 2028); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + 2027, + [self::LOCALE => 'ANZAC Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, 2027, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NorthernTerritory/EasterSundayTest.php b/tests/Australia/NorthernTerritory/EasterSundayTest.php new file mode 100644 index 000000000..1ab58574b --- /dev/null +++ b/tests/Australia/NorthernTerritory/EasterSundayTest.php @@ -0,0 +1,97 @@ + + */ + +namespace Yasumi\tests\Australia\NorthernTerritory; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in Northern Territory (Australia). + */ +class EasterSundayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php b/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php index d4be2ce9d..7c4a05376 100644 --- a/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php +++ b/tests/Australia/NorthernTerritory/NorthernTerritoryBaseTestCase.php @@ -28,10 +28,10 @@ abstract class NorthernTerritoryBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/North'; + public const TIMEZONE = 'Australia/Darwin'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\NorthernTerritory'; - public string $timezone = 'Australia/North'; + public string $timezone = 'Australia/Darwin'; } diff --git a/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php b/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php index 746a52884..efde3363c 100644 --- a/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php +++ b/tests/Australia/NorthernTerritory/NorthernTerritoryTest.php @@ -54,7 +54,8 @@ public function testOfficialHolidays(): void 'australiaDay', 'anzacDay', 'easterSaturday', - 'queensBirthday', + 'easter', + 'monarchsBirthday', 'mayDay', 'picnicDay', ]; @@ -63,6 +64,11 @@ public function testOfficialHolidays(): void $expectedHolidays[] = 'nationalDayOfMourning'; } + $anzacDay = new \DateTime("{$this->year}-04-25", new \DateTimeZone(self::TIMEZONE)); + if (0 === (int) $anzacDay->format('w')) { + $expectedHolidays[] = 'anzacDayMonday'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } diff --git a/tests/Australia/NorthernTerritory/QueensBirthdayTest.php b/tests/Australia/NorthernTerritory/QueensBirthdayTest.php index c9aa98c09..4015b8d5b 100644 --- a/tests/Australia/NorthernTerritory/QueensBirthdayTest.php +++ b/tests/Australia/NorthernTerritory/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\NorthernTerritory; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Northern Territory (Australia). + * Class for testing Monarch's Birthday in Northern Territory (Australia). */ class QueensBirthdayTest extends NorthernTerritoryBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends NorthernTerritoryBaseTestCase implements Holida public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/Queensland/Brisbane/BrisbaneTest.php b/tests/Australia/Queensland/Brisbane/BrisbaneTest.php index a5dbea8a1..7e39d11b5 100644 --- a/tests/Australia/Queensland/Brisbane/BrisbaneTest.php +++ b/tests/Australia/Queensland/Brisbane/BrisbaneTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', 'peoplesDay', ]; diff --git a/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php b/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php index cda565a91..6fafe33a0 100644 --- a/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php +++ b/tests/Australia/Queensland/Brisbane/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Queensland\Brisbane; /** - * Class for testing Queen's Birthday in Brisbane (Australia).. + * Class for testing Monarch's Birthday in Brisbane (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Queensland\QueensBirthdayTest { diff --git a/tests/Australia/Queensland/EasterSaturdayTest.php b/tests/Australia/Queensland/EasterSaturdayTest.php new file mode 100644 index 000000000..2db0460ff --- /dev/null +++ b/tests/Australia/Queensland/EasterSaturdayTest.php @@ -0,0 +1,98 @@ + + */ + +namespace Yasumi\tests\Australia\Queensland; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Saturday in Queensland (Australia). + */ +class EasterSaturdayTest extends QueenslandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easterSaturday'; + + /** + * Tests Easter Saturday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(); + $date = static::computeEaster($year, self::TIMEZONE); + $date->sub(new \DateInterval('P1D')); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(), + [self::LOCALE => 'Easter Saturday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/Queensland/EasterSundayTest.php b/tests/Australia/Queensland/EasterSundayTest.php new file mode 100644 index 000000000..bb0572c85 --- /dev/null +++ b/tests/Australia/Queensland/EasterSundayTest.php @@ -0,0 +1,105 @@ + + */ + +namespace Yasumi\tests\Australia\Queensland; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in Queensland (Australia). + */ +class EasterSundayTest extends QueenslandBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(2017); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2017), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2016); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(2017), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/Queensland/LabourDayTest.php b/tests/Australia/Queensland/LabourDayTest.php index 35c73e0b4..96e0f0a4f 100644 --- a/tests/Australia/Queensland/LabourDayTest.php +++ b/tests/Australia/Queensland/LabourDayTest.php @@ -52,7 +52,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -68,6 +68,9 @@ public static function HolidayDataProvider(): array [2018, '2018-05-07'], [2019, '2019-05-06'], [2020, '2020-05-04'], + [2024, '2024-05-06'], + [2025, '2025-05-05'], + [2026, '2026-05-04'], ]; } diff --git a/tests/Australia/Queensland/QueensBirthdayTest.php b/tests/Australia/Queensland/QueensBirthdayTest.php index 8d3f14f67..4a9d3c790 100644 --- a/tests/Australia/Queensland/QueensBirthdayTest.php +++ b/tests/Australia/Queensland/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\Queensland; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Queensland (Australia).. + * Class for testing Monarch's Birthday in Queensland (Australia).. */ class QueensBirthdayTest extends QueenslandBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends QueenslandBaseTestCase implements HolidayTestCa public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-10-01'], [2019, '2019-10-07'], [2020, '2020-10-05'], + [2021, '2021-10-04'], + [2022, '2022-10-03'], + [2023, '2023-10-02'], + [2024, '2024-10-07'], + [2025, '2025-10-06'], + [2026, '2026-10-05'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/Queensland/QueenslandBaseTestCase.php b/tests/Australia/Queensland/QueenslandBaseTestCase.php index d27d7965e..5146413e1 100644 --- a/tests/Australia/Queensland/QueenslandBaseTestCase.php +++ b/tests/Australia/Queensland/QueenslandBaseTestCase.php @@ -28,10 +28,10 @@ abstract class QueenslandBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/Queensland'; + public const TIMEZONE = 'Australia/Brisbane'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\Queensland'; - public string $timezone = 'Australia/Queensland'; + public string $timezone = 'Australia/Brisbane'; } diff --git a/tests/Australia/Queensland/QueenslandTest.php b/tests/Australia/Queensland/QueenslandTest.php index d291e2364..b97e3edf5 100644 --- a/tests/Australia/Queensland/QueenslandTest.php +++ b/tests/Australia/Queensland/QueenslandTest.php @@ -53,9 +53,15 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', + 'easterSaturday', ]; + + if ($this->year >= 2017) { + $expectedHolidays[] = 'easter'; + } + if (2022 === $this->year) { $expectedHolidays[] = 'nationalDayOfMourning'; } diff --git a/tests/Australia/SouthAustralia/EasterSundayTest.php b/tests/Australia/SouthAustralia/EasterSundayTest.php new file mode 100644 index 000000000..a297dfe30 --- /dev/null +++ b/tests/Australia/SouthAustralia/EasterSundayTest.php @@ -0,0 +1,109 @@ + + */ + +namespace Yasumi\tests\Australia\SouthAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in South Australia (Australia). + * + * Easter Sunday is only a public holiday from 2024 onwards (via Public Holidays Act 2023). + */ +class EasterSundayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(2024); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests that Easter Sunday is NOT a holiday before 2024. + * + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2023); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2024), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(2024), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/SouthAustralia/ProclamationDayTest.php b/tests/Australia/SouthAustralia/ProclamationDayTest.php index dddd26513..6baa0f33b 100644 --- a/tests/Australia/SouthAustralia/ProclamationDayTest.php +++ b/tests/Australia/SouthAustralia/ProclamationDayTest.php @@ -52,7 +52,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -68,6 +68,40 @@ public static function HolidayDataProvider(): array [2018, '2018-12-26'], [2019, '2019-12-26'], [2020, '2020-12-28'], + [2024, '2024-12-26'], + [2025, '2025-12-26'], + [2026, '2026-12-26'], + ]; + } + + /** + * Tests substitute Proclamation Day. + * + * @param int $year the year for which the substitute holiday needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('SubstituteHolidayDataProvider')] + public function testSubstituteHoliday(int $year, string $expected): void + { + $this->assertSubstituteHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of substitute holiday test dates. + * + * @return array list of test dates for substitute Proclamation Day + */ + public static function SubstituteHolidayDataProvider(): array + { + return [ + [2026, '2026-12-28'], ]; } diff --git a/tests/Australia/SouthAustralia/QueensBirthdayTest.php b/tests/Australia/SouthAustralia/QueensBirthdayTest.php index f01e518ad..cd99eadd3 100644 --- a/tests/Australia/SouthAustralia/QueensBirthdayTest.php +++ b/tests/Australia/SouthAustralia/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\SouthAustralia; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in South Australia (Australia).. + * Class for testing Monarch's Birthday in South Australia (Australia).. */ class QueensBirthdayTest extends SouthAustraliaBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends SouthAustraliaBaseTestCase implements HolidayTe public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php b/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php index e81e15457..6b48da2b8 100644 --- a/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php +++ b/tests/Australia/SouthAustralia/SouthAustraliaBaseTestCase.php @@ -28,10 +28,10 @@ abstract class SouthAustraliaBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/South'; + public const TIMEZONE = 'Australia/Adelaide'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\SouthAustralia'; - public string $timezone = 'Australia/South'; + public string $timezone = 'Australia/Adelaide'; } diff --git a/tests/Australia/SouthAustralia/SouthAustraliaTest.php b/tests/Australia/SouthAustralia/SouthAustraliaTest.php index 030ba90bd..c143acdc2 100644 --- a/tests/Australia/SouthAustralia/SouthAustraliaTest.php +++ b/tests/Australia/SouthAustralia/SouthAustraliaTest.php @@ -54,13 +54,22 @@ public function testOfficialHolidays(): void 'australiaDay', 'anzacDay', 'easterSaturday', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', 'adelaideCup', ]; if (2022 === $this->year) { $expectedHolidays[] = 'nationalDayOfMourning'; } + + if ($this->year >= 2024) { + $expectedHolidays[] = 'easter'; + } + + if (2026 === $this->year) { + $expectedHolidays[] = 'substituteHoliday:proclamationDay'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); } diff --git a/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php b/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php index 9c29788ae..c72453e40 100644 --- a/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php +++ b/tests/Australia/Tasmania/CentralNorth/CentralNorthTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'devonportShow', diff --git a/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php b/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php index 11419c8fb..b2e6a54b3 100644 --- a/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/CentralNorth/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\CentralNorth; /** - * Class for testing Queen's Birthday in central north Tasmania (Australia).. + * Class for testing Monarch's Birthday in central north Tasmania (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php index c62151902..186375568 100644 --- a/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/FlindersIslandTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'flindersIslandShow', diff --git a/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php b/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php index 4de25bac8..202486621 100644 --- a/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/FlindersIsland/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\FlindersIsland; /** - * Class for testing Queen's Birthday in Flinders Island (Australia).. + * Class for testing Monarch's Birthday in Flinders Island (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/KingIsland/KingIslandTest.php b/tests/Australia/Tasmania/KingIsland/KingIslandTest.php index 6d3dc16af..66f8dcc6d 100644 --- a/tests/Australia/Tasmania/KingIsland/KingIslandTest.php +++ b/tests/Australia/Tasmania/KingIsland/KingIslandTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'kingIslandShow', diff --git a/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php b/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php index f994c01c3..beb3385aa 100644 --- a/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/KingIsland/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\KingIsland; /** - * Class for testing Queen's Birthday in King Island (Australia).. + * Class for testing Monarch's Birthday in King Island (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/Northeast/NortheastTest.php b/tests/Australia/Tasmania/Northeast/NortheastTest.php index 218199f4c..91cf4c73e 100644 --- a/tests/Australia/Tasmania/Northeast/NortheastTest.php +++ b/tests/Australia/Tasmania/Northeast/NortheastTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'launcestonShow', diff --git a/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php index 026aec886..3f8053368 100644 --- a/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northeast/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\Northeast; /** - * Class for testing Queen's Birthday in northeast Tasmania (Australia).. + * Class for testing Monarch's Birthday in northeast Tasmania (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php index 62eabdf0a..65b7001b3 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/CircularHeadTest.php @@ -52,7 +52,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'burnieShow', diff --git a/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php index d0ed1e5c4..87f97703a 100644 --- a/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northwest/CircularHead/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\Northwest\CircularHead; /** - * Class for testing Queen's Birthday in Circular Head (Australia).. + * Class for testing Monarch's Birthday in Circular Head (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\Northwest\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/Northwest/NorthwestTest.php b/tests/Australia/Tasmania/Northwest/NorthwestTest.php index fb1de0c14..335f6d013 100644 --- a/tests/Australia/Tasmania/Northwest/NorthwestTest.php +++ b/tests/Australia/Tasmania/Northwest/NorthwestTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'burnieShow', diff --git a/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php b/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php index 89fe4db23..19074144d 100644 --- a/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/Northwest/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\Northwest; /** - * Class for testing Queen's Birthday in northwest Tasmania (Australia).. + * Class for testing Monarch's Birthday in northwest Tasmania (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/QueensBirthdayTest.php b/tests/Australia/Tasmania/QueensBirthdayTest.php index 255009155..0ce0ecfdd 100644 --- a/tests/Australia/Tasmania/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\Tasmania; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Tasmania (Australia).. + * Class for testing Monarch's Birthday in Tasmania (Australia).. */ class QueensBirthdayTest extends TasmaniaBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends TasmaniaBaseTestCase implements HolidayTestCase public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/Tasmania/South/QueensBirthdayTest.php b/tests/Australia/Tasmania/South/QueensBirthdayTest.php index 93e51a1b9..9cfa99790 100644 --- a/tests/Australia/Tasmania/South/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/South/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\South; /** - * Class for testing Queen's Birthday in southe0rn Tasmania (Australia).. + * Class for testing Monarch's Birthday in southe0rn Tasmania (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/South/SouthTest.php b/tests/Australia/Tasmania/South/SouthTest.php index 67c2b1fc0..3ca99befc 100644 --- a/tests/Australia/Tasmania/South/SouthTest.php +++ b/tests/Australia/Tasmania/South/SouthTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', 'hobartShow', diff --git a/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php b/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php index 32d2ae81d..0457bc48c 100644 --- a/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php +++ b/tests/Australia/Tasmania/South/Southeast/QueensBirthdayTest.php @@ -18,7 +18,7 @@ namespace Yasumi\tests\Australia\Tasmania\South\Southeast; /** - * Class for testing Queen's Birthday in southeastern Tasmania (Australia).. + * Class for testing Monarch's Birthday in southeastern Tasmania (Australia).. */ class QueensBirthdayTest extends \Yasumi\tests\Australia\Tasmania\South\QueensBirthdayTest { diff --git a/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php b/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php index 8d4f0f59b..e926c5406 100644 --- a/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php +++ b/tests/Australia/Tasmania/South/Southeast/SoutheastTest.php @@ -52,7 +52,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'hobartShow', 'hobartRegatta', diff --git a/tests/Australia/Tasmania/TasmaniaBaseTestCase.php b/tests/Australia/Tasmania/TasmaniaBaseTestCase.php index 6bd6d3e77..b8bd3cede 100644 --- a/tests/Australia/Tasmania/TasmaniaBaseTestCase.php +++ b/tests/Australia/Tasmania/TasmaniaBaseTestCase.php @@ -28,10 +28,10 @@ abstract class TasmaniaBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/Tasmania'; + public const TIMEZONE = 'Australia/Hobart'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\Tasmania'; - public string $timezone = 'Australia/Tasmania'; + public string $timezone = 'Australia/Hobart'; } diff --git a/tests/Australia/Tasmania/TasmaniaTest.php b/tests/Australia/Tasmania/TasmaniaTest.php index 9f4347e08..93078661c 100644 --- a/tests/Australia/Tasmania/TasmaniaTest.php +++ b/tests/Australia/Tasmania/TasmaniaTest.php @@ -53,7 +53,7 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'eightHourDay', 'recreationDay', ]; diff --git a/tests/Australia/Victoria/AFLGrandFinalFridayTest.php b/tests/Australia/Victoria/AFLGrandFinalFridayTest.php index 2b10ce91d..340ec57c5 100644 --- a/tests/Australia/Victoria/AFLGrandFinalFridayTest.php +++ b/tests/Australia/Victoria/AFLGrandFinalFridayTest.php @@ -31,7 +31,7 @@ class AFLGrandFinalFridayTest extends VictoriaBaseTestCase implements HolidayTes public const HOLIDAY = 'aflGrandFinalFriday'; public const ESTABLISHMENT_YEAR = 2015; - public const LAST_KNOWN_YEAR = 2020; + public const LAST_KNOWN_YEAR = 2025; /** * Tests AFL Grand Final Friday. @@ -104,6 +104,11 @@ public static function HolidayDataProvider(): array [2018, '2018-09-28'], [2019, '2019-09-27'], [2020, '2020-09-25'], + [2021, '2021-09-24'], + [2022, '2022-09-23'], + [2023, '2023-09-29'], + [2024, '2024-09-27'], + [2025, '2025-09-26'], ]; } } diff --git a/tests/Australia/Victoria/QueensBirthdayTest.php b/tests/Australia/Victoria/QueensBirthdayTest.php index b8a7cd95d..fe9210a43 100644 --- a/tests/Australia/Victoria/QueensBirthdayTest.php +++ b/tests/Australia/Victoria/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\Victoria; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Victoria (Australia).. + * Class for testing Monarch's Birthday in Victoria (Australia).. */ class QueensBirthdayTest extends VictoriaBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends VictoriaBaseTestCase implements HolidayTestCase public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-06-11'], [2019, '2019-06-10'], [2020, '2020-06-08'], + [2021, '2021-06-14'], + [2022, '2022-06-13'], + [2023, '2023-06-12'], + [2024, '2024-06-10'], + [2025, '2025-06-09'], + [2026, '2026-06-08'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/Victoria/VictoriaBaseTestCase.php b/tests/Australia/Victoria/VictoriaBaseTestCase.php index 06796c0e4..245f8caab 100644 --- a/tests/Australia/Victoria/VictoriaBaseTestCase.php +++ b/tests/Australia/Victoria/VictoriaBaseTestCase.php @@ -28,10 +28,10 @@ abstract class VictoriaBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/Victoria'; + public const TIMEZONE = 'Australia/Melbourne'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\Victoria'; - public string $timezone = 'Australia/Victoria'; + public string $timezone = 'Australia/Melbourne'; } diff --git a/tests/Australia/Victoria/VictoriaTest.php b/tests/Australia/Victoria/VictoriaTest.php index d3558e5fd..f5658cddb 100644 --- a/tests/Australia/Victoria/VictoriaTest.php +++ b/tests/Australia/Victoria/VictoriaTest.php @@ -37,7 +37,7 @@ class VictoriaTest extends VictoriaBaseTestCase implements ProviderTestCase */ protected function setUp(): void { - $this->year = static::generateRandomYear(2015, 2018); + $this->year = static::generateRandomYear(2015, 2026); } /** @@ -55,11 +55,15 @@ public function testOfficialHolidays(): void 'anzacDay', 'easter', 'easterSaturday', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', - 'aflGrandFinalFriday', 'melbourneCup', ]; + + if ($this->year <= 2025) { + $expectedHolidays[] = 'aflGrandFinalFriday'; + } + if (2022 === $this->year) { $expectedHolidays[] = 'nationalDayOfMourning'; } diff --git a/tests/Australia/WesternAustralia/AnzacDayMondayTest.php b/tests/Australia/WesternAustralia/AnzacDayMondayTest.php new file mode 100644 index 000000000..3eb3f7e3b --- /dev/null +++ b/tests/Australia/WesternAustralia/AnzacDayMondayTest.php @@ -0,0 +1,105 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing ANZAC Day Monday substitute in Western Australia (Australia). + * + * When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is a public holiday. + */ +class AnzacDayMondayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'anzacDayMonday'; + + /** + * Tests ANZAC Day Monday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + */ + public static function HolidayDataProvider(): array + { + return [ + [2015, '2015-04-27'], // April 25 = Saturday → Monday 27th + [2020, '2020-04-27'], // April 25 = Saturday → Monday 27th + [2021, '2021-04-26'], // April 25 = Sunday → Monday 26th + [2026, '2026-04-27'], // April 25 = Saturday → Monday 27th + ]; + } + + /** + * Tests that ANZAC Day Monday is NOT a holiday when April 25 is a weekday. + * + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 1931); + // 2022: April 25 = Monday (weekday, no substitute) + $this->assertNotHoliday($this->region, self::HOLIDAY, 2022); + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + 2026, + [self::LOCALE => 'ANZAC Day'] + ); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, 2026, Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/WesternAustralia/EasterSundayTest.php b/tests/Australia/WesternAustralia/EasterSundayTest.php new file mode 100644 index 000000000..cefcd7bf3 --- /dev/null +++ b/tests/Australia/WesternAustralia/EasterSundayTest.php @@ -0,0 +1,105 @@ + + */ + +namespace Yasumi\tests\Australia\WesternAustralia; + +use Yasumi\Holiday; +use Yasumi\tests\HolidayTestCase; + +/** + * Class for testing Easter Sunday in Western Australia (Australia). + */ +class EasterSundayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase +{ + /** + * The name of the holiday. + */ + public const HOLIDAY = 'easter'; + + /** + * Tests Easter Sunday. + * + * @param int $year the year for which the holiday defined in this test needs to be tested + * @param string $expected the expected date + * + * @throws \Exception + */ + #[\PHPUnit\Framework\Attributes\DataProvider('HolidayDataProvider')] + public function testHoliday(int $year, string $expected): void + { + $this->assertHoliday( + $this->region, + self::HOLIDAY, + $year, + new \DateTime($expected, new \DateTimeZone($this->timezone)) + ); + } + + /** + * Returns a list of test dates. + * + * @return array list of test dates for the holiday defined in this test + * + * @throws \Exception + */ + public static function HolidayDataProvider(): array + { + $data = []; + + for ($y = 0; $y < 50; ++$y) { + $year = static::generateRandomYear(2022); + $date = static::computeEaster($year, self::TIMEZONE); + + $data[] = [$year, $date->format('Y-m-d')]; + } + + return $data; + } + + /** + * Tests the translated name of the holiday defined in this test. + * + * @throws \Exception + */ + public function testTranslation(): void + { + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2022), + [self::LOCALE => 'Easter Sunday'] + ); + } + + /** + * @throws \Exception + */ + public function testNotHoliday(): void + { + $this->assertNotHoliday($this->region, self::HOLIDAY, 2021); + } + + /** + * Tests type of the holiday defined in this test. + * + * @throws \Exception + */ + public function testHolidayType(): void + { + $this->assertHolidayType($this->region, self::HOLIDAY, static::generateRandomYear(2022), Holiday::TYPE_OFFICIAL); + } +} diff --git a/tests/Australia/WesternAustralia/QueensBirthdayTest.php b/tests/Australia/WesternAustralia/QueensBirthdayTest.php index 0ea4590c5..0a0acbaff 100644 --- a/tests/Australia/WesternAustralia/QueensBirthdayTest.php +++ b/tests/Australia/WesternAustralia/QueensBirthdayTest.php @@ -18,17 +18,20 @@ namespace Yasumi\tests\Australia\WesternAustralia; use Yasumi\Holiday; +use Yasumi\tests\Australia\MonarchsBirthdayTransitionTestTrait; use Yasumi\tests\HolidayTestCase; /** - * Class for testing Queen's Birthday in Western Australia (Australia).. + * Class for testing Monarch's Birthday in Western Australia (Australia).. */ class QueensBirthdayTest extends WesternAustraliaBaseTestCase implements HolidayTestCase { + use MonarchsBirthdayTransitionTestTrait; + /** * The name of the holiday. */ - public const HOLIDAY = 'queensBirthday'; + public const HOLIDAY = 'monarchsBirthday'; /** * The year in which the holiday was first established. @@ -36,7 +39,7 @@ class QueensBirthdayTest extends WesternAustraliaBaseTestCase implements Holiday public const ESTABLISHMENT_YEAR = 1950; /** - * Tests Queen's Birthday. + * Tests Monarch's Birthday. * * @param int $year the year for which the holiday defined in this test needs to be tested * @param string $expected the expected date @@ -57,7 +60,7 @@ public function testHoliday(int $year, string $expected): void /** * Returns a list of test dates. * - * @return array list of test dates for the holiday defined in this test + * @return array list of test dates for the holiday defined in this test */ public static function HolidayDataProvider(): array { @@ -73,6 +76,12 @@ public static function HolidayDataProvider(): array [2018, '2018-09-24'], [2019, '2019-09-30'], [2020, '2020-09-28'], + [2021, '2021-09-27'], + [2022, '2022-09-26'], + [2023, '2023-09-25'], + [2024, '2024-09-23'], + [2025, '2025-09-29'], + [2026, '2026-09-28'], ]; } @@ -86,9 +95,15 @@ public function testTranslation(): void $this->assertTranslatedHolidayName( $this->region, self::HOLIDAY, - static::generateRandomYear(self::ESTABLISHMENT_YEAR), + static::generateRandomYear(self::ESTABLISHMENT_YEAR, 2022), [self::LOCALE => 'Queen’s Birthday'] ); + $this->assertTranslatedHolidayName( + $this->region, + self::HOLIDAY, + static::generateRandomYear(2023), + [self::LOCALE => 'King’s Birthday'] + ); } /** diff --git a/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php b/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php index e57df32e4..880cf8193 100644 --- a/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php +++ b/tests/Australia/WesternAustralia/WesternAustraliaBaseTestCase.php @@ -28,10 +28,10 @@ abstract class WesternAustraliaBaseTestCase extends AustraliaBaseTestCase use YasumiBase; /** Timezone in which this provider has holidays defined. */ - public const TIMEZONE = 'Australia/West'; + public const TIMEZONE = 'Australia/Perth'; /** Name of the region (e.g. country / state) to be tested. */ public string $region = 'Australia\WesternAustralia'; - public string $timezone = 'Australia/West'; + public string $timezone = 'Australia/Perth'; } diff --git a/tests/Australia/WesternAustralia/WesternAustraliaTest.php b/tests/Australia/WesternAustralia/WesternAustraliaTest.php index 408b5e2ae..b5234c7f6 100644 --- a/tests/Australia/WesternAustralia/WesternAustraliaTest.php +++ b/tests/Australia/WesternAustralia/WesternAustraliaTest.php @@ -53,13 +53,24 @@ public function testOfficialHolidays(): void 'secondChristmasDay', 'australiaDay', 'anzacDay', - 'queensBirthday', + 'monarchsBirthday', 'labourDay', 'westernAustraliaDay', ]; + + if ($this->year >= 2022) { + $expectedHolidays[] = 'easter'; + } + if (2022 === $this->year) { $expectedHolidays[] = 'nationalDayOfMourning'; } + + $anzacDay = new \DateTime("{$this->year}-04-25", new \DateTimeZone(self::TIMEZONE)); + if ($this->year >= 1972 && in_array((int) $anzacDay->format('w'), [0, 6], true)) { + $expectedHolidays[] = 'anzacDayMonday'; + } + $this->assertDefinedHolidays($expectedHolidays, $this->region, $this->year, Holiday::TYPE_OFFICIAL); }