blob: cbc60140aafa4105d123e1ed9b889069c6956945 (
plain)
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
|
package util
import "time"
// Contains searches for `needle` in `haystack` and returns `true` if found.
func Contains[T comparable](haystack []T, needle T) bool {
for _, s := range haystack {
if s == needle {
return true
}
}
return false
}
// TimeFormat formats the given time, where an empty time is formatted as "not set".
func TimeFormat(t time.Time) string {
if t.IsZero() {
return "not set"
}
return t.Format(time.ANSIC)
}
// Days returns the number of days in a duration. Fraction of days are discarded.
func Days(d time.Duration) int {
return int(d.Hours() / 24)
}
|