Skip to content

Commit

Permalink
Update Taiwan holidays (#2026)
Browse files Browse the repository at this point in the history
Co-authored-by: Arkadii Yakovets <[email protected]>
  • Loading branch information
KJhellico and arkid15r authored Oct 1, 2024
1 parent ba4ed6f commit e36887a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 20 deletions.
44 changes: 33 additions & 11 deletions holidays/countries/taiwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,24 @@
from gettext import gettext as tr
from typing import Set

from holidays.calendars.gregorian import JAN, FEB, MAR, APR, MAY, JUN, SEP, OCT, DEC
from holidays.calendars.gregorian import (
JAN,
FEB,
MAR,
APR,
MAY,
JUN,
SEP,
OCT,
DEC,
MON,
TUE,
WED,
THU,
FRI,
SAT,
SUN,
)
from holidays.groups import ChineseCalendarHolidays, InternationalHolidays, StaticHolidays
from holidays.observed_holiday_base import (
ObservedHolidayBase,
Expand All @@ -24,12 +41,14 @@
SAT_SUN_TO_NEXT_WORKDAY,
)

CHILDRENS_DAY_RULE = ObservedRule({MON: +1, TUE: -1, WED: -1, THU: +1, FRI: -1, SAT: -1, SUN: -2})


class Taiwan(ObservedHolidayBase, ChineseCalendarHolidays, InternationalHolidays, StaticHolidays):
"""
References:
- https://en.wikipedia.org/wiki/Public_holidays_in_Taiwan
- https://www.officeholidays.com/countries/taiwan
- `2025 <https://www.dgpa.gov.tw/en/information?uid=353&pid=11979>`_
- `2024 <https://www.dgpa.gov.tw/en/information?uid=353&pid=11402>`_
- `2023 <https://www.dgpa.gov.tw/en/information?uid=353&pid=11016>`_
- `2022 <https://www.dgpa.gov.tw/en/information?uid=353&pid=10659>`_
Expand Down Expand Up @@ -65,9 +84,17 @@ def _populate_observed(
) -> None:
if self._year < since:
return None

childrens_day = self.tr("兒童節")
for dt in sorted(dts):
for name in self.get_list(dt):
self._add_observed(dt, name, rule)
names = self.get_list(dt)
for name in names:
self._add_observed(
dt,
name,
# Children's Day falls on the same day as Tomb Sweeping Day.
CHILDRENS_DAY_RULE if name == childrens_day and len(names) > 1 else rule,
)

def _populate_public_holidays(self):
if self._year <= 1911:
Expand Down Expand Up @@ -97,9 +124,7 @@ def _populate_public_holidays(self):

if 1990 <= self._year <= 1999 or self._year >= 2011:
# Children's Day.
apr_4 = self._add_holiday_apr_4(tr("兒童節"))
if self._year != 2021:
dts_observed.add(apr_4)
dts_observed.add(self._add_holiday_apr_4(tr("兒童節")))

if self._year >= 1972:
# Tomb Sweeping Day.
Expand Down Expand Up @@ -185,12 +210,9 @@ class TaiwanStaticHolidays:
(OCT, 9, SEP, 23),
),
2024: (FEB, 8, FEB, 17),
2025: (JAN, 27, FEB, 8),
}

special_public_holidays_observed = {
2013: (APR, 5, childrens_day),
2016: (APR, 5, childrens_day),
2017: (APR, 3, childrens_day),
2021: (APR, 2, childrens_day),
2024: (APR, 5, childrens_day),
}
21 changes: 15 additions & 6 deletions snapshots/countries/TW_COMMON.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,7 @@
"2021-03-01": "Peace Memorial Day (observed)",
"2021-04-02": "Children's Day (observed)",
"2021-04-04": "Children's Day; Tomb Sweeping Day",
"2021-04-05": "Children's Day (observed)",
"2021-04-06": "Tomb Sweeping Day (observed)",
"2021-04-05": "Tomb Sweeping Day (observed)",
"2021-06-14": "Dragon Boat Festival",
"2021-09-20": "Day off (substituted from 09/11/2021)",
"2021-09-21": "Mid-Autumn Festival",
Expand Down Expand Up @@ -772,11 +771,13 @@
"2024-09-17": "Mid-Autumn Festival",
"2024-10-10": "National Day",
"2025-01-01": "Founding Day of the Republic of China",
"2025-01-27": "Day off (substituted from 02/08/2025)",
"2025-01-28": "Chinese New Year's Eve",
"2025-01-29": "Chinese New Year",
"2025-01-30": "Chinese New Year",
"2025-01-31": "Chinese New Year",
"2025-02-28": "Peace Memorial Day",
"2025-04-03": "Children's Day (observed)",
"2025-04-04": "Children's Day; Tomb Sweeping Day",
"2025-05-30": "Dragon Boat Festival (observed)",
"2025-05-31": "Dragon Boat Festival",
Expand Down Expand Up @@ -820,6 +821,7 @@
"2028-01-27": "Chinese New Year",
"2028-01-28": "Chinese New Year",
"2028-02-28": "Peace Memorial Day",
"2028-04-03": "Children's Day (observed)",
"2028-04-04": "Children's Day; Tomb Sweeping Day",
"2028-05-28": "Dragon Boat Festival",
"2028-05-29": "Dragon Boat Festival (observed)",
Expand All @@ -831,6 +833,7 @@
"2029-02-14": "Chinese New Year",
"2029-02-15": "Chinese New Year",
"2029-02-28": "Peace Memorial Day",
"2029-04-03": "Children's Day (observed)",
"2029-04-04": "Children's Day; Tomb Sweeping Day",
"2029-06-15": "Dragon Boat Festival (observed)",
"2029-06-16": "Dragon Boat Festival",
Expand Down Expand Up @@ -870,9 +873,9 @@
"2032-02-13": "Chinese New Year",
"2032-02-27": "Peace Memorial Day (observed)",
"2032-02-28": "Peace Memorial Day",
"2032-04-02": "Children's Day (observed)",
"2032-04-04": "Children's Day; Tomb Sweeping Day",
"2032-04-05": "Children's Day (observed)",
"2032-04-06": "Tomb Sweeping Day (observed)",
"2032-04-05": "Tomb Sweeping Day (observed)",
"2032-06-11": "Dragon Boat Festival (observed)",
"2032-06-12": "Dragon Boat Festival",
"2032-09-19": "Mid-Autumn Festival",
Expand All @@ -888,6 +891,7 @@
"2033-02-03": "Chinese New Year's Eve (observed)",
"2033-02-28": "Peace Memorial Day",
"2033-04-04": "Children's Day; Tomb Sweeping Day",
"2033-04-05": "Children's Day (observed)",
"2033-06-01": "Dragon Boat Festival",
"2033-09-08": "Mid-Autumn Festival",
"2033-10-10": "National Day",
Expand Down Expand Up @@ -926,6 +930,7 @@
"2036-01-30": "Chinese New Year",
"2036-01-31": "Chinese New Year's Eve (observed)",
"2036-02-28": "Peace Memorial Day",
"2036-04-03": "Children's Day (observed)",
"2036-04-04": "Children's Day; Tomb Sweeping Day",
"2036-05-30": "Dragon Boat Festival",
"2036-10-03": "Mid-Autumn Festival (observed)",
Expand Down Expand Up @@ -985,6 +990,7 @@
"2040-02-15": "Chinese New Year's Eve (observed)",
"2040-02-16": "Chinese New Year (observed)",
"2040-02-28": "Peace Memorial Day",
"2040-04-03": "Children's Day (observed)",
"2040-04-04": "Children's Day; Tomb Sweeping Day",
"2040-06-14": "Dragon Boat Festival",
"2040-09-20": "Mid-Autumn Festival",
Expand All @@ -998,6 +1004,7 @@
"2041-02-05": "Chinese New Year (observed)",
"2041-02-28": "Peace Memorial Day",
"2041-04-04": "Children's Day; Tomb Sweeping Day",
"2041-04-05": "Children's Day (observed)",
"2041-06-03": "Dragon Boat Festival",
"2041-09-10": "Mid-Autumn Festival",
"2041-10-10": "National Day",
Expand Down Expand Up @@ -1040,6 +1047,7 @@
"2044-02-28": "Peace Memorial Day",
"2044-02-29": "Peace Memorial Day (observed)",
"2044-04-04": "Children's Day; Tomb Sweeping Day",
"2044-04-05": "Children's Day (observed)",
"2044-05-31": "Dragon Boat Festival",
"2044-10-05": "Mid-Autumn Festival",
"2044-10-10": "National Day",
Expand All @@ -1052,6 +1060,7 @@
"2045-02-20": "Chinese New Year (observed)",
"2045-02-21": "Chinese New Year (observed)",
"2045-02-28": "Peace Memorial Day",
"2045-04-03": "Children's Day (observed)",
"2045-04-04": "Children's Day; Tomb Sweeping Day",
"2045-06-19": "Dragon Boat Festival",
"2045-09-25": "Mid-Autumn Festival",
Expand Down Expand Up @@ -1103,9 +1112,9 @@
"2049-02-04": "Chinese New Year",
"2049-02-28": "Peace Memorial Day",
"2049-03-01": "Peace Memorial Day (observed)",
"2049-04-02": "Children's Day (observed)",
"2049-04-04": "Children's Day; Tomb Sweeping Day",
"2049-04-05": "Children's Day (observed)",
"2049-04-06": "Tomb Sweeping Day (observed)",
"2049-04-05": "Tomb Sweeping Day (observed)",
"2049-06-04": "Dragon Boat Festival",
"2049-09-10": "Mid-Autumn Festival (observed)",
"2049-09-11": "Mid-Autumn Festival",
Expand Down
28 changes: 25 additions & 3 deletions tests/countries/test_taiwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,14 @@ def test_childrens_day(self):
self.assertNoHolidayName(name, Taiwan(years=1989))

obs_dt = (
"2013-04-05",
"2015-04-03",
"2016-04-05",
"2017-04-03",
"2020-04-03",
"2021-04-05",
"2021-04-02",
"2024-04-05",
"2025-04-03",
)
self.assertHolidayName(f"{name}(慶祝)", obs_dt)
self.assertNoNonObservedHoliday(obs_dt)
Expand Down Expand Up @@ -176,7 +181,7 @@ def test_tomb_sweeping_day(self):
obs_dt = (
"2015-04-06",
"2020-04-02",
"2021-04-06",
"2021-04-05",
)
self.assertHolidayName(f"{name}(慶祝)", obs_dt)
self.assertNoNonObservedHoliday(obs_dt)
Expand Down Expand Up @@ -482,7 +487,6 @@ def test_2021(self):
"2021-04-02",
"2021-04-04",
"2021-04-05",
"2021-04-06",
"2021-06-14",
"2021-09-20",
"2021-09-21",
Expand Down Expand Up @@ -553,6 +557,24 @@ def test_2024(self):
("2024-10-10", "中華民國國慶日"),
)

def test_2025(self):
self.assertHolidays(
Taiwan(years=2025),
("2025-01-01", "中華民國開國紀念日"),
("2025-01-27", "休息日(2025-02-08日起取代)"),
("2025-01-28", "農曆除夕"),
("2025-01-29", "春節"),
("2025-01-30", "春節"),
("2025-01-31", "春節"),
("2025-02-28", "和平紀念日"),
("2025-04-03", "兒童節(慶祝)"),
("2025-04-04", "兒童節; 清明節"),
("2025-05-30", "端午節(慶祝)"),
("2025-05-31", "端午節"),
("2025-10-06", "中秋節"),
("2025-10-10", "中華民國國慶日"),
)

def test_l10n_default(self):
self.assertLocalizedHolidays(
("2022-01-01", "中華民國開國紀念日"),
Expand Down

0 comments on commit e36887a

Please sign in to comment.