Skip to content

Commit

Permalink
Update Japan holidays (#2013)
Browse files Browse the repository at this point in the history
Co-authored-by: Arkadii Yakovets <[email protected]>
  • Loading branch information
KJhellico and arkid15r committed Sep 23, 2024
1 parent f12e3da commit cb30b0f
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 202 deletions.
52 changes: 27 additions & 25 deletions holidays/countries/japan.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,34 @@ def __init__(self, *args, **kwargs) -> None:
kwargs.setdefault("observed_rule", SUN_TO_NEXT_WORKDAY)
super().__init__(*args, **kwargs)

def _is_observed(self, dt: date) -> bool:
return dt >= date(1973, APR, 12)

def _populate_observed(self, dts: Set[date]) -> None:
# When a national holiday falls on Sunday, next working day
# shall become a public holiday (振替休日) - substitute holidays.
# shall become a public holiday (振替休日) - substitute holiday.
for dt in sorted(dts):
is_observed, dt_observed = self._add_observed(
dt,
# Substitute Holiday.
name=tr("振替休日"),
show_observed_label=False,
)
if is_observed:
dts.add(dt_observed) # type: ignore[arg-type]

# A weekday between national holidays becomes
# a holiday too (国民の休日) - national holidays.
for dt in dts:
if _timedelta(dt, +2) not in dts:
continue
dt_observed = _timedelta(dt, +1)
if self._is_sunday(dt_observed) or dt_observed in dts:
continue
# National Holiday.
self._add_holiday(tr("国民の休日"), dt_observed)
# Substitute Holiday.
self._add_observed(dt, name=tr("振替休日"), show_observed_label=False)

# A weekday between national holidays becomes a holiday too (国民の休日) -
# national holiday.
# In 1986-2006 it was only May 4 (between Constitution Day and Children's Day).
# Since 2006, it may be only the day between Respect for the Aged Day and
# Autumnal Equinox Day (in September).
if self._year <= 1985:
return None
if self._year <= 2006:
may_4 = (MAY, 4)
if not self._is_monday(may_4) and not self._is_sunday(may_4):
# National Holiday.
self._add_holiday(tr("国民の休日"), may_4)
else:
for dt in dts:
if dt.month == SEP and _timedelta(dt, +2) in dts:
# National Holiday.
self._add_holiday(tr("国民の休日"), _timedelta(dt, +1))
break

def _populate_public_holidays(self):
if self._year < 1949 or self._year > 2099:
Expand Down Expand Up @@ -147,11 +152,7 @@ def _populate_public_holidays(self):
}
# Mountain Day.
name = tr("山の日")
dts_observed.add(
self._add_holiday(name, dates[self._year])
if self._year in dates
else self._add_holiday_aug_11(name)
)
dts_observed.add(self._add_holiday(name, dates.get(self._year, (AUG, 11))))

if self._year >= 1966:
# Respect for the Aged Day.
Expand Down Expand Up @@ -204,6 +205,7 @@ def _populate_bank_holidays(self):

# Bank Holiday.
name = tr("銀行休業日")
self._add_new_years_day(name)
self._add_new_years_day_two(name)
self._add_new_years_day_three(name)
self._add_new_years_eve(name)
Expand Down
Loading

0 comments on commit cb30b0f

Please sign in to comment.