Skip to content

Commit

Permalink
Merge pull request #35 from bozena-wloch/patch-1
Browse files Browse the repository at this point in the history
add Poland holidays
  • Loading branch information
rickar authored Dec 14, 2019
2 parents 0e8e6fc + d2fed1e commit f14ccb8
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
61 changes: 61 additions & 0 deletions holiday_defs_pl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cal

import (
"time"
)

// Poland holidays
var (
PLNewYear = NewYear
PLThreeKings = NewHoliday(time.January, 6)
PLEasterMonday = EasterMonday
PLEasterSunday = NewHolidayFunc(calculateEasterSunday)
PLLabourDay = NewHoliday(time.May, 1)
PLNationalDay = NewHoliday(time.May, 3)
PLPentecostDay = NewHolidayFunc(calculatePentecostDay)
PLCorpusChristi = NewHolidayFunc(calculateCorpusChristiDay)
PLAssumptionBlessedVirginMary = NewHoliday(time.August, 15)
PLAllSaints = NewHoliday(time.November, 1)
PLNationalIndependenceDay = NewHoliday(time.November, 11)
PLChristmasDayOne = Christmas
PLChristmasDayTwo = Christmas2
)

// AddPolandHolidays adds all Poland holidays to the Calendar
func AddPolandHolidays(c *Calendar) {
c.AddHoliday(
PLNewYear,
PLThreeKings,
PLEasterMonday,
PLEasterSunday,
PLLabourDay,
PLNationalDay,
PLPentecostDay,
PLCorpusChristi,
PLAssumptionBlessedVirginMary,
PLAllSaints,
PLNationalIndependenceDay,
PLChristmasDayOne,
PLChristmasDayTwo,
)
}

func calculateEasterSunday(year int, loc *time.Location) (time.Month, int) {
easter := calculateEaster(year, loc)
return easter.Month(), easter.Day()
}

func calculatePentecostDay(year int, loc *time.Location) (time.Month, int) {
easter := calculateEaster(year, loc)
// 50 days after Easter Sunday
em := easter.AddDate(0, 0, +49)
return em.Month(), em.Day()
}

func calculateCorpusChristiDay(year int, loc *time.Location) (time.Month, int) {

easter := calculateEaster(year, loc)
// 60 days after Easter Sunday
em := easter.AddDate(0, 0, +60)
return em.Month(), em.Day()
}
39 changes: 39 additions & 0 deletions holiday_defs_pl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package cal

import (
"testing"
"time"
)

func TestPolandHolidays(t *testing.T) {
c := NewCalendar()
c.Observed = ObservedExact
AddPolandHolidays(c)

tests := []struct {
t time.Time
want bool
}{
{time.Date(2018, 1, 1, 12, 0, 0, 0, time.UTC), true}, // New Year
{time.Date(2018, 1, 6, 12, 0, 0, 0, time.UTC), true}, // Three Kings
{time.Date(2018, 4, 1, 12, 0, 0, 0, time.UTC), true}, // Easter Sunday
{time.Date(2018, 4, 2, 12, 0, 0, 0, time.UTC), true}, // Easter Monday
{time.Date(2018, 5, 1, 12, 0, 0, 0, time.UTC), true}, // Labour Day
{time.Date(2018, 5, 3, 12, 0, 0, 0, time.UTC), true}, // National Day
{time.Date(2018, 5, 20, 12, 0, 0, 0, time.UTC), true}, // Pentecost Day
{time.Date(2018, 5, 31, 12, 0, 0, 0, time.UTC), true}, // Corpus Christi
{time.Date(2018, 8, 15, 12, 0, 0, 0, time.UTC), true}, // Assumption Blessed Virgin Mary
{time.Date(2018, 11, 1, 12, 0, 0, 0, time.UTC), true}, // All Saints
{time.Date(2018, 11, 11, 12, 0, 0, 0, time.UTC), true}, // National Independence Day
{time.Date(2018, 12, 25, 12, 0, 0, 0, time.UTC), true}, // Christmas Day One
{time.Date(2018, 12, 26, 12, 0, 0, 0, time.UTC), true}, // Christmas Day Two
{time.Date(2018, 02, 14, 12, 0, 0, 0, time.UTC), false}, // false test
}

for _, test := range tests {
got := c.IsHoliday(test.t)
if got != test.want {
t.Errorf("got: %t; want: %t (%s)", got, test.want, test.t)
}
}
}

0 comments on commit f14ccb8

Please sign in to comment.