From 5037cc5228dbb10900f9409afd6c1593cfb1686a Mon Sep 17 00:00:00 2001 From: Lirian Su Date: Wed, 13 Nov 2024 13:25:27 +0800 Subject: [PATCH] feat: support 2025's holiday --- chinese_calendar/constants.py | 38 ++++++++++++++++++++++++++++++++ chinese_calendar/scripts/data.py | 20 ++++++++++++++++- setup.py | 2 +- tests/test_holiday_amount.py | 9 ++++++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/chinese_calendar/constants.py b/chinese_calendar/constants.py index 9fd7649..07ac2dd 100644 --- a/chinese_calendar/constants.py +++ b/chinese_calendar/constants.py @@ -588,6 +588,34 @@ def __new__(cls, english, chinese, days): datetime.date(year=2024, month=10, day=5): Holiday.national_day.value, datetime.date(year=2024, month=10, day=6): Holiday.national_day.value, datetime.date(year=2024, month=10, day=7): Holiday.national_day.value, + datetime.date(year=2025, month=1, day=1): Holiday.new_years_day.value, + datetime.date(year=2025, month=1, day=28): Holiday.spring_festival.value, + datetime.date(year=2025, month=1, day=29): Holiday.spring_festival.value, + datetime.date(year=2025, month=1, day=30): Holiday.spring_festival.value, + datetime.date(year=2025, month=1, day=31): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=1): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=2): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=3): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=4): Holiday.spring_festival.value, + datetime.date(year=2025, month=4, day=4): Holiday.tomb_sweeping_day.value, + datetime.date(year=2025, month=4, day=5): Holiday.tomb_sweeping_day.value, + datetime.date(year=2025, month=4, day=6): Holiday.tomb_sweeping_day.value, + datetime.date(year=2025, month=5, day=1): Holiday.labour_day.value, + datetime.date(year=2025, month=5, day=2): Holiday.labour_day.value, + datetime.date(year=2025, month=5, day=3): Holiday.labour_day.value, + datetime.date(year=2025, month=5, day=4): Holiday.labour_day.value, + datetime.date(year=2025, month=5, day=5): Holiday.labour_day.value, + datetime.date(year=2025, month=5, day=31): Holiday.dragon_boat_festival.value, + datetime.date(year=2025, month=6, day=1): Holiday.dragon_boat_festival.value, + datetime.date(year=2025, month=6, day=2): Holiday.dragon_boat_festival.value, + datetime.date(year=2025, month=10, day=1): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=2): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=3): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=4): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=5): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=6): Holiday.mid_autumn_festival.value, + datetime.date(year=2025, month=10, day=7): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=8): Holiday.national_day.value, } workdays = { @@ -730,6 +758,11 @@ def __new__(cls, english, chinese, days): datetime.date(year=2024, month=9, day=14): Holiday.mid_autumn_festival.value, datetime.date(year=2024, month=9, day=29): Holiday.national_day.value, datetime.date(year=2024, month=10, day=12): Holiday.national_day.value, + datetime.date(year=2025, month=1, day=26): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=8): Holiday.spring_festival.value, + datetime.date(year=2025, month=4, day=27): Holiday.labour_day.value, + datetime.date(year=2025, month=9, day=28): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=11): Holiday.national_day.value, } in_lieu_days = { @@ -873,4 +906,9 @@ def __new__(cls, english, chinese, days): datetime.date(year=2024, month=9, day=16): Holiday.mid_autumn_festival.value, datetime.date(year=2024, month=10, day=4): Holiday.national_day.value, datetime.date(year=2024, month=10, day=7): Holiday.national_day.value, + datetime.date(year=2025, month=2, day=3): Holiday.spring_festival.value, + datetime.date(year=2025, month=2, day=4): Holiday.spring_festival.value, + datetime.date(year=2025, month=5, day=5): Holiday.labour_day.value, + datetime.date(year=2025, month=10, day=7): Holiday.national_day.value, + datetime.date(year=2025, month=10, day=8): Holiday.national_day.value, } diff --git a/chinese_calendar/scripts/data.py b/chinese_calendar/scripts/data.py index 1944da3..4bacd75 100644 --- a/chinese_calendar/scripts/data.py +++ b/chinese_calendar/scripts/data.py @@ -66,6 +66,24 @@ def __init__(self): pass # fmt: off + def _2025(self): + """https://www.gov.cn/zhengce/content/202411/content_6986382.htm + 一、元旦:1月1日(周三)放假1天,不调休。 + 二、春节:1月28日(农历除夕、周二)至2月4日(农历正月初七、周二)放假调休,共8天。1月26日(周日)、2月8日(周六)上班。 + 三、清明节:4月4日(周五)至6日(周日)放假,共3天。 + 四、劳动节:5月1日(周四)至5日(周一)放假调休,共5天。4月27日(周日)上班。 + 五、端午节:5月31日(周六)至6月2日(周一)放假,共3天。 + 六、国庆节、中秋节:10月1日(周三)至8日(周三)放假调休,共8天。9月28日(周日)、10月11日(周六)上班。 + """ + self.year_at(2025) \ + .nyd().rest(1, 1) \ + .sf().rest(1, 28).to(2, 4).work(1, 26).work(2, 8).in_lieu(2, 3).to(2, 4) \ + .tsd().rest(4, 4).to(4, 6) \ + .ld().rest(5, 1).to(5, 5).work(4, 27).in_lieu(5, 5) \ + .dbf().rest(5, 31).to(6, 2) \ + .nd().rest(10, 1).to(10, 8).work(9, 28).work(10, 11).in_lieu(10, 7).to(10, 8) \ + .maf().rest(10, 6) + def _2024(self): """https://www.gov.cn/zhengce/content/202310/content_6911527.htm 一、元旦:1月1日放假,与周末连休。 @@ -101,7 +119,7 @@ def _2023(self): .ld().rest(4, 29).to(5, 3).work(4, 23).work(5, 6).in_lieu(5, 2).to(5, 3) \ .dbf().rest(6, 22).to(6, 24).work(6, 25).in_lieu(6, 23) \ .maf().rest(9, 29) \ - .nd().rest(9, 30).to(10, 6).work(10, 7).to(10, 8).in_lieu(10, 5).to(10, 6)\ + .nd().rest(9, 30).to(10, 6).work(10, 7).to(10, 8).in_lieu(10, 5).to(10, 6) \ .nyd().rest(12, 30).to(12, 31) def _2022(self): diff --git a/setup.py b/setup.py index d8fe661..fb525d1 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = f.read() setup( - name="chinesecalendar", + name="chinese_calendar", version=chinese_calendar.__version__, description="check if some day is holiday in China", long_description=long_description, diff --git a/tests/test_holiday_amount.py b/tests/test_holiday_amount.py index cd08bd1..f57b50b 100644 --- a/tests/test_holiday_amount.py +++ b/tests/test_holiday_amount.py @@ -21,6 +21,11 @@ def test_holiday_amount(self): holiday_amounts[2012] -= 1 # 12年可以享受11年补班的假 holiday_amounts[2015] -= 1 # 15年是中国人民抗日战争暨世界反法西斯战争胜利70周年,多放1天 holiday_amounts[2020] -= 2 # 20年春节因为新型冠状病毒疫情防控,延长假期2天 - for year in range(2007, 2023 + 1): # 06年数据少,不测了 - self.assertEqual(11, holiday_amounts[year], "Holiday amount of year {}".format(year)) + max_supported_year = max([_.year for _ in holidays]) + for year in range(2007, max_supported_year + 1): # 06年数据少,不测了 + if year <= 2024: + expected_holidays = 11 + else: + expected_holidays = 13 + self.assertEqual(expected_holidays, holiday_amounts[year], "Holiday amount of year {}".format(year)) self.assertEqual(1, 1)