]> git.r.bdr.sh - rbdr/mobius/blame - hotline/time.go
Add arm32 to goreleaser config
[rbdr/mobius] / hotline / time.go
CommitLineData
29f329ae
JH
1package hotline
2
3import (
4 "encoding/binary"
95159e55 5 "slices"
29f329ae
JH
6 "time"
7)
8
9// toHotlineTime converts a time.Time to the 8 byte Hotline time format:
10// Year (2 bytes), milliseconds (2 bytes) and seconds (4 bytes)
95159e55 11func toHotlineTime(t time.Time) (b [8]byte) {
29f329ae
JH
12 yearBytes := make([]byte, 2)
13 secondBytes := make([]byte, 4)
14
15 // Get a time.Time for January 1st 00:00 from t so we can calculate the difference in seconds from t
16 startOfYear := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local)
17
18 binary.BigEndian.PutUint16(yearBytes, uint16(t.Year()))
19 binary.BigEndian.PutUint32(secondBytes, uint32(t.Sub(startOfYear).Seconds()))
20
95159e55
JH
21 return [8]byte(slices.Concat(
22 yearBytes,
23 []byte{0, 0},
24 secondBytes,
25 ))
29f329ae 26}