So, say each user in a RTDB has a child called caption. This child is a timestamp of seconds since 1970. Now you want to display all users who have a timestamp that is in today. You need to query the database for all users with a timestamp that is in today, because you don't want to send all users to the phone and then filter.
Below, in the first code is how I am currently sending all users to the device and then filtering. The second set of code is where I am attempting to first query all users who have a timestamp in today, ie before sending all to the users device.
One idea would be to make a firebase entry automatically each day that just represents the day. Then just compare that to all the timestamps of the users. The issue I have with that is that timezones are different.
var dict = CLLocation()
...
dict = CLLocation(latitude: lat, longitude: lon)
...
let thisUsersUid = Auth.auth().currentUser?.uid
self.refArtists2 = Database.database().reference().child("people"); self.refArtists2.observe(DataEventType.value, with: { snapshot in
if snapshot.childrenCount>0{
self.people.removeAll()
for people in snapshot.children.allObjects as! [DataSnapshot] {
if people.key != thisUsersUid {
let peopleObject = people.value as? [String: AnyObject]
let peoplecaption = peopleObject?["caption"] as? Int //is timestamp
let coordSnap12 = people.childSnapshot(forPath: "caption").value as? Int ?? 0
let date = Date(timeIntervalSince1970: TimeInterval(coordSnap12)/1000.0)
//let secondsInDay = 86400
**if Calendar.current.isDateInToday(date)** {
.
var ppp: String! ////this should be the uid of all users in db
let people = Database.database().reference().child("people").child(self.ppp).child("captions")
people.observe(DataEventType.value, with: { snapshot in
let captionss = snapshot.value as? Int ?? 0
let date = Date(timeIntervalSince1970: TimeInterval(captionss)/1000.0)
let query1 = Database.database().reference().child("people").queryOrdered(byChild: "caption").where?(isDateInToday(date))