New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Encode timestamp fraction according to the Proto3 JSON Specification. #8035
Conversation
🦋 Changeset detectedLatest commit: 370a5e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Changeset File Check ✅
|
Size Report 1Affected Products
Test Logs |
Size Analysis Report 1Affected Products
Test Logs |
|
||
// Pad the fraction out to 3, 6, or 9 digits | ||
let microStr = ('000000000' + timestamp.nanoseconds).slice(-9); | ||
while (microStr.endsWith('000')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't endsWith()
be startsWith()
? By using endsWith()
, isn't that loop effectively dividing the fraction by 1000 on each iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The loop trims "000" off the end. So 1.123000
becomes 1.123
. This has the same numeric value but allows comparison of the date strings returned by Firestore backend, which also perform this truncation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about backwards compatibility? Do we need to write a data migration to convert timestamps from the old format to the new format?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are persisting date strings from the backend, which already have the truncated format, so at least for this we don't need a migration. However, I'm running into some issues with edge cases and I think using the Proto3 JSON date format for comparison will not work.
After testing some edge cases, there are other issues with comparing these Proto3 JSON timestamp values. This approach will not work. Closing this PR for now. |
The SDK encodes a string representation of a timestamp for use as the key value in client side indexes. For this, and other reason, the SDK and Firestore backend must stringify timestamps identically.
Fixes: #8031