I'm saving my data inside files (Google Firebase.Firestore) that are given the date as an ID when created. Files are put inside collection "Events". The structure looks like this:
Document 14-Jan-2019
ID: 1547504172
pr: "true"
po: "false"
Document 17-Jan-2019
ID: 1547763372
pr: "false"
...
Document 20-Jan-2019
ID: 1548025154
pr: "true"
Document 21-Jan-2019
ID: 1548107873
pr: "true"
IDs are created like this:
long ID = (long) Date().getTime()/1000
There is another collection called "Habits" that contains HabitInfo objects.
Document pr (object HabitInfo)
name: "pr"
startDay: 1547504172 //14-Jan-2019
points: 12 ...
Each object has a startDay parameter that specifies the beginning of the week being observed.
I would like to get all files whose dates of creation (in form of long numbers) are less than seven days after my startDay. The time of the day doesn't matter, only the date.
I tried doing something like this:
CollectionReference colRef = db.collection("events");
Query query = colRef.whereGreaterThanOrEqualTo("ID", hInfo.startDay)
.whereLessThan("ID", hInfo.startDay + 7*24*60*60);
The problem with this is that time difference between two of my IDs can be more than 7 days (converted to seconds) because they are recorded at different times of the day. For example, Monday 14th at 7 A.M. and Monday 21st at 3 P.M. are more than seven days away when looking at values in seconds.
How can I get a range considering only dates?