Skip to content

Commit

Permalink
TH: Buddhist holiday extended testcases, applying suggestions
Browse files Browse the repository at this point in the history
Co-Authored-By: ~Jhellico <KJhellico@users.noreply.github.com>
  • Loading branch information
PPsyrius and KJhellico committed Feb 7, 2023
1 parent b7793e1 commit aa0a822
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
17 changes: 9 additions & 8 deletions holidays/countries/thailand.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,17 @@ def __init__(self, **kwargs):
HolidayBase.__init__(self, **kwargs)

def _populate(self, year):
# Due to Thai Calendar Migration, this is capped off at 1941
# But certain holidays were implemented before 1941
if year <= 1940:
return

# DEFAULT
def add_holiday(dt, holiday_name) -> None:
# Only add if current year and year is 1941 (B.E. 2484) or later
# This is here as a stub for future islamic consecutive holidays
# Which can stradle across gregorian years in southern region
# ** Due to Thai Calendar Migration, this is capped off at 1941
if dt.year == year and dt.year >= 1941:
if dt.year == year:
self[dt] = holiday_name

# !!! If Public Holiday falls on weekends, (in lieu) on workday !!!
Expand Down Expand Up @@ -272,12 +276,11 @@ def add_holiday(dt, holiday_name) -> None:
# วันจักรี
# Status: In-Use
# Starts in present form in 1918 (B.E. 2461)
# ** Due to Thai Calendar Migration, this is capped off at 1941
# Sources:
# (ocac.got.th 's wbm) http://tiny.cc/wa_ocac_chakri
chakri_memorial_en = "Chakri Memorial Day"

if year >= 1941:
if year >= 1918:
add_holiday(date(year, APR, 6), chakri_memorial_en)

# !!! Songkran Festival !!!
Expand Down Expand Up @@ -359,12 +362,11 @@ def add_holiday(dt, holiday_name) -> None:
# Status: Defunct (Historical)
# Starts in 1939 (B.E. 2482) by Plaek Phibunsongkhram
# Replaced by Rama IX's birthday in 1960 (B.E. 2503) by Sarit Thanarat
# ** Due to Thai Calendar Migration, this is capped off at 1941
# Sources:
# (Ministry of Culture 's wbm) http://tiny.cc/wa_mincul_nat_day
national_day_khana_ratsadon_en = "National Day"

if 1941 <= year <= 1959:
if 1939 <= year <= 1959:
add_holiday(date(year, JUN, 24), national_day_khana_ratsadon_en)

# !!! Coronation Day !!!
Expand Down Expand Up @@ -460,12 +462,11 @@ def add_holiday(dt, holiday_name) -> None:
# วันปิยมหาราช
# Status: In-Use
# Started in 1911 (B.E. 2454)
# ** Due to Thai Calendar Migration, this is capped off at 1941
# Sources:
# https://th.wikipedia.org/wiki/วันปิยมหาราช
rama_five_memorial_en = "Chulalongkorn Memorial Day"

if year >= 1941:
if year >= 1911:
add_holiday(date(year, OCT, 23), rama_five_memorial_en)

# !!! HM King Bhumibol Adulyadej's Birthday Anniversary !!!
Expand Down
32 changes: 32 additions & 0 deletions test/countries/test_thailand.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def test_makha_bucha(self):

self.assertNoHolidayName(name, Thailand(years=1940))
dt = (
"2010-02-28",
"2011-02-18",
"2012-03-07",
"2013-02-25",
Expand All @@ -362,6 +363,13 @@ def test_makha_bucha(self):
"2021-02-26",
"2022-02-16",
"2023-03-06",
"2024-02-24",
"2025-02-12",
"2026-03-03",
"2027-02-21",
"2028-02-10",
"2029-02-27",
"2030-02-17",
)
self.assertHolidaysName(name, dt)
self.assertHolidayName(name, Thailand(years=[1941, 2058]))
Expand All @@ -381,6 +389,7 @@ def test_visakha_bucha(self):

self.assertNoHolidayName(name, Thailand(years=1940))
dt = (
"2010-05-28",
"2011-05-17",
"2012-06-04",
"2013-05-24",
Expand All @@ -394,6 +403,13 @@ def test_visakha_bucha(self):
"2021-05-26",
"2022-05-15",
"2023-06-03",
"2024-05-22",
"2025-05-11",
"2026-05-31",
"2027-05-20",
"2028-05-08",
"2029-05-27",
"2030-05-16",
)
self.assertHolidaysName(name, dt)
self.assertHolidayName(name, Thailand(years=[1941, 2058]))
Expand All @@ -413,6 +429,7 @@ def test_asarnha_bucha(self):

self.assertNoHolidayName(name, Thailand(years=1940))
dt = (
"2010-07-26",
"2011-07-15",
"2012-08-02",
"2013-07-22",
Expand All @@ -426,6 +443,13 @@ def test_asarnha_bucha(self):
"2021-07-24",
"2022-07-13",
"2023-08-01",
"2024-07-20",
"2025-07-10",
"2026-07-29",
"2027-07-18",
"2028-07-06",
"2029-07-25",
"2030-07-14",
)
self.assertHolidaysName(name, dt)
self.assertHolidayName(name, Thailand(years=[1941, 2058]))
Expand All @@ -445,6 +469,7 @@ def test_khao_phansa(self):

self.assertNoHolidayName(name, Thailand(years=1940))
dt = (
"2010-07-27",
"2011-07-16",
"2012-08-03",
"2013-07-23",
Expand All @@ -458,6 +483,13 @@ def test_khao_phansa(self):
"2021-07-25",
"2022-07-14",
"2023-08-02",
"2024-07-21",
"2025-07-11",
"2026-07-30",
"2027-07-19",
"2028-07-07",
"2029-07-26",
"2030-07-15",
)
self.assertHolidaysName(name, dt)
self.assertHolidayName(name, Thailand(years=[1941, 2058]))
Expand Down

0 comments on commit aa0a822

Please sign in to comment.