+7
-2
atproto/syntax/tid.go
+7
-2
atproto/syntax/tid.go
···
53
53
}
54
54
55
55
// Constructs a new TID from a UNIX timestamp (in milliseconds) and clock ID value.
56
-
func NewTID(unixMilis int64, clockId uint) TID {
57
-
var v uint64 = (uint64(unixMilis&0x1F_FFFF_FFFF_FFFF) << 10) | uint64(clockId&0x3FF)
56
+
func NewTID(unixMicros int64, clockId uint) TID {
57
+
var v uint64 = (uint64(unixMicros&0x1F_FFFF_FFFF_FFFF) << 10) | uint64(clockId&0x3FF)
58
58
return NewTIDFromInteger(v)
59
+
}
60
+
61
+
// Constructs a new TID from a [time.Time] and clock ID value
62
+
func NewTIDFromTime(ts time.Time, clockId uint) TID {
63
+
return NewTID(ts.UTC().UnixMicro(), clockId)
59
64
}
60
65
61
66
// Returns full integer representation of this TID (not used often)
+5
-1
atproto/syntax/tid_test.go
+5
-1
atproto/syntax/tid_test.go
···
104
104
assert.Equal("2222222222222", zero.String())
105
105
assert.Equal(uint64(0), zero.Integer())
106
106
assert.Equal(uint(0), zero.ClockID())
107
-
assert.Equal(time.UnixMilli(0).UTC(), zero.Time())
107
+
assert.Equal(time.UnixMicro(0).UTC(), zero.Time())
108
108
109
109
now := NewTIDNow(1011)
110
110
assert.Equal(uint(1011), now.ClockID())
···
112
112
113
113
over := NewTIDNow(4096)
114
114
assert.Equal(uint(0), over.ClockID())
115
+
116
+
next := NewTIDFromTime(time.Now(), 123)
117
+
assert.Equal(uint(123), next.ClockID())
118
+
assert.True(time.Since(next.Time()) < time.Minute)
115
119
}
116
120
117
121
func TestTIDClock(t *testing.T) {