Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Yasumi/Provider/Australia.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Australia extends AbstractProvider
*/
public const ID = 'AU';

protected const MONARCHY_CHANGE_YEAR = 2023;

public string $timezone = 'Australia/Melbourne';

/**
Expand Down Expand Up @@ -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.
*
Expand Down
58 changes: 46 additions & 12 deletions src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
));
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -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))
);
}

/**
Expand Down
58 changes: 46 additions & 12 deletions src/Yasumi/Provider/Australia/NewSouthWales.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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
));
}

/**
Expand Down Expand Up @@ -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.
*
Expand All @@ -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))
);
}

/**
Expand Down
82 changes: 70 additions & 12 deletions src/Yasumi/Provider/Australia/NorthernTerritory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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();
}
Expand Down Expand Up @@ -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.
*
Expand All @@ -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))
);
}

/**
Expand Down
Loading