-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
35 lines (30 loc) · 1.1 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package temporalis
import (
"fmt"
"time"
)
// pluralize returns the plural form of the given word if the count is not 1.
func pluralize(count int64, word string) string {
if count == 1 {
return fmt.Sprintf("%d %s", count, word)
}
return fmt.Sprintf("%d %ss", count, word)
}
// isWeekend returns true if the given time is on a weekend (Saturday or Sunday), and false otherwise.
// It takes a single argument, t, which is the time to check.
func isWeekend(t time.Time) bool {
return t.Weekday() == time.Saturday || t.Weekday() == time.Sunday
}
// isHoliday checks if the given date is a holiday. It takes a date in the format
// "YYYY-MM-DD" and a map of holidays where the keys are the holiday dates in the
// same format and the values are the holiday names. If the given date is found in
// the holidays map, it returns true along with the name of the holiday, otherwise
// it returns false and an empty string.
func isHoliday(t time.Time, holidays []time.Time) bool {
for _, h := range holidays {
if t.Year() == h.Year() && t.Month() == h.Month() && t.Day() == h.Day() {
return true
}
}
return false
}