From d3ea59508f3d0b96df3eb3b7e5882cb0aad3f3d5 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Sun, 30 Nov 2025 14:10:11 -0800 Subject: Add helper methods for hotline.Time conversion --- hotline/time.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hotline/time.go b/hotline/time.go index 35fa399..671e036 100644 --- a/hotline/time.go +++ b/hotline/time.go @@ -26,3 +26,20 @@ func NewTime(t time.Time) (b Time) { secondBytes, )) } + +// Time converts the Hotline Time format to a Go time.Time. +// The Hotline format stores: Year (2 bytes) + milliseconds (2 bytes, unused) + seconds since Jan 1 (4 bytes) +func (t Time) Time() time.Time { + year := binary.BigEndian.Uint16(t[0:2]) + seconds := binary.BigEndian.Uint32(t[4:8]) + + // Create start of year, then add seconds + startOfYear := time.Date(int(year), time.January, 1, 0, 0, 0, 0, time.Local) + return startOfYear.Add(time.Duration(seconds) * time.Second) +} + +// Format returns the time formatted according to the layout string. +// This is a convenience wrapper around Time().Format(). +func (t Time) Format(layout string) string { + return t.Time().Format(layout) +} -- cgit