-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix New Year calculation when observed crosses year
Fixes #98
- Loading branch information
Showing
4 changed files
with
46 additions
and
10 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
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
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,34 @@ | ||
package tests | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/rickar/cal/v2" | ||
"github.com/rickar/cal/v2/us" | ||
) | ||
|
||
// New Year calculation was not checking that the observed year was correct so | ||
// 12/31/2022 was treated as a holiday because 12/31/2021 was. | ||
func TestNewYear2022(t *testing.T) { | ||
c := cal.NewBusinessCalendar() | ||
c.AddHoliday(us.NewYear) | ||
|
||
tests := []struct { | ||
date time.Time | ||
wantAct bool | ||
wantObs bool | ||
}{ | ||
{time.Date(2022, 12, 31, 12, 30, 0, 0, time.UTC), false, false}, | ||
{time.Date(2023, 1, 1, 12, 30, 0, 0, time.UTC), true, false}, | ||
{time.Date(2023, 1, 2, 12, 30, 0, 0, time.UTC), false, true}, | ||
} | ||
|
||
for i, test := range tests { | ||
gotAct, gotObs, _ := c.IsHoliday(test.date) | ||
if gotAct != test.wantAct || gotObs != test.wantObs { | ||
t.Errorf("[%d] gotAct: %t, wantAct: %t; gotObs: %t, wantObs: %t", i, gotAct, test.wantAct, gotObs, | ||
test.wantObs) | ||
} | ||
} | ||
} |