-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.go
40 lines (36 loc) · 794 Bytes
/
time.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
36
37
38
39
40
package gofn
import "time"
// MinTime finds the minimum time in the list
// NOTE: if zero time is in the list, the result will be zero
func MinTime(t1 time.Time, s ...time.Time) time.Time {
min := t1
for i := range s {
if s[i].Before(min) {
min = s[i]
}
}
return min
}
// MaxTime finds the maximum time in the list
func MaxTime(t1 time.Time, s ...time.Time) time.Time {
max := t1
for i := range s {
if s[i].After(max) {
max = s[i]
}
}
return max
}
// MinMaxTime gets the minimum and maximum time values in the list
func MinMaxTime(t1 time.Time, s ...time.Time) (time.Time, time.Time) {
minTime := t1
maxTime := t1
for i := range s {
if s[i].Before(minTime) {
minTime = s[i]
} else if s[i].After(maxTime) {
maxTime = s[i]
}
}
return minTime, maxTime
}