From 5571adeb82f9819aa6e0b9573a06129d3afc2daa Mon Sep 17 00:00:00 2001 From: Ryu Hoshino Date: Mon, 2 Dec 2024 13:59:38 +0900 Subject: [PATCH 1/2] fix: Handle Emperor's Birthday in 2019 special case --- v2/jp/jp_holidays.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/v2/jp/jp_holidays.go b/v2/jp/jp_holidays.go index 4131727..61f8869 100644 --- a/v2/jp/jp_holidays.go +++ b/v2/jp/jp_holidays.go @@ -4,10 +4,11 @@ package jp import ( - "github.com/rickar/cal/v2" - "github.com/rickar/cal/v2/aa" "math" "time" + + "github.com/rickar/cal/v2" + "github.com/rickar/cal/v2/aa" ) var ( @@ -47,16 +48,19 @@ var ( Day: 23, Observed: weekendAlt, Func: func(h *cal.Holiday, year int) time.Time { - if year <= 2019 { + switch { + case year <= 2018: // Emperor Akihito abdicated in 2019. holiday := *h holiday.Month = time.December holiday.Day = 23 - return cal.CalcDayOfMonth(&holiday, year) + case year == 2019: + // There is no official Emperor's Birthday holiday in 2019 due to the transition + return time.Time{} + default: + return cal.CalcDayOfMonth(h, year) } - - return cal.CalcDayOfMonth(h, year) }, } From 290361902aa6d8a3992915a17c4b94dbfb4e39be Mon Sep 17 00:00:00 2001 From: Ryu Hoshino Date: Wed, 4 Dec 2024 10:12:34 +0900 Subject: [PATCH 2/2] fix test --- v2/jp/jp_holidays_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/v2/jp/jp_holidays_test.go b/v2/jp/jp_holidays_test.go index 689bee8..d2c6068 100644 --- a/v2/jp/jp_holidays_test.go +++ b/v2/jp/jp_holidays_test.go @@ -3,9 +3,10 @@ package jp import ( - "github.com/rickar/cal/v2" "testing" "time" + + "github.com/rickar/cal/v2" ) func d(y, m, d int) time.Time { @@ -50,7 +51,7 @@ func TestHolidays(t *testing.T) { {TheEmperorsBirthday, 2016, d(2016, 12, 23), d(2016, 12, 23)}, {TheEmperorsBirthday, 2017, d(2017, 12, 23), d(2017, 12, 23)}, {TheEmperorsBirthday, 2018, d(2018, 12, 23), d(2018, 12, 24)}, - {TheEmperorsBirthday, 2019, d(2019, 12, 23), d(2019, 12, 23)}, + {TheEmperorsBirthday, 2019, time.Time{}, time.Time{}}, {TheEmperorsBirthday, 2020, d(2020, 2, 23), d(2020, 2, 24)}, {TheEmperorsBirthday, 2021, d(2021, 2, 23), d(2021, 2, 23)}, {TheEmperorsBirthday, 2022, d(2022, 2, 23), d(2022, 2, 23)},