mirror of https://github.com/status-im/go-waku.git
26 lines
619 B
Go
26 lines
619 B
Go
package utils
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// GetUnixEpochFrom converts a time into a unix timestamp with nanoseconds
|
|
func GetUnixEpochFrom(now time.Time) int64 {
|
|
return now.UnixNano()
|
|
}
|
|
|
|
type Timesource interface {
|
|
Now() time.Time
|
|
}
|
|
|
|
// GetUnixEpoch returns the current time in unix timestamp with the integer part
|
|
// representing seconds and the decimal part representing subseconds.
|
|
// Optionally receives a timesource to obtain the time from
|
|
func GetUnixEpoch(timesource ...Timesource) int64 {
|
|
if len(timesource) != 0 {
|
|
return GetUnixEpochFrom(timesource[0].Now())
|
|
} else {
|
|
return GetUnixEpochFrom(time.Now())
|
|
}
|
|
}
|