aboutsummaryrefslogtreecommitdiff
path: root/hotline/time.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-15 11:13:16 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-06-15 11:13:16 -0700
commit95159e5585762c06c654945070ba54262b7dcec9 (patch)
tree23609018c1460b056ce22067290ea12ee851d483 /hotline/time.go
parenta6216dd89252fa01dc176f98f1e4ecfd3f637566 (diff)
Refactoring and cleanup
* Split CLI client into separate project * Convert more functions to follow common Golang idioms e.g io.Reader, io.Writer * Use ldflags for versioning * Misc cleanup and simplification
Diffstat (limited to 'hotline/time.go')
-rw-r--r--hotline/time.go13
1 files changed, 7 insertions, 6 deletions
diff --git a/hotline/time.go b/hotline/time.go
index 3b87864..edc700d 100644
--- a/hotline/time.go
+++ b/hotline/time.go
@@ -2,12 +2,13 @@ package hotline
import (
"encoding/binary"
+ "slices"
"time"
)
// toHotlineTime converts a time.Time to the 8 byte Hotline time format:
// Year (2 bytes), milliseconds (2 bytes) and seconds (4 bytes)
-func toHotlineTime(t time.Time) (b []byte) {
+func toHotlineTime(t time.Time) (b [8]byte) {
yearBytes := make([]byte, 2)
secondBytes := make([]byte, 4)
@@ -17,9 +18,9 @@ func toHotlineTime(t time.Time) (b []byte) {
binary.BigEndian.PutUint16(yearBytes, uint16(t.Year()))
binary.BigEndian.PutUint32(secondBytes, uint32(t.Sub(startOfYear).Seconds()))
- b = append(b, yearBytes...)
- b = append(b, []byte{0, 0}...)
- b = append(b, secondBytes...)
-
- return b
+ return [8]byte(slices.Concat(
+ yearBytes,
+ []byte{0, 0},
+ secondBytes,
+ ))
}