adds time functions from unix micros/millis

This commit is contained in:
2020-09-21 16:37:01 -07:00
parent b1f0eb2769
commit f1397c40b1
3 changed files with 38 additions and 0 deletions

20
util.go
View File

@@ -69,3 +69,23 @@ func CopyFile(src, dst string) (err error) {
err = out.Sync()
return
}
func TimeFromUnixMilli(ms int64) time.Time {
const millisInSecond = 1000
const nsInSecond = 1000000
return time.Unix(ms/int64(millisInSecond), (ms%int64(millisInSecond))*int64(nsInSecond))
}
func TimeFromUnixMicro(ms int64) time.Time {
const microInSecond = 1000000
const nsInSecond = 1000000
return time.Unix(ms/int64(microInSecond), (ms%int64(microInSecond))*int64(nsInSecond))
}
func TimeFromWebKit(input int64) time.Time {
// webkit time is stupid and uses 1601-01-01 for epoch
// it's 11644473600 seconds behind unix 1970-01-01 epoch
// it's also in microseconds
unixMicrosCorrected := input - (11644473600 * 1000000)
return TimeFromUnixMicro(unixMicrosCorrected)
}