Working with Firebase and some Date filters

I have a hotel reservation application that displays a calendar with the ability to scroll to the user. Now the ultimate goal is to provide a calendar-like interface with small dots under each reserved date. At the moment, I'm just trying to print on the console all the reserves between the start and end dates (where the start and end dates are the beginning and end of the month, respectively).

However, I cannot get this to work with Firebase. Here's how the data is on Firebase at the moment:

{
  "reservations" : {
    "-KSgRjwpssoZJWjV9ScM" : {
      "checkin" : 1474950600,
      "checkout" : 1475116200,
      "customer" : "-KMVMMudWJlFeiimtgJl"
    }
  }
}

And here is my Swift code to retrieve the data:

private var ref: FIRDatabaseReference!

// viewdidload:
ref = FIRDatabase.database().reference()
ref.keepSynced(true)

// logic to fetch data
DispatchQueue.global().async {

        // Background Processing
        // Check Firebase for events between startdate and enddate
        print("Fetching Reservations")
        print(startDate.timeIntervalSince1970)
        print(endDate.timeIntervalSince1970)

        self.ref.child("reservations").queryStarting(atValue: startDate.timeIntervalSince1970, childKey: "checkin").observe(.childAdded, with: { (snapshot) -> Void in

            print("Data Retrieved.\n")
            print(snapshot)

        })
}

Here is what is now displayed on the console:

Fetching Reservations
1469989800.0
1472581800.0
Fetching Reservations
1472668200.0
1475173800.0

Since it is clearly visible that the data falls into the second range, but I still can not display it.

What could be wrong here? Thank you

+4
1

I'v , :

let ref = FIRDatabase.database().reference()
let refReservations = ref.child("reservations")

let startDate: Double = 1472668200.0

refReservations
  .queryOrdered(byChild: "checkin")
  .queryStarting(atValue: startDate)
  .observeSingleEvent(of: .value) { (snap: FIRDataSnapshot) in
    print(snap.value)
  }

- :

.queryOrdered(byChild: "checkin")
.queryStarting(atValue: startDate)

.queryStarting(atValue: startDate, childKey: "checkin")
+3

Source: https://habr.com/ru/post/1655995/


All Articles