diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-11-30 14:10:11 -0800 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2025-11-30 14:10:11 -0800 |
| commit | d3ea59508f3d0b96df3eb3b7e5882cb0aad3f3d5 (patch) | |
| tree | 854f7c9e898179a61cc13f1201fc51dd335ab8ce | |
| parent | f96e805b5472c18eb8eef2bed178e150a3145ad2 (diff) | |
Add helper methods for hotline.Time conversion
| -rw-r--r-- | hotline/time.go | 17 |
1 files changed, 17 insertions, 0 deletions
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) +} |