forked from wlbr/feiertage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check Time method to Module and updatet Docs
- Loading branch information
nicobock
committed
Oct 25, 2022
1 parent
a6db102
commit 5ae7ed8
Showing
4 changed files
with
88 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package feiertage | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"time" | ||
) | ||
|
||
func CheckIfIsBankHoliday(date time.Time, region Region) bool { | ||
|
||
for _, feiertag := range region.Feiertage { | ||
if datesAreEqual(feiertag.Time, date) { | ||
return true | ||
} | ||
} | ||
return false | ||
|
||
} | ||
|
||
func datesAreEqual(date1, date2 time.Time) bool { | ||
if date1.Year() != date2.Year() { | ||
return false | ||
} | ||
if date1.Month() != date2.Month() { | ||
return false | ||
} | ||
if date1.Day() != date2.Day() { | ||
return false | ||
} | ||
return true | ||
} | ||
func CheckIfIsBankHolidayIn(date time.Time, state string) (bool, error) { | ||
|
||
region, err := GetRegionFromString(state, date.Year()) | ||
if err != nil { | ||
return false, errors.Wrap(err, "Failed to parse region from state string") | ||
} | ||
return CheckIfIsBankHoliday(date, region), nil | ||
} |
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,20 @@ | ||
package feiertage | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestCheckIfIsBankHoliday(t *testing.T) { | ||
isBankHoliday := CheckIfIsBankHoliday(time.Date(2022, 10, 31, 0, 0, 0, 0, time.UTC), Niedersachsen(2022)) | ||
assert.True(t, isBankHoliday) | ||
isBankHoliday = CheckIfIsBankHoliday(time.Date(2022, 12, 25, 0, 0, 0, 0, time.UTC), Niedersachsen(2022)) | ||
assert.True(t, isBankHoliday) | ||
isBankHoliday = CheckIfIsBankHoliday(time.Date(2022, 12, 26, 0, 0, 0, 0, time.UTC), Niedersachsen(2022)) | ||
assert.True(t, isBankHoliday) | ||
isBankHoliday = CheckIfIsBankHoliday(time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC), Niedersachsen(2023)) | ||
assert.True(t, isBankHoliday) | ||
isBankHoliday = CheckIfIsBankHoliday(time.Date(2022, 10, 30, 0, 0, 0, 0, time.UTC), Niedersachsen(2022)) | ||
assert.False(t, isBankHoliday) | ||
} |
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