This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package clock
|
||||
|
||||
import "time"
|
||||
|
||||
// Instant is a UTC point represented as Unix milliseconds.
|
||||
type Instant int64
|
||||
|
||||
func (i Instant) Valid() bool { return i > 0 }
|
||||
|
||||
func NowInstant() Instant { return FromTime(time.Now().UTC()) }
|
||||
|
||||
func FromTime(value time.Time) Instant { return Instant(value.UTC().UnixMilli()) }
|
||||
|
||||
func (i Instant) Time() time.Time { return time.UnixMilli(int64(i)).UTC() }
|
||||
@@ -0,0 +1,14 @@
|
||||
package clock
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestInstantRoundTripUsesUTCUnixMilliseconds(t *testing.T) {
|
||||
want := time.Date(2026, time.August, 29, 12, 34, 56, 789000000, time.FixedZone("local", 3*60*60))
|
||||
got := FromTime(want).Time()
|
||||
if !got.Equal(want.UTC()) || got.Location() != time.UTC {
|
||||
t.Fatalf("instant round trip = %v, want %v UTC", got, want.UTC())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user