From 30dae389e34db1497088f8cd7d48774e1c0e7932 Mon Sep 17 00:00:00 2001 From: Ryu Hoshino Date: Mon, 2 Dec 2024 14:17:38 +0900 Subject: [PATCH 1/2] Fix: Handle Mountain Day Holiday Correctly in Jp --- v2/jp/jp_holidays.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/v2/jp/jp_holidays.go b/v2/jp/jp_holidays.go index 4131727..f2a4a17 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 ( @@ -141,12 +142,24 @@ var ( // MountainDay represents Mountain Day on 11-August MountainDay = &cal.Holiday{ - Name: "Mountain Day", - Type: cal.ObservancePublic, - Month: time.August, - Day: 11, - Observed: weekendAlt, - Func: cal.CalcDayOfMonth, + Name: "Mountain Day", + Type: cal.ObservancePublic, + Month: time.August, + Day: 11, + Observed: weekendAlt, + Func: func(h *cal.Holiday, year int) time.Time { + switch year { + case 2020: + // Mountain Day is observed on August 10 in 2020 + return time.Date(year, time.August, 10, 0, 0, 0, 0, time.Local) + case 2021: + // Mountain Day is observed on August 8 from 2021 + return time.Date(year, time.August, 8, 0, 0, 0, 0, time.Local) + default: + // For all other years, Mountain Day is observed on August 11 + return time.Date(year, time.August, 11, 0, 0, 0, 0, time.Local) + } + }, StartYear: 2016, } From 384ff9e8574b81679ac606fb93694a3db0f4bdd9 Mon Sep 17 00:00:00 2001 From: Ryu Hoshino Date: Wed, 4 Dec 2024 10:10:39 +0900 Subject: [PATCH 2/2] fix test --- v2/jp/jp_holidays_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/v2/jp/jp_holidays_test.go b/v2/jp/jp_holidays_test.go index 689bee8..f913ad1 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 { @@ -130,9 +131,11 @@ func TestHolidays(t *testing.T) { {MountainDay, 2017, d(2017, 8, 11), d(2017, 8, 11)}, {MountainDay, 2018, d(2018, 8, 11), d(2018, 8, 11)}, {MountainDay, 2019, d(2019, 8, 11), d(2019, 8, 12)}, - {MountainDay, 2020, d(2020, 8, 11), d(2020, 8, 11)}, - {MountainDay, 2021, d(2021, 8, 11), d(2021, 8, 11)}, + {MountainDay, 2020, d(2020, 8, 10), d(2020, 8, 10)}, + {MountainDay, 2021, d(2021, 8, 8), d(2021, 8, 9)}, {MountainDay, 2022, d(2022, 8, 11), d(2022, 8, 11)}, + {MountainDay, 2023, d(2023, 8, 11), d(2023, 8, 11)}, + {MountainDay, 2024, d(2024, 8, 11), d(2024, 8, 12)}, {RespectForTheAgedDay, 2015, d(2015, 9, 21), d(2015, 9, 21)}, {RespectForTheAgedDay, 2016, d(2016, 9, 19), d(2016, 9, 19)},