adds time functions from unix micros/millis

Bu işleme şunda yer alıyor:
Jeffrey Paul 2020-09-21 16:37:01 -07:00
ebeveyn b1f0eb2769
işleme f1397c40b1
3 değiştirilmiş dosya ile 38 ekleme ve 0 silme

14
LICENSE Normal dosya
Dosyayı Görüntüle

@ -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.

Dosyayı Görüntüle

@ -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
Dosyayı Görüntüle

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