Skip to content

Commit 977bfd6

Browse files
committed
feat: update australian holidays and timezones
Signed-off-by: Aaron Florey <azza@jcaks.net>
1 parent 77a7d98 commit 977bfd6

61 files changed

Lines changed: 1595 additions & 157 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Yasumi/Provider/Australia/AustralianCapitalTerritory.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AustralianCapitalTerritory extends Australia
3333
*/
3434
public const ID = 'AU-ACT';
3535

36-
public string $timezone = 'Australia/ACT';
36+
public string $timezone = 'Australia/Sydney';
3737

3838
/**
3939
* Initialize holidays for Australian Capital Territory (Australia).
@@ -48,10 +48,48 @@ public function initialize(): void
4848

4949
$this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale));
5050
$this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale));
51-
$this->calculateQueensBirthday();
51+
$this->calculateMonarchsBirthday();
5252
$this->calculateLabourDay();
5353
$this->calculateCanberraDay();
5454
$this->calculateReconciliationDay();
55+
$this->calculateAnzacDayMonday();
56+
}
57+
58+
/**
59+
* ANZAC Day Monday substitute.
60+
*
61+
* When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is an additional public holiday
62+
* in this state/territory.
63+
*
64+
* @see https://en.wikipedia.org/wiki/Anzac_Day
65+
* @see https://www.timeanddate.com/holidays/australia/anzac-day
66+
*
67+
* @throws \Exception
68+
*/
69+
protected function calculateAnzacDayMonday(): void
70+
{
71+
if ($this->year < 2020) {
72+
return;
73+
}
74+
75+
$date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone));
76+
$dow = (int) $date->format('w');
77+
78+
if (6 === $dow) { // Saturday → Monday
79+
$date->add(new \DateInterval('P2D'));
80+
} elseif (0 === $dow) { // Sunday → Monday
81+
$date->add(new \DateInterval('P1D'));
82+
} else {
83+
return;
84+
}
85+
86+
$this->addHoliday(new Holiday(
87+
'anzacDayMonday',
88+
['en' => 'ANZAC Day'],
89+
$date,
90+
$this->locale,
91+
Holiday::TYPE_OFFICIAL
92+
));
5593
}
5694

