nodejs-firestore icon indicating copy to clipboard operation
nodejs-firestore copied to clipboard

FR: Firestore Timestamp should have a comparator method

Open CodingDoug opened this issue 8 months ago • 1 comments

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

CodingDoug avatar Oct 19 '23 13:10 CodingDoug

Once https://github.com/firebase/firebase-js-sdk/issues/7711 is resolved, we can implement the same solution here.

ehsannas avatar Oct 19 '23 20:10 ehsannas