-
Notifications
You must be signed in to change notification settings - Fork 22
/
duration.go
173 lines (143 loc) · 4.04 KB
/
duration.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package unit
// Duration represents a SI unit of time (in seconds, s)
type Duration Unit
// ...
const (
// SI
Yoctosecond = Second * 1e-24
Zeptosecond = Second * 1e-21
Attosecond = Second * 1e-18
Femtosecond = Second * 1e-15
Picosecond = Second * 1e-12
Nanosecond = Second * 1e-9
Microsecond = Second * 1e-6
Millisecond = Second * 1e-3
Centisecond = Second * 1e-2
Decisecond = Second * 1e-1
Second Duration = 1e0
Decasecond = Second * 1e1
Hectosecond = Second * 1e2
Kilosecond = Second * 1e3
Megasecond = Second * 1e6
Gigasecond = Second * 1e9
Terasecond = Second * 1e12
Petasecond = Second * 1e15
Exasecond = Second * 1e18
Zettasecond = Second * 1e21
Yottasecond = Second * 1e24
// non-SI
Minute = Second * 60
Hour = Minute * 60
Day = Hour * 24
Week = Day * 7
ThirtyDayMonth = Day * 30
JulianYear = Day * 365.25
)
// Yoctoseconds returns the time in ys
func (t Duration) Yoctoseconds() float64 {
return float64(t / Yoctosecond)
}
// Zeptoseconds returns the time in zs
func (t Duration) Zeptoseconds() float64 {
return float64(t / Zeptosecond)
}
// Attoseconds returns the time in as
func (t Duration) Attoseconds() float64 {
return float64(t / Attosecond)
}
// Femtoseconds returns the time in fs
func (t Duration) Femtoseconds() float64 {
return float64(t / Femtosecond)
}
// Picoseconds returns the time in ps
func (t Duration) Picoseconds() float64 {
return float64(t / Picosecond)
}
// Nanoseconds returns the time in ns
func (t Duration) Nanoseconds() float64 {
return float64(t / Nanosecond)
}
// Microseconds returns the time in µs
func (t Duration) Microseconds() float64 {
return float64(t / Microsecond)
}
// Milliseconds returns the time in ms
func (t Duration) Milliseconds() float64 {
return float64(t / Millisecond)
}
// Centiseconds returns the time in cs
func (t Duration) Centiseconds() float64 {
return float64(t / Centisecond)
}
// Deciseconds returns the time in ds
func (t Duration) Deciseconds() float64 {
return float64(t / Decisecond)
}
// Seconds returns the time in s
func (t Duration) Seconds() float64 {
return float64(t / Second)
}
// Decaseconds returns the time in das
func (t Duration) Decaseconds() float64 {
return float64(t / Decasecond)
}
// Hectoseconds returns the time in hs
func (t Duration) Hectoseconds() float64 {
return float64(t / Hectosecond)
}
// Kiloseconds returns the time in ks
func (t Duration) Kiloseconds() float64 {
return float64(t / Kilosecond)
}
// Megaseconds returns the time in Ms
func (t Duration) Megaseconds() float64 {
return float64(t / Megasecond)
}
// Gigaseconds returns the time in Gs
func (t Duration) Gigaseconds() float64 {
return float64(t / Gigasecond)
}
// Teraseconds returns the time in Ts
func (t Duration) Teraseconds() float64 {
return float64(t / Terasecond)
}
// Petaseconds returns the time in Ps
func (t Duration) Petaseconds() float64 {
return float64(t / Petasecond)
}
// Exaseconds returns the time in Es
func (t Duration) Exaseconds() float64 {
return float64(t / Exasecond)
}
// Zettaseconds returns the time in Zs
func (t Duration) Zettaseconds() float64 {
return float64(t / Zettasecond)
}
// Yottaseconds returns the time in Ys
func (t Duration) Yottaseconds() float64 {
return float64(t / Yottasecond)
}
// Minutes returns the time in m
func (t Duration) Minutes() float64 {
return float64(t / Minute)
}
// Hours returns the time in h
func (t Duration) Hours() float64 {
return float64(t / Hour)
}
// Days returns the time in d
func (t Duration) Days() float64 {
return float64(t / Day)
}
// Weeks returns the time in w
func (t Duration) Weeks() float64 {
return float64(t / Week)
}
// ThirtyDayMonths returns the time in M
func (t Duration) ThirtyDayMonths() float64 {
return float64(t / ThirtyDayMonth)
}
// JulianYears returns the time in Y
func (t Duration) JulianYears() float64 {
return float64(t / JulianYear)
}