GEN2-002: add shared semantic primitives
CI / test (push) Successful in 52s

This commit is contained in:
m
2026-08-29 02:08:20 +03:00
parent c14ad7fd0b
commit 29815c49b8
11 changed files with 227 additions and 7 deletions
+14
View File
@@ -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() }
+14
View File
@@ -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())
}
}