Skip to content

Commit 7843ebf

Browse files
authored
fix(firestore): more precision fixes (#20073)
Turns out precision for read snapshots is clamped to usec precision, so this updates the parse code to truncate precision accordingly.
1 parent 24a976e commit 7843ebf

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

firestore/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,14 @@ type readSettings struct {
554554
}
555555

556556
// parseReadTime ensures that fallback order of read options is respected.
557+
// As firestore only accepts usec precision, more precise (e.g. nano) values
558+
// are clamped accordingly.
557559
func parseReadTime(c *Client, rs *readSettings) (*timestamppb.Timestamp, bool) {
558560
if rs != nil && !rs.readTime.IsZero() {
559-
return timestamppb.New(rs.readTime), true
561+
return timestamppb.New(rs.readTime.Truncate(time.Microsecond)), true
560562
}
561563
if c.readSettings != nil && !c.readSettings.readTime.IsZero() {
562-
return timestamppb.New(c.readSettings.readTime), true
564+
return timestamppb.New(c.readSettings.readTime.Truncate(time.Microsecond)), true
563565
}
564566
return nil, false
565567
}

firestore/util_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
)
3232

3333
var (
34-
aTime = time.Date(2017, 1, 26, 1, 2, 3, 4, time.UTC)
35-
aTime2 = time.Date(2017, 2, 5, 2, 3, 4, 5, time.UTC)
36-
aTime3 = time.Date(2017, 3, 20, 5, 4, 3, 2, time.UTC)
34+
aTime = time.Date(2017, 1, 26, 1, 2, 3, 4000, time.UTC)
35+
aTime2 = time.Date(2017, 2, 5, 2, 3, 4, 5000, time.UTC)
36+
aTime3 = time.Date(2017, 3, 20, 5, 4, 3, 2000, time.UTC)
3737
aTimestamp = mustTimestampProto(aTime)
3838
aTimestamp2 = mustTimestampProto(aTime2)
3939
aTimestamp3 = mustTimestampProto(aTime3)

0 commit comments

Comments
 (0)