-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconutil.go
53 lines (44 loc) · 824 Bytes
/
conutil.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
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"strings"
"time"
)
type ArbitraryData = map[string]interface{}
const day = time.Minute * 60 * 24
func duration(d time.Duration) string {
// Format duration as string, also pretty formatting days.
if d < day {
return d.String()
}
var b strings.Builder
days := d / day
d -= days * day
ds := d.String()
if d == 0 {
ds = ""
}
_, _ = fmt.Fprintf(&b, "%ddays%s", days, ds)
return b.String()
}
func maxDuration(a, b time.Duration) time.Duration {
if a > b {
return a
}
return b
}
func maxDate(a, b time.Time) time.Time {
if a.After(b) {
return a
}
return b
}
func minDate(a, b time.Time) time.Time {
if a.Before(b) {
return a
}
return b
}
func newDate(year int, month time.Month, day int) time.Time {
return time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
}