Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kr holidays #63

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add rest of kr holidays
- kr.BeforeLunarNewYear
- kr.AfterLunarNewYear
- kr.BeforeChuseok
- kr.AfterChuseok
  • Loading branch information
aanoaa committed Mar 16, 2021
commit 14a5217402a41010d2c3ea11ac1dc8322a6895a0
56 changes: 56 additions & 0 deletions v2/kr/kr_holidays.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ var (
// NewYear represents New Year's Day on 1-Jan
NewYear = aa.NewYear.Clone(&cal.Holiday{Name: "새해 첫날", Type: cal.ObservancePublic})

// BeforeLunarNewYear represents 설전날 before on the Lunar 1-Jan
BeforeLunarNewYear = &cal.Holiday{
Name: "설전날",
Type: cal.ObservancePublic,
Month: time.January,
Day: 1,
Lunar: true,
Func: CalcBeforeDayOfLunarMonth,
}

// LunarNewYear represents 설날 on the Lunar 1-Jan
LunarNewYear = &cal.Holiday{
Name: "설날",
Expand All @@ -47,6 +57,16 @@ var (
Func: CalcDayOfLunarMonth,
}

// AfterLunarNewYear represents 설다음날 after on the Lunar 1-Jan
AfterLunarNewYear = &cal.Holiday{
Name: "설다음날",
Type: cal.ObservancePublic,
Month: time.January,
Day: 1,
Lunar: true,
Func: CalcAfterDayOfLunarMonth,
}

// IndependenceMovementDay represents 3.1절 on the 1-Mar
IndependenceMovementDay = &cal.Holiday{
Name: "3.1절",
Expand Down Expand Up @@ -94,6 +114,16 @@ var (
Func: cal.CalcDayOfMonth,
}

// BeforeChuseok represents 추석전날 before on the Lunar 15-August
BeforeChuseok = &cal.Holiday{
Name: "추석전날",
Type: cal.ObservancePublic,
Month: time.August,
Day: 15,
Lunar: true,
Func: CalcBeforeDayOfLunarMonth,
}

// Chuseok represents 추석 on the Lunar 15-August
Chuseok = &cal.Holiday{
Name: "추석",
Expand All @@ -105,6 +135,16 @@ var (
Func: CalcDayOfLunarMonth,
}

// AfterChuseok represents 추석전날 after on the Lunar 15-August
AfterChuseok = &cal.Holiday{
Name: "추석다음날",
Type: cal.ObservancePublic,
Month: time.August,
Day: 15,
Lunar: true,
Func: CalcAfterDayOfLunarMonth,
}

// FoundationDay represents 개천절 on the 3-October
FoundationDay = &cal.Holiday{
Name: "개천절",
Expand All @@ -129,13 +169,17 @@ var (
// Holidays provides a list of the standard national holidays
Holidays = []*cal.Holiday{
NewYear,
BeforeLunarNewYear,
LunarNewYear,
AfterLunarNewYear,
IndependenceMovementDay,
BuddhasDay,
ChildrensDay,
MemorialDay,
LiberationDay,
BeforeChuseok,
Chuseok,
AfterChuseok,
FoundationDay,
HangeulDay,
ChristmasDay,
Expand All @@ -147,3 +191,15 @@ var (
func CalcDayOfLunarMonth(h *cal.Holiday, year int) time.Time {
return Lunar2Solar(year, int(h.Month), h.Day, false)
}

// CalcBeforeDayOfLunarMonth a before day of specific LunarDate.
// 1/1 before day maybe become 12/29 or 12/30
// so treat before day as solar calendar
func CalcBeforeDayOfLunarMonth(h *cal.Holiday, year int) time.Time {
return Lunar2Solar(year, int(h.Month), h.Day, false).Add(time.Hour * 24 * -1)
}

// CalcAfterDayOfLunarMonth a after day of specific LunarDate.
func CalcAfterDayOfLunarMonth(h *cal.Holiday, year int) time.Time {
return Lunar2Solar(year, int(h.Month), h.Day, false).Add(time.Hour * 24)
}
34 changes: 34 additions & 0 deletions v2/kr/kr_holidays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ func TestHolidays(t *testing.T) {
{NewYear, 2021, d(2021, 1, 1), d(2021, 1, 1)},
{NewYear, 2022, d(2022, 1, 1), d(2022, 1, 1)},

{BeforeLunarNewYear, 2015, d(2015, 2, 18), d(2015, 2, 18)},
{BeforeLunarNewYear, 2016, d(2016, 2, 7), d(2016, 2, 7)},
{BeforeLunarNewYear, 2017, d(2017, 1, 27), d(2017, 1, 27)},
{BeforeLunarNewYear, 2018, d(2018, 2, 15), d(2018, 2, 15)},
{BeforeLunarNewYear, 2019, d(2019, 2, 4), d(2019, 2, 4)},
{BeforeLunarNewYear, 2020, d(2020, 1, 24), d(2020, 1, 24)},
{BeforeLunarNewYear, 2021, d(2021, 2, 11), d(2021, 2, 11)},
{BeforeLunarNewYear, 2022, d(2022, 1, 31), d(2022, 1, 31)},

{LunarNewYear, 2015, d(2015, 2, 19), d(2015, 2, 19)},
{LunarNewYear, 2016, d(2016, 2, 8), d(2016, 2, 8)},
{LunarNewYear, 2017, d(2017, 1, 28), d(2017, 1, 30)},
Expand All @@ -39,6 +48,15 @@ func TestHolidays(t *testing.T) {
{LunarNewYear, 2021, d(2021, 2, 12), d(2021, 2, 12)},
{LunarNewYear, 2022, d(2022, 2, 1), d(2022, 2, 1)},

{AfterLunarNewYear, 2015, d(2015, 2, 20), d(2015, 2, 20)},
{AfterLunarNewYear, 2016, d(2016, 2, 9), d(2016, 2, 9)},
{AfterLunarNewYear, 2017, d(2017, 1, 29), d(2017, 1, 29)},
{AfterLunarNewYear, 2018, d(2018, 2, 17), d(2018, 2, 17)},
{AfterLunarNewYear, 2019, d(2019, 2, 6), d(2019, 2, 6)},
{AfterLunarNewYear, 2020, d(2020, 1, 26), d(2020, 1, 26)},
{AfterLunarNewYear, 2021, d(2021, 2, 13), d(2021, 2, 13)},
{AfterLunarNewYear, 2022, d(2022, 2, 2), d(2022, 2, 2)},

{IndependenceMovementDay, 2015, d(2015, 3, 1), d(2015, 3, 1)},
{IndependenceMovementDay, 2016, d(2016, 3, 1), d(2016, 3, 1)},
{IndependenceMovementDay, 2017, d(2017, 3, 1), d(2017, 3, 1)},
Expand Down Expand Up @@ -84,6 +102,14 @@ func TestHolidays(t *testing.T) {
{LiberationDay, 2021, d(2021, 8, 15), d(2021, 8, 15)},
{LiberationDay, 2022, d(2022, 8, 15), d(2022, 8, 15)},

{BeforeChuseok, 2016, d(2016, 9, 14), d(2016, 9, 14)},
{BeforeChuseok, 2017, d(2017, 10, 3), d(2017, 10, 3)},
{BeforeChuseok, 2018, d(2018, 9, 23), d(2018, 9, 23)},
{BeforeChuseok, 2019, d(2019, 9, 12), d(2019, 9, 12)},
{BeforeChuseok, 2020, d(2020, 9, 30), d(2020, 9, 30)},
{BeforeChuseok, 2021, d(2021, 9, 20), d(2021, 9, 20)},
{BeforeChuseok, 2022, d(2022, 9, 9), d(2022, 9, 9)},

{Chuseok, 2016, d(2016, 9, 15), d(2016, 9, 15)},
{Chuseok, 2017, d(2017, 10, 4), d(2017, 10, 4)},
{Chuseok, 2018, d(2018, 9, 24), d(2018, 9, 24)},
Expand All @@ -92,6 +118,14 @@ func TestHolidays(t *testing.T) {
{Chuseok, 2021, d(2021, 9, 21), d(2021, 9, 21)},
{Chuseok, 2022, d(2022, 9, 10), d(2022, 9, 12)},

{AfterChuseok, 2016, d(2016, 9, 16), d(2016, 9, 16)},
{AfterChuseok, 2017, d(2017, 10, 5), d(2017, 10, 5)},
{AfterChuseok, 2018, d(2018, 9, 25), d(2018, 9, 25)},
{AfterChuseok, 2019, d(2019, 9, 14), d(2019, 9, 14)},
{AfterChuseok, 2020, d(2020, 10, 2), d(2020, 10, 2)},
{AfterChuseok, 2021, d(2021, 9, 22), d(2021, 9, 22)},
{AfterChuseok, 2022, d(2022, 9, 11), d(2022, 9, 11)},

{FoundationDay, 2015, d(2015, 10, 3), d(2015, 10, 3)},
{FoundationDay, 2016, d(2016, 10, 3), d(2016, 10, 3)},
{FoundationDay, 2017, d(2017, 10, 3), d(2017, 10, 3)},
Expand Down