Skip to content

Commit

Permalink
Merge pull request #28 from jaraco/debt/china-2024
Browse files Browse the repository at this point in the history
Add China holidays for 2024
  • Loading branch information
jaraco committed Feb 10, 2024
2 parents df2932f + 38d3297 commit fa54a77
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 8 deletions.
37 changes: 30 additions & 7 deletions calendra/asia/china.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
'Mid-Autumn Festival': [(9, 29)],
'National Day': [(9, 30)]
},
2024:
{
'Spring Festival': [(2, 16), (2, 17)],
'Ching Ming Festival': [(4, 4), (4, 5), (4, 6)],
'Labour Day Holiday': [(5, 1), (5, 2), (5, 3), (5, 4), (5, 5)],
'Dragon Boat Festival': [(6, 8), (6, 9), (6, 10)],
'Mid-Autumn Festival': [(9, 15), (9, 16), (9, 17)],
},
}

workdays = {
Expand Down Expand Up @@ -95,21 +103,29 @@
'Dragon Boat Festival Shift': [(6, 25)],
'National Day Shift': [(10, 7), (10, 8)]
},
2024:
{
'Spring Festival Shift': [(2, 4), (2, 9), (2, 18)],
'Ching Ming Festival Shift': [(4, 7)],
'Labour Day Holiday Shift': [(4, 28), (5, 11)],
'Mid-Autumn Festival Shift': [(9, 14)],
'National Day Shift': [(9, 29), (10, 12)]
},
}


@iso_register('CN')
class China(ChineseNewYearCalendar):
"China"
# WARNING: Support 2018-2023 currently, need update every year.
# WARNING: Support 2018-2024 currently, need update every year.
shift_new_years_day = True
include_chinese_new_year_eve = True

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.extra_working_days = []
for year, data in workdays.items():
for holiday_name, day_list in data.items():
for working_day_name, day_list in data.items():
for v in day_list:
self.extra_working_days.append(date(year, v[0], v[1]))

Expand All @@ -125,20 +141,27 @@ def get_calendar_holidays(self, year):
return super().get_calendar_holidays(year)

def get_variable_days(self, year):
days = super().get_variable_days(year)
days = [(day, holiday_name) for (day, holiday_name)
in super().get_variable_days(year)
if day not in self.extra_working_days]

# Spring Festival, eve, 1.1, and 1.2 - 1.6 in lunar day
for i in range(2, 7):
days.append((ChineseNewYearCalendar.lunar(year, 1, i),
"Spring Festival"))
day = ChineseNewYearCalendar.lunar(year, 1, i)
if day not in self.extra_working_days:
days.append((day, "Spring Festival"))

# National Days, 10.1 - 10.7 in general
for i in range(1, 8):
if date(year, 10, i) not in self.extra_working_days:
days.append((date(year, 10, i), "National Day"))
day = date(year, 10, i)
if day not in self.extra_working_days:
days.append((day, "National Day"))

# other holidays
for holiday_name, day_list in holidays[year].items():
for v in day_list:
days.append((date(year, v[0], v[1]), holiday_name))

return days

def is_working_day(self, day,
Expand Down
33 changes: 32 additions & 1 deletion calendra/tests/test_asia.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,37 @@ def test_year_2023(self):
self.assertNotIn(date(2023, 10, 7), holidays) # National Day Shift
self.assertNotIn(date(2023, 10, 8), holidays) # National Day Shift

def test_year_2024(self):
holidays = self.cal.holidays_set(2024)
self.assertIn(date(2024, 1, 1), holidays) # New Year
for i in range(10, 18):
self.assertIn(date(2024, 2, i), holidays) # Spring Festival
self.assertIn(date(2024, 4, 4), holidays) # Ching Ming Festival
self.assertIn(date(2024, 4, 5), holidays) # Ching Ming Festival
self.assertIn(date(2024, 4, 6), holidays) # Ching Ming Festival
for i in range(1, 6):
self.assertIn(date(2024, 5, i), holidays) # Labour Day Holiday
self.assertIn(date(2024, 6, 8), holidays) # Dragon Boat Festival
self.assertIn(date(2024, 6, 9), holidays) # Dragon Boat Festival
self.assertIn(date(2024, 6, 10), holidays) # Dragon Boat Festival
self.assertIn(date(2024, 9, 15), holidays) # Mid-Autumn Festival
self.assertIn(date(2024, 9, 16), holidays) # Mid-Autumn Festival
self.assertIn(date(2024, 9, 17), holidays) # Mid-Autumn Festival
for i in range(1, 8):
self.assertIn(date(2024, 10, i), holidays) # National Day

self.assertNotIn(date(2024, 2, 4), holidays) # Spring Festival Shift
self.assertNotIn(date(2024, 2, 9), holidays) # Spring Festival Shift
self.assertNotIn(date(2024, 2, 18), holidays) # Spring Festival Shift
# Ching Ming Festival Shift
self.assertNotIn(date(2024, 4, 7), holidays)
self.assertNotIn(date(2024, 4, 28), holidays) # Labour Day Shift
self.assertNotIn(date(2024, 5, 11), holidays) # Labour Day Shift
# Mid-Autumn Festival Shift
self.assertNotIn(date(2024, 9, 14), holidays)
self.assertNotIn(date(2024, 9, 29), holidays) # National Day Shift
self.assertNotIn(date(2024, 10, 12), holidays) # National Day Shift

def test_missing_holiday_year(self):
save_2018 = china_holidays[2018]
del china_holidays[2018]
Expand All @@ -146,7 +177,7 @@ def test_warning(self):
with patch('warnings.warn') as patched:
self.cal.get_calendar_holidays(year)
patched.assert_called_with(
'Support years 2018-2023 currently, need update every year.'
'Support years 2018-2024 currently, need update every year.'
)

def test_is_working_day(self):
Expand Down
1 change: 1 addition & 0 deletions newsfragments/+1dfc5485.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added China holidays for 2024.

0 comments on commit fa54a77

Please sign in to comment.