v1.15.1
ADDED: * timex, for some floaty-UNIX-y things
This commit is contained in:
35
timex/funcs.go
Normal file
35
timex/funcs.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package timex
|
||||
|
||||
import (
|
||||
`time`
|
||||
)
|
||||
|
||||
/*
|
||||
F64Seconds returns [time.Time] `t` as a 64-bit float of <seconds>.<nanoseconds>
|
||||
(where <nanoseconds> is the number of nanoseconds since <seconds>,
|
||||
and <seconds> is the number of seconds since the UNIX epoch).
|
||||
|
||||
This can be used to represent a UNIX Epoch timestamp as seconds but with nanosecond precision.
|
||||
*/
|
||||
func F64Seconds(t time.Time) (f64 float64) {
|
||||
return F64Nanoseconds(t) / float64(time.Second)
|
||||
}
|
||||
|
||||
/*
|
||||
F64Milliseconds is like [F64Seconds] but with a millisecond integer.
|
||||
*/
|
||||
func F64Milliseconds(t time.Time) (f64 float64) {
|
||||
return F64Nanoseconds(t) / float64(time.Millisecond)
|
||||
}
|
||||
|
||||
/*
|
||||
F64Microseconds is like [F64Seconds] but with a microsecond integer.
|
||||
*/
|
||||
func F64Microseconds(t time.Time) (f64 float64) {
|
||||
return F64Nanoseconds(t) / float64(time.Microsecond)
|
||||
}
|
||||
|
||||
// F64Nanoseconds returns [time.Time.UnixNano] as a float64.
|
||||
func F64Nanoseconds(t time.Time) (f64 float64) {
|
||||
return float64(t.UnixNano())
|
||||
}
|
||||
Reference in New Issue
Block a user