adds time functions from unix micros/millis
This commit is contained in:
parent
b1f0eb2769
commit
f1397c40b1
14
LICENSE
Normal file
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
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user