I'm dealing with some problems while querying a database hosted on AppWrite in dart. Basically I need to query a date that is save in AppWrite.
final response = await _db.listDocuments(
databaseId: AppwriteConstants.database_id,
collectionId: AppwriteConstants.collection_id_events,
queries: [
Query.equal('fk_user', fk_user),
Query.equal('date', date.toIso8601String()),
],
);
Without the second query Query.equal('date', date.toIso8601String())
the call is fine since it returns all the documents with fk_user = user
and in this case the date is returned with the format: 2023-12-15T00:00:00.000+00:00
.
While creating a document the date is added in this way:
final response = _db.createDocument(
databaseId: AppwriteConstants.database_id,
collectionId: AppwriteConstants.collection_id_events,
documentId: ..,
data: {
...
'date': date.toIso8601String(),
'startTime': startTime.toIso8601String(),
'endTime': endTime.toIso8601String(),
...
},
);
If I print the date.toIso8601String()
it returns: 2023-12-15T00:00:00.000
which differs from what I obtain without the second query on the date which is 2023-12-15T00:00:00.000+00:00
. Is this the problem? In the query I also tried to append to date.toIso8601String()
the +00:00
but nothing has changed.
In my opinion, Flutter does
toIso8601String()
a little weird in that the timezone stays in the local timezone. Best practice when working with a remote server is to send data to the server in UTC timezone. So, instead of:do
when you create the document or query.
Also, be careful with doing an exact match (
Query.equal()
) on date times because if the millisecond doesn't match up, the query won't match.