Closed simeonangelov94 closed 9 months ago
You can just bring in the Timestamp class from cloud_firestore flutter package as a work around for now. Pretty simple class.
Can you give an example of what a query using Timestamp should look like? This may be as simple as exporting the generated Timestamp class, but I'd like to create a test for it to make sure.
My workaround was building my own API for the specific query.
FirebaseFirestore.instance.collection('Collection1').where('Date1', isGreaterThan: Timestamp.fromDate(Date1)).get();
For my REST API I used
extension Timestamp on DateTime { String toTimestamp() { return add(Duration(days: 0)).toIso8601String() + 'Z'; } }
which worked.
That's just writing a DateTime
object directly to the database, which from my testing Firebase stores as a timestamp
on their side.
This code works for me:
test('Timestamp query', () async {
await firestore
.document('test/query')
.set({'test_field': DateTime.now()});
var query = await firestore
.collection('test')
.where('test_field', isLessThan: DateTime.now())
.get();
expect(query.isNotEmpty, true);
});
Am I missing something?
That's just writing a
DateTime
object directly to the database, which from my testing Firebase stores as atimestamp
on their side.This code works for me:
test('Timestamp query', () async { await firestore .document('test/query') .set({'test_field': DateTime.now()}); var query = await firestore .collection('test') .where('test_field', isLessThan: DateTime.now()) .get(); expect(query.isNotEmpty, true); });
Am I missing something?
I just realized this also. But I haven't tested querying. So your saying if you query against a Timestamp using DateTime it will work as expected?
Hello,
To my understanding there is no Timestamp class that can be utilized using Firedart. I tried querying or creating documents with substitute conversions but Firebase is still not able to read it as Timestamp.I would appreciate if anybody can propose a solution.
Thank you for your help.
Best, Simeon