From cd579627b9ce2a3214389342554152875b8d8f2e Mon Sep 17 00:00:00 2001 From: nathaniel <68157143+nathanielmiller23@users.noreply.github.com> Date: Tue, 6 Aug 2024 00:24:31 +0000 Subject: [PATCH] Updated SG.py per the requirements of the PR comments. In addition, I updated the snapshots. --- src/holidata/holidays/SG.py | 76 ++++++------------- ...idays_for_locale_and_year[de-DE-2011] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2012] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2013] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2014] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2015] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2016] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2017] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2018] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2019] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2020] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2021] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2022] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2023] 1.py | 8 -- ...idays_for_locale_and_year[de-DE-2024] 1.py | 8 -- 15 files changed, 25 insertions(+), 163 deletions(-) diff --git a/src/holidata/holidays/SG.py b/src/holidata/holidays/SG.py index 425707d..29cfc73 100644 --- a/src/holidata/holidays/SG.py +++ b/src/holidata/holidays/SG.py @@ -1,6 +1,6 @@ from datetime import date, timedelta from dateutil.easter import EASTER_WESTERN -from holidata.utils import month_reference +from holidata.utils import SmartDayArrow from .holidays import Country class SG(Country): @@ -30,9 +30,9 @@ def __init__(self): self.define_holiday() \ .with_name("Good Friday") \ - .on(self.good_friday) \ + .on("2 days before Easter") \ .with_flags("NRV") - + self.define_holiday() \ .with_name("Labour Day") \ .on(self.labour_day) \ @@ -71,9 +71,8 @@ def __init__(self): @staticmethod def shift_to_monday_if_weekend(holiday_date): """Shift the holiday to Monday if it falls on a Saturday or Sunday.""" - if holiday_date.weekday() >= 5: # Saturday or Sunday - return holiday_date + timedelta(days=(7 - holiday_date.weekday())) - return holiday_date + smart_date = SmartDayArrow.fromdate(holiday_date) + return smart_date.shift_to_weekday("monday", including=True).date() @staticmethod def new_years_day(year): @@ -109,29 +108,6 @@ def chinese_new_year_day2(year): first_day = SG.chinese_new_year(year) return SG.shift_to_monday_if_weekend(first_day + timedelta(days=1)) if first_day else None - @staticmethod - def good_friday(year): - """Return the date of Good Friday for the given year.""" - dates = { - 2011: date(2011, 4, 22), - 2012: date(2012, 4, 6), - 2013: date(2013, 3, 29), - 2014: date(2014, 4, 18), - 2015: date(2015, 4, 3), - 2016: date(2016, 3, 25), - 2017: date(2017, 4, 14), - 2018: date(2018, 3, 30), - 2019: date(2019, 4, 19), - 2020: date(2020, 4, 10), - 2021: date(2021, 4, 2), - 2022: date(2022, 4, 15), - 2023: date(2023, 4, 7), - 2024: date(2024, 3, 29), - 2025: date(2025, 4, 18), - 2026: date(2026, 4, 3) - } - return dates.get(year) - @staticmethod def labour_day(year): """Return the date of Labour Day for the given year.""" @@ -204,7 +180,7 @@ def hari_raya_haji(year): 2022: date(2022, 7, 10), 2023: date(2023, 6, 29), 2024: date(2024, 6, 17), - 2025: date(2025, 6, 6), + 2025: date(2025, 6, 7), 2026: date(2026, 5, 27) } return dates.get(year) @@ -218,22 +194,22 @@ def national_day(year): def deepavali(year): """Return the date of Deepavali for the given year.""" dates = { - 2011: date(2011, 10, 26), - 2012: date(2012, 11, 13), - 2013: date(2013, 11, 3), - 2014: date(2014, 10, 22), - 2015: date(2015, 11, 10), - 2016: date(2016, 10, 29), - 2017: date(2017, 10, 18), - 2018: date(2018, 11, 6), - 2019: date(2019, 10, 27), - 2020: date(2020, 11, 14), - 2021: date(2021, 11, 4), - 2022: date(2022, 10, 24), - 2023: date(2023, 11, 12), - 2024: date(2024, 10, 31), - 2025: date(2025, 10, 20), - 2026: date(2026, 11, 8) + 2011: date(2011, 10, 26), + 2012: date(2012, 11, 13), + 2013: date(2013, 11, 3), + 2014: date(2014, 10, 22), + 2015: date(2015, 11, 10), + 2016: date(2016, 10, 29), + 2017: date(2017, 10, 18), + 2018: date(2018, 11, 6), + 2019: date(2019, 10, 27), + 2020: date(2020, 11, 14), + 2021: date(2021, 11, 4), + 2022: date(2022, 10, 24), + 2023: date(2023, 11, 12), + 2024: date(2024, 10, 31), + 2025: date(2025, 10, 20), + 2026: date(2026, 11, 9) } return SG.shift_to_monday_if_weekend(dates.get(year)) @@ -242,8 +218,6 @@ def christmas_day(year): """Return the date of Christmas Day for the given year.""" return SG.shift_to_monday_if_weekend(date(year, 12, 25)) - # Add a class attribute for legal sources - legal_sources = [ - "https://www.mom.gov.sg/employment-practices/public-holidays", - "https://www.mom.gov.sg/employment-practices/public-holidays-entitlement-and-pay" - ] + # Legal sources: + # https://www.mom.gov.sg/employment-practices/public-holidays + # https://www.mom.gov.sg/employment-practices/public-holidays-entitlement-and-pay \ No newline at end of file diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2011] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2011] 1.py index 3479d00..cccec12 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2011] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2011] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2011-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2011-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2012] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2012] 1.py index d358ffc..40ebd42 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2012] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2012] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2012-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2012-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2013] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2013] 1.py index c43ca88..b7a4867 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2013] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2013] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2013-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2013-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2014] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2014] 1.py index b0cbfd2..fbad120 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2014] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2014] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2014-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2014-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2015] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2015] 1.py index a869670..e1a0785 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2015] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2015] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2015-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2015-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2016] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2016] 1.py index 43f9480..2d2a992 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2016] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2016] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2016-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2016-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2017] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2017] 1.py index 4589cdf..1783491 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2017] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2017] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2017-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2017-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2018] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2018] 1.py index f7400d0..7bbadf8 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2018] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2018] 1.py @@ -135,14 +135,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2018-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2018-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2019] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2019] 1.py index 5c17d4d..1c05334 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2019] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2019] 1.py @@ -143,14 +143,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2019-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2019-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2020] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2020] 1.py index 1f7f8f5..5c99880 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2020] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2020] 1.py @@ -151,14 +151,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2020-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2020-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2021] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2021] 1.py index b341779..2aff7e7 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2021] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2021] 1.py @@ -143,14 +143,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2021-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2021-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2022] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2022] 1.py index b4352e3..019cf2e 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2022] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2022] 1.py @@ -143,14 +143,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2022-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2022-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2023] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2023] 1.py index 0ab1db7..190cd48 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2023] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2023] 1.py @@ -143,14 +143,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2023-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2023-08-15', 'description': 'Mariä Himmelfahrt', diff --git a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2024] 1.py b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2024] 1.py index 37236db..d641edd 100644 --- a/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2024] 1.py +++ b/tests/snapshots/snap_test_holidata/test_holidata_produces_holidays_for_locale_and_year[de-DE-2024] 1.py @@ -143,14 +143,6 @@ 'region': 'SL', 'type': 'RV' }, - { - 'date': '2024-08-15', - 'description': 'Mariä Himmelfahrt', - 'locale': 'de-DE', - 'notes': 'In Gemeinden mit überwiegend katholischer Bevölkerung', - 'region': 'BY', - 'type': 'RF' - }, { 'date': '2024-08-15', 'description': 'Mariä Himmelfahrt',