Skip to content

Commit

Permalink
Fixes for Australian public holidays (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Gurcke authored and dr-prodigy committed Mar 8, 2019
1 parent ab3b148 commit 64d2366
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
34 changes: 18 additions & 16 deletions holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ class Australia(HolidayBase):

def __init__(self, **kwargs):
self.country = 'AU'
self.prov = kwargs.pop('prov', kwargs.pop('state', 'ACT'))
self.prov = kwargs.pop('prov', None)
HolidayBase.__init__(self, **kwargs)

def _populate(self, year):
Expand Down Expand Up @@ -1978,7 +1978,7 @@ def _populate(self, year):
self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"
if self.prov in ('ACT', 'NSW', 'NT', 'QLD', 'SA', 'VIC'):
self[easter(year) + rd(weekday=SA(-1))] = "Easter Saturday"
if self.prov == 'NSW':
if self.prov in ('ACT', 'NSW', 'QLD', 'VIC'):
self[easter(year)] = "Easter Sunday"
self[easter(year) + rd(weekday=MO)] = "Easter Monday"

Expand Down Expand Up @@ -2021,7 +2021,7 @@ def _populate(self, year):
elif self.prov == 'WA':
# by proclamation ?!?!
self[date(year, OCT, 1) + rd(weekday=MO(-1))] = name
else:
elif self.prov in ('NSW', 'VIC', 'ACT', 'SA', 'NT', 'TAS'):
dt = date(year, JUN, 1) + rd(weekday=MO(+2))
self[dt] = name
elif year > 1911:
Expand All @@ -2034,6 +2034,12 @@ def _populate(self, year):
name = "Picnic Day"
self[date(year, AUG, 1) + rd(weekday=MO)] = name

# Bank Holiday
if self.prov == 'NSW':
if year >= 1912:
name = "Bank Holiday"
self[date(year, 8, 1) + rd(weekday=MO)] = name

# Labour Day
name = "Labour Day"
if self.prov in ('NSW', 'ACT', 'SA'):
Expand Down Expand Up @@ -2077,24 +2083,20 @@ def _populate(self, year):
self[date(year, SEP, 28)] = name
elif year == 2016:
self[date(year, SEP, 26)] = name
elif 2017 <= year <= 2020:
labour_day = date(year, OCT, 1) + rd(weekday=MO)
if year == 2017:
dt = date(year, SEP, 23) + rd(weekday=MO)
elif year == 2018:
dt = date(year, SEP, 29) + rd(weekday=MO)
elif year == 2019:
dt = date(year, SEP, 28) + rd(weekday=MO)
elif year == 2020:
dt = date(year, SEP, 26) + rd(weekday=MO)
if dt == labour_day:
dt += rd(weekday=MO(+1))
self[date(year, SEP, 26)] = name
elif year == 2017:
self[date(year, SEP, 25)] = name

# Reconciliation Day
if self.prov == 'ACT':
name = "Reconciliation Day"
if year >= 2018:
self[date(year, 5, 27) + rd(weekday=MO)] = name

if self.prov == 'VIC':
# Grand Final Day
if year >= 2015:
self[date(year, SEP, 24) + rd(weekday=FR)] = "Grand Final Day"

# Melbourne Cup
self[date(year, NOV, 1) + rd(weekday=TU)] = "Melbourne Cup"

Expand Down
23 changes: 18 additions & 5 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2365,9 +2365,10 @@ def test_easter_sunday(self):
for dt in [date(1900, 4, 15), date(1901, 4, 7), date(1902, 3, 30),
date(1999, 4, 4), date(2010, 4, 4),
date(2018, 4, 1), date(2019, 4, 21), date(2020, 4, 12)]:
self.assertIn(dt, self.state_hols['NSW'], dt)
self.assertEqual(self.state_hols['NSW'][dt], "Easter Sunday")
for state in ['ACT', 'NT', 'QLD', 'SA', 'VIC', 'TAS', 'WA']:
for state in ['NSW', 'ACT', 'QLD', 'VIC']:
self.assertIn(dt, self.state_hols[state], (state, dt))
self.assertEqual(self.state_hols[state][dt], "Easter Sunday")
for state in ['NT', 'SA', 'TAS', 'WA']:
self.assertNotIn(dt, self.state_hols[state], (state, dt))

def test_easter_monday(self):
Expand All @@ -2378,6 +2379,12 @@ def test_easter_monday(self):
self.assertEqual(self.holidays[dt], "Easter Monday")
self.assertNotIn(dt + relativedelta(days=+1), self.holidays)

def test_bank_holiday(self):
for dt in [date(1912, 8, 5), date(1913, 8, 4),
date(1999, 8, 2), date(2018, 8, 6), date(2020, 8, 3)]:
self.assertIn(dt, self.state_hols['NSW'], dt)
self.assertEqual(self.state_hols['NSW'][dt], "Bank Holiday")

def test_labour_day(self):
for year, day in enumerate([7, 5, 4, 3, 2, 7, 6, ], 2011):
dt = date(year, 3, day)
Expand Down Expand Up @@ -2457,13 +2464,19 @@ def test_picnic_day(self):
self.assertEqual(self.state_hols['NT'][dt], "Picnic Day")

def test_family_and_community_day(self):
for dt in [date(2010, 9, 26), date(2011, 10, 10), date(2012, 10, 8),
for dt in [date(2007, 11, 6), date(2008, 11, 4), date(2009, 11, 3),
date(2010, 9, 26), date(2011, 10, 10), date(2012, 10, 8),
date(2013, 9, 30), date(2014, 9, 29), date(2015, 9, 28),
date(2016, 9, 26)]:
date(2016, 9, 26), date(2017, 9, 25)]:
self.assertIn(dt, self.state_hols['ACT'], dt)
self.assertEqual(self.state_hols['ACT'][dt],
"Family & Community Day")

def test_reconciliation_day(self):
for dt in [date(2018, 5, 28), date(2019, 5, 27), date(2020, 6, 1)]:
self.assertIn(dt, self.state_hols['ACT'], dt)
self.assertEqual(self.state_hols['ACT'][dt], "Reconciliation Day")

def test_grand_final_day(self):
dt = date(2019, 9, 27)
self.assertIn(dt, self.state_hols['VIC'], dt)
Expand Down

0 comments on commit 64d2366

Please sign in to comment.