This may have changed since I wrote this code, but the following is a simple utility function for getting the "remoteDate" by using the server's TimeOffset:
var remoteDate = null;
utils.remoteDate = function(ref) {
if (remoteDate) return remoteDate;
var offset = 0;
ref.child('/.info/serverTimeOffset').on('value', function(snapshot) {
offset = snapshot.val() || 0;
});
remoteDate = function() {
return Date.now() + offset;
};
return remoteDate;
};
This function returns a function that uses the offset to get the remote date:
this.remoteDate = utils.remoteDate(this.root);
Then I use `this.remoteDate` when querying the database:
var now = this.remoteDate();
this.ref.orderByChild('nextRun')
.endAt(now)
.once('value', function(snapshot) {
cb(null, snapshot.val());
});
`nextRun` in the `orderByChild` above is also a timestamp, so I'm looking for all the records from before the current time.
Hope this helps. The code can be found in
firebase-cron if you need a closer look.
Thanks,
Brian