File: time.go

package info (click to toggle)
golang-github-cactus-mlog 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download
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)
}