-
Notifications
You must be signed in to change notification settings - Fork 125
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 #44 from stackworx-go/master
Add South African Public Holidays
- Loading branch information
Showing
3 changed files
with
110 additions
and
1 deletion.
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
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,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, | ||
) | ||
} |
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,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) | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
} |