From d6536522a21d0845af8a609168b9cc72b07b229a Mon Sep 17 00:00:00 2001 From: Bruno Bord Date: Fri, 22 May 2020 11:27:52 +0200 Subject: [PATCH] Fixing duplicated holidays in Hong-Kong and Hong-Kong Bank holiday calendars refs #496 --- Changelog.md | 1 + workalendar/asia/hong_kong.py | 12 +++--------- workalendar/tests/test_asia.py | 6 ++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Changelog.md b/Changelog.md index 51f4721..cfca698 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ ## master (unreleased) - Making the Israel calendar more efficient (#498). +- Fixing duplicated holidays in Hong-Kong and Hong-Kong Bank holiday calendars (#496). ## v9.0.0 (2020-04-24) diff --git a/workalendar/asia/hong_kong.py b/workalendar/asia/hong_kong.py index a056385..ddaa4e9 100644 --- a/workalendar/asia/hong_kong.py +++ b/workalendar/asia/hong_kong.py @@ -59,20 +59,14 @@ class HongKong(WesternCalendar, ChineseNewYearCalendar, ChristianMixin): (ChineseNewYearCalendar.lunar(year, 9, 9), "Chung Yeung Festival"), ]) - # Shifting all potential holidays that fall on SUN. - shifts = [] - for day, label in days: - if day.weekday() == SUN: - shifts.append(( - day + timedelta(days=1), "{} (shift)".format(label) - )) + # All holidays that fall on SUN are shifted in + # ``ChineseNewYearCalendar.get_calendar_holidays()`` # Special case for Boxing Day. # If Christmas day is on SUN, the December 27th is also a holiday if date(year, 12, 25).weekday() == SUN: - shifts.append( + days.append( (date(year, 12, 27), "The second weekday after Christmas") ) - days.extend(shifts) return days diff --git a/workalendar/tests/test_asia.py b/workalendar/tests/test_asia.py index 0f3808b..3380515 100644 --- a/workalendar/tests/test_asia.py +++ b/workalendar/tests/test_asia.py @@ -257,6 +257,12 @@ class HongKongBankTest(HongKongTest): date(2020, 2, 13) ) + def test_no_duplicate_days(self): + holidays = self.cal.holidays(2021) + labels = list(day[1] for day in holidays) + labels_dedup = list(set(labels)) + assert sorted(labels) == sorted(labels_dedup) + class JapanTest(GenericCalendarTest):