forked from statping-ng/statping-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
50 lines (38 loc) · 857 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
41
42
43
44
45
46
47
48
49
50
package types
import (
"time"
)
const (
TIME_NANO = "2006-01-02T15:04:05Z"
TIME = "2006-01-02 15:04:05"
CHART_TIME = "2006-01-02T15:04:05.999999-07:00"
TIME_DAY = "2006-01-02"
)
var (
Second = time.Second
Minute = time.Minute
Hour = time.Hour
Day = Hour * 24
Week = Day * 7
Month = Week * 4
Year = Day * 365
)
func FixedTime(t time.Time, d time.Duration) string {
return t.Format(durationStr(d))
}
func durationStr(d time.Duration) string {
switch m := d.Seconds(); {
case m >= Month.Seconds():
return "2006-01-01T00:00:00Z"
case m >= Week.Seconds():
return "2006-01-02T00:00:00Z"
case m >= Day.Seconds():
return "2006-01-02T00:00:00Z"
case m >= Hour.Seconds():
return "2006-01-02T15:00:00Z"
case m >= Minute.Seconds():
return "2006-01-02T15:04:00Z"
default:
return "2006-01-02T15:04:05Z"
}
}