-
Notifications
You must be signed in to change notification settings - Fork 8
/
uptime.go
123 lines (103 loc) · 2.34 KB
/
uptime.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main
import (
"fmt"
"time"
"github.com/grokify/simplego/fmt/fmtutil"
"github.com/grokify/simplego/time/timeutil"
)
func getIncident(t0s, t1s, format string, durRange time.Duration, impactNum, totalNum int) {
durPct := timeutil.DurationPct{DurationRange: durRange}
t0, err := time.Parse(format, t0s)
if err != nil {
panic(err)
}
t1, err := time.Parse(format, t1s)
if err != nil {
panic(err)
}
durPct.DurationStartTime = t0
durPct.DurationEndTime = t1
fmt.Println(durPct.DurationRange.String())
impPct := timeutil.ImpactPct{
ImpactNum: impactNum,
TotalNum: totalNum}
inc := timeutil.Event{
DurationPct: durPct,
ImpactPct: impPct}
err = inc.Inflate()
if err != nil {
panic(err)
}
fmtutil.PrintJSON(inc)
}
func main() {
dt, err := time.Parse(time.RFC3339, "2017-08-08T00:00:00Z")
if err != nil {
panic(err)
}
rangeDur := timeutil.QuarterDuration(dt)
fmt.Println(rangeDur.String())
getIncident(
"2017-09-04T09:15:00-0700",
"2017-09-05T12:11:04-0600",
timeutil.ISO8601, rangeDur, 140, 6577)
getIncident(
"2017-09-29T17:09:00Z",
"2017-10-02T07:02:00Z",
time.RFC3339, rangeDur, 180, 6577)
fmt.Println("DONE")
}
/*
func getInc1(t0, t1 string, format string, rangeDur time.Duration, impactNum int) (timeutil.Incident, error) {
t10, err := time.Parse(format, t0)
if err != nil {
return timeutil.Incident{}, err
}
t11, err := time.Parse(format, t1)
if err != nil {
return timeutil.Incident{}, err
}
inc1 := timeutil.Incident{
StartTime: t10,
EndTime: t11,
ImpactNum: impactNum,
TotalNum: 6577,
RangeDuration: rangeDur,
}
err = inc1.Inflate()
if err != nil {
return timeutil.Incident{}, err
}
return inc1, nil
}
func main() {
dt, err := time.Parse(time.RFC3339, "2017-08-08T00:00:00Z")
if err != nil {
panic(err)
}
rangeDur, err := timeutil.QuarterDuration(dt)
if err != nil {
panic(err)
}
fmt.Println(rangeDur.String())
inc1, err := getInc1(
"2017-09-04T09:15:00-0700",
"2017-09-05T12:11:04-0600",
timeutil.ISO8601Z4, rangeDur, 142)
if err != nil {
panic(err)
}
fmtutil.PrintJSON(inc1)
fmt.Println(inc1.Duration.String())
inc2, err := getInc1(
"2017-09-29T17:09:00Z",
"2017-10-02T07:02:00Z",
time.RFC3339, rangeDur, 180)
if err != nil {
panic(err)
}
fmtutil.PrintJSON(inc2)
fmt.Println(inc2.Duration.String())
fmt.Println("DONE")
}
*/