-
Notifications
You must be signed in to change notification settings - Fork 1
/
time.go
52 lines (44 loc) · 1 KB
/
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
51
52
package mlog
import (
"time"
"github.com/cactus/tai64"
)
func writeTime(sb intSliceWriter, t *time.Time, flags FlagSet) {
year, month, day := t.Date()
sb.AppendIntWidth(year, 4)
sb.WriteByte('-')
sb.AppendIntWidth(int(month), 2)
sb.WriteByte('-')
sb.AppendIntWidth(day, 2)
sb.WriteByte('T')
hour, min, sec := t.Clock()
sb.AppendIntWidth(hour, 2)
sb.WriteByte(':')
sb.AppendIntWidth(min, 2)
sb.WriteByte(':')
sb.AppendIntWidth(sec, 2)
sb.WriteByte('.')
sb.AppendIntWidth(t.Nanosecond(), 9)
_, offset := t.Zone()
if offset == 0 {
sb.WriteByte('Z')
} else {
if offset < 0 {
sb.WriteByte('-')
offset = -offset
} else {
sb.WriteByte('+')
}
sb.AppendIntWidth(offset/3600, 2)
sb.WriteByte(':')
sb.AppendIntWidth(offset%3600, 2)
}
}
func writeTimeTAI64N(sb intSliceWriter, t *time.Time, flags FlagSet) {
tu := t.UTC()
tux := tu.Unix()
offset := tai64.GetOffsetUnix(tux)
sb.WriteString("@4")
sb.AppendIntWidthHex(tux+offset, 15)
sb.AppendIntWidthHex(int64(tu.Nanosecond()), 8)
}