I have a collection with the next item and one of their properties is the date:
id: xxxxxx
name: xxxx
date: August 21, 2018 at 1:00:00 AM UTC+8 (timestamp)
Inside a firebase cloud function I am trying to query all objects from a period, this period can be the day, the week, the year, etc.
I want to query the items by the current server day, so I do this in a Firebase Cloud Function:
let auxDate = moment();
dateStart = auxDate.startOf('day').toDate();
dateEnd = auxDate.endOf('day').toDate();
await admin.firestore().collection('items')
.where("date", ">=", dateStart)
.where('date', '<=', dateEnd).get();
The values of dateStart and dateEnd printed in the console are:
Date start: Tue Aug 21 2018 00:00:00 GMT+0000 (UTC)
Date end: Tue Aug 21 2018 23:59:59 GMT+0000 (UTC)
And the query return 0 items. But when I change the date of the item to
id: xxxxxx
name: xxxx
date: August 21, 2018 at 8:00:00 AM UTC+8 (timestamp)
The query return the item correctly.
So now i know the problem is about the Offset, but how can i fix this? Why firebase save all dates in UTC+8?