Skip to content

Commit

Permalink
Merge pull request #44 from stackworx-go/master
Browse files Browse the repository at this point in the history
Add South African Public Holidays
  • Loading branch information
rickar authored Apr 17, 2020
2 parents 70520eb + 387be29 commit 8514a8d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
2 changes: 1 addition & 1 deletion holiday_defs_sk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"
)

func TestCzechHolidays(t *testing.T) {
func TestSlovakiaHolidays(t *testing.T) {
c := NewCalendar()
c.Observed = ObservedExact
AddSlovakHolidays(c)
Expand Down
40 changes: 40 additions & 0 deletions holiday_defs_za.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// (c) 2014 Rick Arnold. Licensed under the BSD license (see LICENSE).

package cal

import "time"

// Holidays in South Africa
// Reference https://en.wikipedia.org/wiki/Public_holidays_in_South_Africa
var (
ZANewYear = NewYear
ZAHumanRights = NewHoliday(time.March, 21)
ZAGoodFriday = GoodFriday
ZAEasterMonday = NewHolidayFunc(calculateEasterMonday)
ZAFreedom = NewHoliday(time.April, 27)
ZAWorkers = NewHoliday(time.May, 1)
ZAYouth = NewHoliday(time.June, 16)
ZANationalWomens = NewHoliday(time.August, 9)
ZAHeritage = NewHoliday(time.September, 24)
ZADayOfReconciliation = NewHoliday(time.December, 16)
ZAChristmas = Christmas
ZADayOfGoodwill = Christmas2
)

// AddSouthAfricanHolidays adds all ZA holidays to the Calendar
func AddSouthAfricanHolidays(cal *Calendar) {
cal.AddHoliday(
ZANewYear,
ZAHumanRights,
ZAGoodFriday,
ZAEasterMonday,
ZAFreedom,
ZAWorkers,
ZAYouth,
ZANationalWomens,
ZAHeritage,
ZADayOfReconciliation,
ZAChristmas,
ZADayOfGoodwill,
)
}
69 changes: 69 additions & 0 deletions holiday_defs_za_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package cal

import (
"reflect"
"testing"
"time"
)

func TestSouthAfricanHolidays(t *testing.T) {
c := NewCalendar()
c.Observed = ObservedMondayTuesday
AddSouthAfricanHolidays(c)
loc, err := time.LoadLocation("Africa/Johannesburg")
if err != nil {
t.Fatal(err)
}

isHolidayTests := []testStruct{
{time.Date(2020, time.January, 1, 0, 0, 0, 0, loc), true, "New year"},
{time.Date(2020, time.March, 21, 0, 0, 0, 0, loc), true, "Human Rights"},
{time.Date(2020, time.April, 10, 0, 0, 0, 0, loc), true, "Good Friday"},
{time.Date(2020, time.April, 13, 0, 0, 0, 0, loc), true, "Easter Monday"},
{time.Date(2020, time.April, 27, 0, 0, 0, 0, loc), true, "Freedom"},
{time.Date(2020, time.May, 1, 0, 0, 0, 0, loc), true, "Workers"},
{time.Date(2020, time.June, 16, 0, 0, 0, 0, loc), true, "Youth"},
{time.Date(2020, time.August, 9, 0, 0, 0, 0, loc), true, "National Women's"},
{time.Date(2020, time.August, 10, 0, 0, 0, 0, loc), false, "National Women's Observed"},
{time.Date(2020, time.September, 24, 0, 0, 0, 0, loc), true, "Heritage"},
{time.Date(2020, time.December, 16, 0, 0, 0, 0, loc), true, "Day of Reconciliation"},
{time.Date(2020, time.December, 25, 0, 0, 0, 0, loc), true, "Christmas"},
{time.Date(2020, time.December, 26, 0, 0, 0, 0, loc), true, "Day of Goodwill"},
}

t.Run("isHoliday", func(t *testing.T) {
for _, tc := range isHolidayTests {
t.Run(tc.name, func(t *testing.T) {
if got := c.IsHoliday(tc.t); !reflect.DeepEqual(got, tc.want) {
t.Errorf("Calendar.AddSkipNonWorkdays() = %v, want %v", got, tc.want)
}
})
}
})

isObservedTests := []testStruct{
{time.Date(2020, time.January, 1, 0, 0, 0, 0, loc), true, "New year"},
{time.Date(2020, time.March, 21, 0, 0, 0, 0, loc), true, "Human Rights"},
{time.Date(2020, time.April, 10, 0, 0, 0, 0, loc), true, "Good Friday"},
{time.Date(2020, time.April, 13, 0, 0, 0, 0, loc), true, "Easter Monday"},
{time.Date(2020, time.April, 27, 0, 0, 0, 0, loc), true, "Freedom"},
{time.Date(2020, time.May, 1, 0, 0, 0, 0, loc), true, "Workers"},
{time.Date(2020, time.June, 16, 0, 0, 0, 0, loc), true, "Youth"},
{time.Date(2020, time.August, 10, 0, 0, 0, 0, loc), true, "National Women's Observed"},
{time.Date(2020, time.September, 24, 0, 0, 0, 0, loc), true, "Heritage"},
{time.Date(2020, time.December, 16, 0, 0, 0, 0, loc), true, "Day of Reconciliation"},
{time.Date(2020, time.December, 25, 0, 0, 0, 0, loc), true, "Christmas"},
{time.Date(2020, time.December, 26, 0, 0, 0, 0, loc), true, "Day of Goodwill"},
}

t.Run("isObserved", func(t *testing.T) {
for _, tc := range isObservedTests {
t.Run(tc.name, func(t *testing.T) {
if got := !c.IsWorkday(tc.t); !reflect.DeepEqual(got, tc.want) {
t.Errorf("Calendar.AddSkipNonWorkdays() = %v, want %v", got, tc.want)
}
})
}
})

}

0 comments on commit 8514a8d

Please sign in to comment.