aboutsummaryrefslogtreecommitdiff
path: root/hotline/time.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-25 17:44:55 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-05-25 19:51:33 -0700
commit29f329aedcdcf4e07a6dc3d9161439dd35ecfe11 (patch)
tree9bc21e1e3ff6412f85af23fef7a885bafec8fe1e /hotline/time.go
parentc62f0b470f0ce33d5f52897f2cae7fd355f04b80 (diff)
Add partial support for file create/modify timestamps
This replaces hardcoded placeholder create/modify timestamps with the real times, mostly. Create time is OS specific, so for now I'm ignoring it at using the modify time as a stand-in.
Diffstat (limited to 'hotline/time.go')
-rw-r--r--hotline/time.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/hotline/time.go b/hotline/time.go
new file mode 100644
index 0000000..3b87864
--- /dev/null
+++ b/hotline/time.go
@@ -0,0 +1,25 @@
+package hotline
+
+import (
+ "encoding/binary"
+ "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) {
+ yearBytes := make([]byte, 2)
+ secondBytes := make([]byte, 4)
+
+ // Get a time.Time for January 1st 00:00 from t so we can calculate the difference in seconds from t
+ startOfYear := time.Date(t.Year(), time.January, 1, 0, 0, 0, 0, time.Local)
+
+ 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
+}