Skip to content
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 #1922

Open
CodingDoug opened this issue Oct 19, 2023 · 1 comment
Open

FR: Firestore Timestamp should have a comparator method #1922

CodingDoug opened this issue Oct 19, 2023 · 1 comment
Assignees
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@CodingDoug
Copy link

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:

array.sort((a, b) => b.ts.toMillis() - a.ts.toMillis())

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.

array.sort((a, b) => b.ts.compareTo(a.ts))

Related issue for the Firebase web client SDK: firebase/firebase-js-sdk#7711

@CodingDoug CodingDoug added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Oct 19, 2023
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/nodejs-firestore API. label Oct 19, 2023
@ehsannas
Copy link
Contributor

Once firebase/firebase-js-sdk#7711 is resolved, we can implement the same solution here.

@ehsannas ehsannas self-assigned this Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/nodejs-firestore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

2 participants