-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtime.go
53 lines (45 loc) · 1018 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
51
52
53
package mlog
import (
"time"
"github.com/cactus/tai64"
)
func writeTime(sb intSliceWriter, t *time.Time) {
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('+')
}
offset := offset / 60
sb.AppendIntWidth(offset/60, 2)
sb.WriteByte(':')
sb.AppendIntWidth(offset%60, 2)
}
}
func writeTimeTAI64N(sb intSliceWriter, t *time.Time) {
tu := t.UTC()
tux := tu.Unix()
offset := tai64.GetOffsetUnix(tux)
sb.WriteString("@4")
sb.AppendIntWidthHex(tux+offset, 15)
sb.AppendIntWidthHex(int64(tu.Nanosecond()), 8)
}