diff --git a/v2/pt/pt_holidays.go b/v2/pt/pt_holidays.go new file mode 100644 index 0000000..386bc41 --- /dev/null +++ b/v2/pt/pt_holidays.go @@ -0,0 +1,98 @@ +// (c) Rick Arnold. Licensed under the BSD license (see LICENSE). + +// Package pt provides holiday definitions for Portugal. +package pt + +import ( + "time" + + "github.com/rickar/cal/v2" + "github.com/rickar/cal/v2/aa" +) + +var ( + // AnoNovo represents New Year's Day on 1-Jan + AnoNovo = aa.NewYear.Clone(&cal.Holiday{Name: "Ano Novo", Type: cal.ObservancePublic}) + + // SextaFeiraSanta represents Good Friday on the Friday before Easter (movable) + SextaFeiraSanta = aa.GoodFriday.Clone(&cal.Holiday{Name: "Sexta-feira Santa", Type: cal.ObservancePublic}) + + // DomingoPascoa represents Easter Sunday (movable) + DomingoPascoa = aa.Easter.Clone(&cal.Holiday{Name: "Domingo de Páscoa", Type: cal.ObservancePublic}) + + // DiaDaLiberdade represents Freedom Day on 25-Apr + DiaDaLiberdade = &cal.Holiday{ + Name: "Dia da Liberdade", + Type: cal.ObservancePublic, + Month: time.April, + Day: 25, + Func: cal.CalcDayOfMonth, + } + + // DiaDoTrabalhador represents Labour Day on 1-May + DiaDoTrabalhador = aa.WorkersDay.Clone(&cal.Holiday{Name: "Dia do Trabalhador", Type: cal.ObservancePublic}) + + // CorpoDeDeus represents Corpus Christi, 60 days after Easter (movable) + CorpoDeDeus = &cal.Holiday{ + Name: "Corpo de Deus", + Type: cal.ObservancePublic, + Func: cal.CalcEasterOffset, + Offset: 60, + } + + // DiaDePortugal represents Portugal Day on 10-Jun + DiaDePortugal = &cal.Holiday{ + Name: "Dia de Portugal", + Type: cal.ObservancePublic, + Month: time.June, + Day: 10, + Func: cal.CalcDayOfMonth, + } + + // AssuncaoDeNossaSenhora represents Assumption Day on 15-Aug + AssuncaoDeNossaSenhora = aa.AssumptionOfMary.Clone(&cal.Holiday{Name: "Assunção de Nossa Senhora", Type: cal.ObservancePublic}) + + // ImplantacaoDaRepublica represents Republic Day on 5-Oct + ImplantacaoDaRepublica = &cal.Holiday{ + Name: "Implantação da República", + Type: cal.ObservancePublic, + Month: time.October, + Day: 5, + Func: cal.CalcDayOfMonth, + } + + // TodosOsSantos represents All Saints' Day on 1-Nov + TodosOsSantos = aa.AllSaintsDay.Clone(&cal.Holiday{Name: "Dia de Todos os Santos", Type: cal.ObservancePublic}) + + // RestauracaoDaIndependencia represents Restoration of Independence Day on 1-Dec + RestauracaoDaIndependencia = &cal.Holiday{ + Name: "Restauração da Independência", + Type: cal.ObservancePublic, + Month: time.December, + Day: 1, + Func: cal.CalcDayOfMonth, + } + + // ImaculadaConceicao represents Immaculate Conception on 8-Dec + ImaculadaConceicao = aa.ImmaculateConception.Clone(&cal.Holiday{Name: "Imaculada Conceição", Type: cal.ObservancePublic}) + + // Natal represents Christmas Day on 25-Dec + Natal = aa.ChristmasDay.Clone(&cal.Holiday{Name: "Natal", Type: cal.ObservancePublic}) + + // Holidays provides a list of the standard national holidays + Holidays = []*cal.Holiday{ + AnoNovo, + SextaFeiraSanta, + DomingoPascoa, + DiaDaLiberdade, + DiaDoTrabalhador, + CorpoDeDeus, + DiaDePortugal, + AssuncaoDeNossaSenhora, + ImplantacaoDaRepublica, + TodosOsSantos, + RestauracaoDaIndependencia, + ImaculadaConceicao, + Natal, + } +) diff --git a/v2/pt/pt_holidays_test.go b/v2/pt/pt_holidays_test.go new file mode 100644 index 0000000..92dad91 --- /dev/null +++ b/v2/pt/pt_holidays_test.go @@ -0,0 +1,78 @@ +// (c) Rick Arnold. Licensed under the BSD license (see LICENSE). + +package pt + +import ( + "testing" + "time" + + "github.com/rickar/cal/v2" +) + +func d(y, m, d int) time.Time { + return time.Date(y, time.Month(m), d, 0, 0, 0, 0, cal.DefaultLoc) +} + +func TestHolidays(t *testing.T) { + tests := []struct { + h *cal.Holiday + y int + wantAct time.Time + wantObs time.Time + }{ + {AnoNovo, 2015, d(2015, 1, 1), d(2015, 1, 1)}, + {AnoNovo, 2016, d(2016, 1, 1), d(2016, 1, 1)}, + {AnoNovo, 2017, d(2017, 1, 1), d(2017, 1, 1)}, + {AnoNovo, 2018, d(2018, 1, 1), d(2018, 1, 1)}, + {AnoNovo, 2019, d(2019, 1, 1), d(2019, 1, 1)}, + {AnoNovo, 2020, d(2020, 1, 1), d(2020, 1, 1)}, + {AnoNovo, 2021, d(2021, 1, 1), d(2021, 1, 1)}, + {AnoNovo, 2022, d(2022, 1, 1), d(2022, 1, 1)}, + + {SextaFeiraSanta, 2015, d(2015, 4, 3), d(2015, 4, 3)}, + {SextaFeiraSanta, 2016, d(2016, 3, 25), d(2016, 3, 25)}, + {SextaFeiraSanta, 2017, d(2017, 4, 14), d(2017, 4, 14)}, + {SextaFeiraSanta, 2018, d(2018, 3, 30), d(2018, 3, 30)}, + {SextaFeiraSanta, 2019, d(2019, 4, 19), d(2019, 4, 19)}, + {SextaFeiraSanta, 2020, d(2020, 4, 10), d(2020, 4, 10)}, + {SextaFeiraSanta, 2021, d(2021, 4, 2), d(2021, 4, 2)}, + {SextaFeiraSanta, 2022, d(2022, 4, 15), d(2022, 4, 15)}, + + {DomingoPascoa, 2015, d(2015, 4, 5), d(2015, 4, 5)}, + {DomingoPascoa, 2016, d(2016, 3, 27), d(2016, 3, 27)}, + {DomingoPascoa, 2017, d(2017, 4, 16), d(2017, 4, 16)}, + {DomingoPascoa, 2018, d(2018, 4, 1), d(2018, 4, 1)}, + {DomingoPascoa, 2019, d(2019, 4, 21), d(2019, 4, 21)}, + {DomingoPascoa, 2020, d(2020, 4, 12), d(2020, 4, 12)}, + {DomingoPascoa, 2021, d(2021, 4, 4), d(2021, 4, 4)}, + {DomingoPascoa, 2022, d(2022, 4, 17), d(2022, 4, 17)}, + + {DiaDaLiberdade, 2015, d(2015, 4, 25), d(2015, 4, 25)}, + {DiaDaLiberdade, 2016, d(2016, 4, 25), d(2016, 4, 25)}, + {DiaDaLiberdade, 2017, d(2017, 4, 25), d(2017, 4, 25)}, + {DiaDaLiberdade, 2018, d(2018, 4, 25), d(2018, 4, 25)}, + {DiaDaLiberdade, 2019, d(2019, 4, 25), d(2019, 4, 25)}, + + {CorpoDeDeus, 2015, d(2015, 6, 4), d(2015, 6, 4)}, + {CorpoDeDeus, 2016, d(2016, 5, 26), d(2016, 5, 26)}, + {CorpoDeDeus, 2017, d(2017, 6, 15), d(2017, 6, 15)}, + {CorpoDeDeus, 2018, d(2018, 5, 31), d(2018, 5, 31)}, + {CorpoDeDeus, 2019, d(2019, 6, 20), d(2019, 6, 20)}, + + {Natal, 2015, d(2015, 12, 25), d(2015, 12, 25)}, + {Natal, 2016, d(2016, 12, 25), d(2016, 12, 25)}, + {Natal, 2017, d(2017, 12, 25), d(2017, 12, 25)}, + {Natal, 2018, d(2018, 12, 25), d(2018, 12, 25)}, + {Natal, 2019, d(2019, 12, 25), d(2019, 12, 25)}, + } + + for _, test := range tests { + gotAct, gotObs := test.h.Calc(test.y) + if !gotAct.Equal(test.wantAct) { + t.Errorf("%s %d: got actual: %s, want: %s", test.h.Name, test.y, gotAct.String(), test.wantAct.String()) + } + if !gotObs.Equal(test.wantObs) { + t.Errorf("%s %d: got observed: %s, want: %s", test.h.Name, test.y, gotObs.String(), test.wantObs.String()) + } + } +}