-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepoch.go
55 lines (45 loc) · 868 Bytes
/
epoch.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
package epochid
import (
"strconv"
)
type EpochID int64
func NewEpochID(item string) (EpochID, error) {
var result EpochID
if errValidation := validationString(
¶msValidationString{
Caller: "NewEpochID",
Name: "item",
Value: item,
},
&result,
); errValidation != nil {
return 0,
errValidation
}
return result,
nil
}
// Errors ignored for faster result.
func (e EpochID) GetUnixTimeSeconds() int64 {
result, _ := strconv.ParseInt(
strconv.FormatInt(int64(e), 10)[:10],
10,
64,
)
return result
}
// Stringer.
func (e EpochID) String() string {
return strconv.FormatInt(
int64(e),
10,
)
}
// Formats as 1728-3090622-0000-3522.
func (e EpochID) UUIDFormat() string {
asNumber := strconv.FormatInt(
int64(e),
10,
)
return asNumber[:4] + "-" + asNumber[4:11] + "-" + asNumber[11:15] + "-" + asNumber[15:]
}