Skip to content

Commit

Permalink
Merge pull request #141 from ryu0114h/bugfix/emperor-birthday-2019
Browse files Browse the repository at this point in the history
fix: Handle Emperor's Birthday in 2019 special case
  • Loading branch information
rickar authored Dec 5, 2024
2 parents dc15b9d + 2903619 commit 36b2290
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
16 changes: 10 additions & 6 deletions v2/jp/jp_holidays.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
},
}

Expand Down
5 changes: 3 additions & 2 deletions v2/jp/jp_holidays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)},
Expand Down

0 comments on commit 36b2290

Please sign in to comment.