5795
/**
@@ -125,9 +163,9 @@ protected function easterSaturday(
125163
}
126164

127165
/**
128-
* Queens Birthday.
166+
* Monarch's Birthday.
129167
*
130-
* The Queen's Birthday is an Australian public holiday but the date varies across
168+
* The Monarch's Birthday is an Australian public holiday but the date varies across
131169
* states and territories. Australia celebrates this holiday because it is a constitutional
132170
* monarchy, with the English monarch as head of state.
133171
*
@@ -139,11 +177,13 @@ protected function easterSaturday(
139177
* @throws \InvalidArgumentException
140178
* @throws \Exception
141179
*/
142-
protected function calculateQueensBirthday(): void
180+
protected function calculateMonarchsBirthday(): void
143181
{
182+
$name = $this->year >= 2023 ? 'King’s Birthday' : 'Queen’s Birthday';
183+
144184
$this->addHoliday(new Holiday(
145-
'queensBirthday',
146-
[],
185+
'monarchsBirthday',
186+
['en' => $name],
147187
new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
148188
$this->locale,
149189
Holiday::TYPE_OFFICIAL

src/Yasumi/Provider/Australia/NewSouthWales.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class NewSouthWales extends Australia
3333
*/
3434
public const ID = 'AU-NSW';
3535

36-
public string $timezone = 'Australia/NSW';
36+
public string $timezone = 'Australia/Sydney';
3737

3838
/**
3939
* Initialize holidays for New South Wales (Australia).
@@ -48,9 +48,47 @@ public function initialize(): void
4848

4949
$this->addHoliday(new Holiday('easter', [], $this->calculateEaster($this->year, $this->timezone), $this->locale));
5050
$this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale));
51-
$this->calculateQueensBirthday();
51+
$this->calculateMonarchsBirthday();
5252
$this->calculateLabourDay();
5353
$this->calculateBankHoliday();
54+
$this->calculateAnzacDayMonday();
55+
}
56+
57+
/**
58+
* ANZAC Day Monday substitute.
59+
*
60+
* When ANZAC Day (April 25) falls on a Saturday or Sunday, the following Monday is an additional public holiday
61+
* in this state/territory.
62+
*
63+
* @see https://en.wikipedia.org/wiki/Anzac_Day
64+
* @see https://www.timeanddate.com/holidays/australia/anzac-day
65+
*
66+
* @throws \Exception
67+
*/
68+
protected function calculateAnzacDayMonday(): void
69+
{
70+
if ($this->year < 2026 || $this->year > 2027) {
71+
return;
72+
}
73+
74+
$date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone));
75+
$dow = (int) $date->format('w');
76+
77+
if (6 === $dow) { // Saturday → Monday
78+
$date->add(new \DateInterval('P2D'));
79+
} elseif (0 === $dow) { // Sunday → Monday
80+
$date->add(new \DateInterval('P1D'));
81+
} else {
82+
return;
83+
}
84+
85+
$this->addHoliday(new Holiday(
86+
'anzacDayMonday',
87+
['en' => 'ANZAC Day'],
88+
$date,
89+
$this->locale,
90+
Holiday::TYPE_OFFICIAL
91+
));
5492
}
5593

5694
/**
@@ -92,9 +130,9 @@ protected function easterSaturday(
92130
}
93131

94132
/**
95-
* Queens Birthday.
133+
* Monarch's Birthday.
96134
*
97-
* The Queen's Birthday is an Australian public holiday but the date varies across
135+
* The Monarch's Birthday is an Australian public holiday but the date varies across
98136
* states and territories. Australia celebrates this holiday because it is a constitutional
99137
* monarchy, with the English monarch as head of state.
100138
*
@@ -106,11 +144,13 @@ protected function easterSaturday(
106144
* @throws \InvalidArgumentException
107145
* @throws \Exception
108146
*/
109-
protected function calculateQueensBirthday(): void
147+
protected function calculateMonarchsBirthday(): void
110148
{
149+
$name = $this->year >= 2023 ? 'King’s Birthday' : 'Queen’s Birthday';
150+
111151
$this->addHoliday(new Holiday(
112-
'queensBirthday',
113-
[],
152+
'monarchsBirthday',
153+
['en' => $name],
114154
new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
115155
$this->locale,
116156
Holiday::TYPE_OFFICIAL

src/Yasumi/Provider/Australia/NorthernTerritory.php

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class NorthernTerritory extends Australia
3333
*/
3434
public const ID = 'AU-NT';
3535

36-
public string $timezone = 'Australia/North';
36+
public string $timezone = 'Australia/Darwin';
3737

3838
/**
3939
* Initialize holidays for Northern Territory (Australia).
@@ -47,7 +47,9 @@ public function initialize(): void
4747
parent::initialize();
4848

4949
$this->addHoliday($this->easterSaturday($this->year, $this->timezone, $this->locale));
50-
$this->calculateQueensBirthday();
50+
$this->addHoliday($this->easterSunday($this->year, $this->timezone, $this->locale));
51+
$this->calculateAnzacDayMonday();
52+
$this->calculateMonarchsBirthday();
5153
$this->calculateMayDay();
5254
$this->calculatePicnicDay();
5355
}
@@ -91,9 +93,69 @@ protected function easterSaturday(
9193
}
9294

9395
/**
94-
* Queens Birthday.
96+
* Easter Sunday.
9597
*
96-
* The Queen's Birthday is an Australian public holiday but the date varies across
98+
* Easter is a festival and holiday celebrating the resurrection of Jesus Christ from the dead. Easter is celebrated
99+
* on a date based on a certain number of days after March 21st. The date of Easter Day was defined by the Council
100+
* of Nicaea in AD325 as the Sunday after the first full moon which falls on or after the Spring Equinox.
101+
*
102+
* @see https://en.wikipedia.org/wiki/Easter
103+
*
104+
* @param int $year the year for which Easter Sunday need to be created
105+
* @param string $timezone the timezone in which Easter Sunday is celebrated
106+
* @param string $locale the locale for which Easter Sunday need to be displayed in
107+
* @param string|null $type The type of holiday. Use the following constants: TYPE_OFFICIAL, TYPE_OBSERVANCE,
108+
* TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default an official holiday is considered.
109+
*
110+
* @throws \Exception
111+
*/
112+
protected function easterSunday(
113+
int $year,
114+
string $timezone,
115+
string $locale,
116+
?string $type = null,
117+
): Holiday {
118+
return new Holiday(
119+
'easter',
120+
['en' => 'Easter Sunday'],
121+
$this->calculateEaster($year, $timezone),
122+
$locale,
123+
$type ?? Holiday::TYPE_OFFICIAL
124+
);
125+
}
126+
127+
/**
128+
* ANZAC Day Monday substitute.
129+
*
130+
* In the Northern Territory, a substitute public holiday is observed on the following Monday
131+
* when ANZAC Day falls on a Sunday.
132+
*
133+
* @see https://nt.gov.au/nt-public-holidays
134+
*
135+
* @throws \Exception
136+
*/
137+
protected function calculateAnzacDayMonday(): void
138+
{
139+
$date = new \DateTime("{$this->year}-04-25", DateTimeZoneFactory::getDateTimeZone($this->timezone));
140+
if ('0' !== $date->format('w')) {
141+
return;
142+
}
143+
144+
$date->add(new \DateInterval('P1D'));
145+
146+
$this->addHoliday(new Holiday(
147+
'anzacDayMonday',
148+
['en' => 'ANZAC Day'],
149+
$date,
150+
$this->locale,
151+
Holiday::TYPE_OFFICIAL
152+
));
153+
}
154+
155+
/**
156+
* Monarch's Birthday.
157+
*
158+
* The Monarch's Birthday is an Australian public holiday but the date varies across
97159
* states and territories. Australia celebrates this holiday because it is a constitutional
98160
* monarchy, with the English monarch as head of state.
99161
*
@@ -105,11 +167,13 @@ protected function easterSaturday(
105167
* @throws \InvalidArgumentException
106168
* @throws \Exception
107169
*/
108-
protected function calculateQueensBirthday(): void
170+
protected function calculateMonarchsBirthday(): void
109171
{
172+
$name = $this->year >= 2023 ? 'King’s Birthday' : 'Queen’s Birthday';
173+
110174
$this->addHoliday(new Holiday(
111-
'queensBirthday',
112-
[],
175+
'monarchsBirthday',
176+
['en' => $name],
113177
new \DateTime("second monday of june {$this->year}", DateTimeZoneFactory::getDateTimeZone($this->timezone)),
114178
$this->locale,
115179
Holiday::TYPE_OFFICIAL

0 commit comments

Comments
 (0)