]> git.r.bdr.sh - rbdr/mobius/blobdiff - hotline/time.go
Extensive refactor, quality of life enhancements
[rbdr/mobius] / hotline / time.go
index 3b87864e53db8932962c6084eeaf9c4ea92673e9..35fa3992e9f5933bf778c4e6a45fe6c6f0b5f07f 100644 (file)
@@ -2,12 +2,15 @@ package hotline
 
 import (
        "encoding/binary"
 
 import (
        "encoding/binary"
+       "slices"
        "time"
 )
 
        "time"
 )
 
-// toHotlineTime converts a time.Time to the 8 byte Hotline time format:
+type Time [8]byte
+
+// NewTime converts a time.Time to the 8 byte Hotline time format:
 // Year (2 bytes), milliseconds (2 bytes) and seconds (4 bytes)
 // Year (2 bytes), milliseconds (2 bytes) and seconds (4 bytes)
-func toHotlineTime(t time.Time) (b []byte) {
+func NewTime(t time.Time) (b Time) {
        yearBytes := make([]byte, 2)
        secondBytes := make([]byte, 4)
 
        yearBytes := make([]byte, 2)
        secondBytes := make([]byte, 4)
 
@@ -17,9 +20,9 @@ func toHotlineTime(t time.Time) (b []byte) {
        binary.BigEndian.PutUint16(yearBytes, uint16(t.Year()))
        binary.BigEndian.PutUint32(secondBytes, uint32(t.Sub(startOfYear).Seconds()))
 
        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,
+       ))
 }
 }