-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.go
32 lines (25 loc) · 794 Bytes
/
time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package banking
import (
"context"
"time"
)
// MillisecondToNanosecondMultiplier is the multiplier for milliseconds to nanoseconds conversion or milliseconds to
// nanoseconds.
const MillisecondToNanosecondMultiplier = 1e6
func MillisecondsToNanoseconds(millis int64) int64 {
return millis * MillisecondToNanosecondMultiplier
}
func NanosecondsToMilliseconds(ns int64) int64 {
return ns / MillisecondToNanosecondMultiplier
}
func TimeToMilliseconds(t time.Time) int64 {
return NanosecondsToMilliseconds(t.UnixNano())
}
func MillisecondsToTime(millis int64) time.Time {
return time.Unix(0, MillisecondsToNanoseconds(millis))
}
// Timer represents a service for retrieving time data.
type Timer interface {
// Time returns time data.
Time(ctx context.Context) (time.Time, error)
}