adds time functions from unix micros/millis

This commit is contained in:
Jeffrey Paul 2020-09-21 16:37:01 -07:00
父節點 b1f0eb2769
當前提交 f1397c40b1
共有 3 個檔案被更改,包括 38 行新增0 行删除

14
LICENSE Normal file
查看文件

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

查看文件

@ -6,10 +6,14 @@ general, so I put them here.
Suggestions are welcome.
Really I think most of these should probably be in the stdlib.
# License
WTFPL (free software, no restrictions)
# Author
* [sneak@sneak.berlin](mailto:sneak@sneak.berlin)

20
util.go
查看文件

@ -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)
}