-
Notifications
You must be signed in to change notification settings - Fork 899
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
FR: Firestore Timestamp should have a comparator method #7711
Comments
Timestamp has the valueOf method for this purpose, though I think it's kind of weird that the timestamp needs to be stringified to be compared. |
@marcusx2 I use I do see here that comparison was the original intent of |
Here is my understanding: When you compare two values the comparison operators (e.g. e.g. const t1 = new Timestamp(...);
const t2 = new Timestamp(...);
if (t1 > t2) {
console.log("t1 has a later time than t2");
} else {
console.log("t2 has a later time than t1");
} The reason that It appears that The FR is to implement a |
Operating System
N/A
Browser Version
N/A
Firebase SDK Version
N/A
Firebase SDK Product:
Firestore
Describe your project's tooling
N/A
Describe the problem
The JS/TS API for Firestore's Timestamp (both web client Timestamp and node backend Timestamp) do not include a comparator function. This makes sorting accurately by Timestamp rather painful, as you have to write a function that manually compares both seconds and nanos. An easy workaround is to use
toMillis
, but it's lossy on nanos:Instead, it would be great if there was a comparator method provided in the same way as the Firestore Timestamp.compareTo() provided by the Java SDK.
Steps and code to reproduce issue
N/A
Related issue for the nodejs SDK: googleapis/nodejs-firestore#1922
The text was updated successfully, but these errors were encountered: