-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from bozena-wloch/patch-1
add Poland holidays
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |