Skip to content

Commit

Permalink
Refactor Australia holidays (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico committed Oct 26, 2023
1 parent 68867a9 commit 7d737a9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
66 changes: 33 additions & 33 deletions holidays/countries/australia.py
Expand Up @@ -9,10 +9,7 @@
# Website: https://github.com/dr-prodigy/python-holidays
# License: MIT (see LICENSE file)

from datetime import date
from datetime import timedelta as td

from holidays.calendars.gregorian import APR, JUN, AUG, SEP, OCT, FRI, _get_nth_weekday_from
from holidays.calendars.gregorian import JUN, AUG, SEP, OCT
from holidays.groups import ChristianHolidays, InternationalHolidays, StaticHolidays
from holidays.observed_holiday_base import (
ObservedHolidayBase,
Expand Down Expand Up @@ -76,30 +73,33 @@ def _populate(self, year):
else:
self._add_holiday_nov_9(self.sovereign_birthday) # Edward VII

# Christmas Day
self._add_observed(self._add_christmas_day("Christmas Day"), rule=SAT_SUN_TO_NEXT_MON_TUE)

def _add_subdiv_holidays(self):
# Australia Day
if self._year >= 1935:
name = (
jan_26 = self._add_holiday_jan_26(
"Anniversary Day"
if self.subdiv == "NSW" and self._year <= 1945
else "Australia Day"
)
jan_26 = self._add_holiday_jan_26(name)
if self._year >= 1946:
self._add_observed(jan_26)
elif self._year >= 1888 and self.subdiv != "SA":
self._add_holiday_jan_26("Anniversary Day")

# Anzac Day
if self._year >= 1921:
self._add_holiday_apr_25("Anzac Day")

# Christmas Day
self._add_observed(self._add_christmas_day("Christmas Day"), rule=SAT_SUN_TO_NEXT_MON_TUE)
self._add_anzac_day("Anzac Day")

# Boxing Day
name = "Proclamation Day" if self.subdiv == "SA" else "Boxing Day"
self._add_observed(self._add_christmas_day_two(name), rule=SAT_SUN_TO_NEXT_MON_TUE)
self._add_observed(
self._add_christmas_day_two(
"Proclamation Day" if self.subdiv == "SA" else "Boxing Day"
),
rule=SAT_SUN_TO_NEXT_MON_TUE,
)

super()._add_subdiv_holidays()

Expand All @@ -117,7 +117,7 @@ def _add_subdiv_act_holidays(self):

# Anzac Day
if self._year >= 1921:
self._add_observed(date(self._year, APR, 25), rule=SUN_TO_NEXT_MON)
self._add_observed(self._add_anzac_day("Anzac Day"), rule=SUN_TO_NEXT_MON)

# Canberra Day
# Info from https://www.timeanddate.com/holidays/australia/canberra-day
Expand All @@ -138,14 +138,14 @@ def _add_subdiv_act_holidays(self):
# TODO need a formula for the ACT school holidays then
# http://www.cmd.act.gov.au/communication/holidays
fc_dates = {
2010: date(2010, SEP, 26),
2011: date(2011, OCT, 10),
2012: date(2012, OCT, 8),
2013: date(2013, SEP, 30),
2014: date(2014, SEP, 29),
2015: date(2015, SEP, 28),
2016: date(2016, SEP, 26),
2017: date(2017, SEP, 25),
2010: (SEP, 26),
2011: (OCT, 10),
2012: (OCT, 8),
2013: (SEP, 30),
2014: (SEP, 29),
2015: (SEP, 28),
2016: (SEP, 26),
2017: (SEP, 25),
}
name = "Family & Community Day"
if self._year in fc_dates:
Expand Down Expand Up @@ -186,7 +186,7 @@ def _add_subdiv_nt_holidays(self):

# Anzac Day
if self._year >= 1921:
self._add_observed(date(self._year, APR, 25))
self._add_observed(self._add_anzac_day("Anzac Day"))

# Picnic Day
self._add_holiday_1st_mon_of_aug("Picnic Day")
Expand All @@ -212,7 +212,7 @@ def _add_subdiv_qld_holidays(self):

# Anzac Day
if self._year >= 1921:
self._add_observed((APR, 25), rule=SUN_TO_NEXT_MON)
self._add_observed(self._add_anzac_day("Anzac Day"), rule=SUN_TO_NEXT_MON)

# The Royal Queensland Show (Ekka)
# The Show starts on the first Friday of August - providing this is
Expand All @@ -226,9 +226,8 @@ def _add_subdiv_qld_holidays(self):
if self._year in ekka_dates:
self._add_holiday(name, ekka_dates[self._year])
else:
self._add_holiday(
name, _get_nth_weekday_from(+1, FRI, date(self._year, AUG, 5)) + td(days=+5)
)
# [1st FRI after Aug 5] + 5 days = [1st WED after Aug 10]
self._add_holiday_1st_wed_from_aug_10(name)

def _add_subdiv_sa_holidays(self):
# Easter
Expand All @@ -243,7 +242,7 @@ def _add_subdiv_sa_holidays(self):

# Anzac Day
if self._year >= 1921:
self._add_observed((APR, 25), rule=SUN_TO_NEXT_MON)
self._add_observed(self._add_anzac_day("Anzac Day"), rule=SUN_TO_NEXT_MON)

# Adelaide Cup
name = "Adelaide Cup"
Expand Down Expand Up @@ -279,10 +278,10 @@ def _add_subdiv_vic_holidays(self):
# Grand Final Day
grand_final_dates = {
# Rescheduled due to COVID-19
2020: date(2020, OCT, 23),
2020: (OCT, 23),
# Rescheduled due to COVID-19
2021: date(2021, SEP, 24),
2022: date(2022, SEP, 23),
2021: (SEP, 24),
2022: (SEP, 23),
}
name = "Grand Final Day"
if self._year in grand_final_dates:
Expand All @@ -300,12 +299,13 @@ def _add_subdiv_wa_holidays(self):

# Anzac Day
if self._year >= 1921:
self._add_observed(date(self._year, APR, 25))
self._add_observed(self._add_anzac_day("Anzac Day"))

# Western Australia Day
if self._year >= 1833:
name = "Western Australia Day" if self._year >= 2015 else "Foundation Day"
self._add_holiday_1st_mon_of_jun(name)
self._add_holiday_1st_mon_of_jun(
"Western Australia Day" if self._year >= 2015 else "Foundation Day"
)


class AU(Australia):
Expand Down
2 changes: 1 addition & 1 deletion holidays/countries/new_zealand.py
Expand Up @@ -111,7 +111,7 @@ def _populate(self, year):

# Anzac Day
if year >= 1921:
apr_25 = self._add_holiday_apr_25("Anzac Day")
apr_25 = self._add_anzac_day("Anzac Day")
if year >= 2014:
self._add_observed(apr_25)

Expand Down
15 changes: 15 additions & 0 deletions holidays/groups/international.py
Expand Up @@ -28,6 +28,21 @@ def _add_africa_day(self, name):
"""
return self._add_holiday_may_25(name)

def _add_anzac_day(self, name):
"""
Add Anzac Day (April 25th)
Anzac Day is a national day of remembrance in Australia and New Zealand
that broadly commemorates all Australians and New Zealanders "who
served and died in all wars, conflicts, and peacekeeping operations"
and "the contribution and suffering of all those who have served".
Anzac Day is a public holiday in Australia, New Zealand, and Tonga; it
used to be a public holiday in Samoa up until 2008.
https://en.wikipedia.org/wiki/Anzac_Day
"""
return self._add_holiday_apr_25(name)

def _add_childrens_day(self, name, variation="JUN"):
"""
Add International Children's Day (June 1).
Expand Down

0 comments on commit 7d737a9

Please sign in to comment.