Skip to content

Commit

Permalink
Merge pull request #38 from Shinil35/master
Browse files Browse the repository at this point in the history
Added Italian holidays
  • Loading branch information
rickar authored Jan 18, 2020
2 parents f14ccb8 + a4a7baf commit 57fe06f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
35 changes: 35 additions & 0 deletions holiday_defs_it.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cal

import "time"

// Italian holidays
var (
ITCapodanno = NewYear
ITEpifania = NewHoliday(time.January, 6)
ITPasquetta = EasterMonday
ITFestaDellaLiberazione = NewHoliday(time.April, 25)
ITFestaDelLavoro = NewHoliday(time.May, 1)
ITFestaDellaRepubblica = NewHoliday(time.June, 2)
ITFerragosto = NewHoliday(time.August, 15)
ITTuttiISanti = NewHoliday(time.November, 1)
ITImmacolata = NewHoliday(time.December, 8)
ITNatale = Christmas
ITSantoStefano = Christmas2
)

// AddItalianHolidays adds all Italian holidays to the Calendar
func AddItalianHolidays(c *Calendar) {
c.AddHoliday(
ITCapodanno,
ITEpifania,
ITPasquetta,
ITFestaDellaLiberazione,
ITFestaDelLavoro,
ITFestaDellaRepubblica,
ITFerragosto,
ITTuttiISanti,
ITImmacolata,
ITNatale,
ITSantoStefano,
)
}
33 changes: 33 additions & 0 deletions holiday_defs_it_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cal

import (
"testing"
"time"
)

func TestItalianHolidays(t *testing.T) {
c := NewCalendar()
c.Observed = ObservedExact
AddItalianHolidays(c)

tests := []testStruct{
{time.Date(2020, 1, 1, 12, 0, 0, 0, time.UTC), true, "ITCapodanno"},
{time.Date(2020, 1, 6, 12, 0, 0, 0, time.UTC), true, "ITEpifania"},
{time.Date(2020, 4, 13, 12, 0, 0, 0, time.UTC), true, "ITPasquetta"},
{time.Date(2020, 4, 25, 12, 0, 0, 0, time.UTC), true, "ITFestaDellaLiberazione"},
{time.Date(2020, 5, 1, 12, 0, 0, 0, time.UTC), true, "ITFestaDelLavoro"},
{time.Date(2020, 6, 2, 12, 0, 0, 0, time.UTC), true, "ITFestaDellaRepubblica"},
{time.Date(2020, 8, 15, 12, 0, 0, 0, time.UTC), true, "ITFerragosto"},
{time.Date(2020, 11, 1, 12, 0, 0, 0, time.UTC), true, "ITTuttiISanti"},
{time.Date(2020, 12, 8, 12, 0, 0, 0, time.UTC), true, "ITImmacolata"},
{time.Date(2020, 12, 25, 12, 0, 0, 0, time.UTC), true, "ITNatale"},
{time.Date(2020, 12, 26, 12, 0, 0, 0, time.UTC), true, "ITSantoStefano"},
}

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

0 comments on commit 57fe06f

Please sign in to comment.