aboutsummaryrefslogtreecommitdiff
path: root/pkg/util/util.go
blob: bacb494d71a0c0af70ab38c9111da531a058cd97 (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"

// StrContains searches for `needle` in `haystack` and returns `true` if found.
func StrContains(haystack []string, needle string) 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)
}