nodejs-firestore
nodejs-firestore copied to clipboard
FR: Firestore Timestamp should have a comparator method
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: https://github.com/firebase/firebase-js-sdk/issues/7711
Once https://github.com/firebase/firebase-js-sdk/issues/7711 is resolved, we can implement the same solution here.