Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Server Side Calculation using Firebase

Given the starting time/date and duration, how can I make a server side calculation that determines if an object is "finished", "in progress", or "upcoming"

--Show
  --duration: "144"
  --startDate: "2015-11-10"
  --startTime: "14:00"
  --status: "?"

Client-side javascript to determine if the show has started yet:

// if negative, then show hasn't started yet
var time = (-(startdate.getTime() - currentdate.getTime()) / 1000 / 60); 

Client-side javascript to determine if the show has finished running yet:

// if negative, then show has finished
var timeLeft = channelDuration - timerStartTime;
like image 269
Onichan Avatar asked Nov 11 '15 02:11

Onichan


1 Answers

There is no way to run your own server-side code on Firebase. See:

  • Common Firebase application architectures
  • Firebase Hosting with own server node.js
  • How would I run server-side code in Firebase?
  • How to write custom code (logic) when using firebase

But you can store a server-side timestamp, which seems what you're trying to do:

ref.child('Show/startTimestamp').set(Firebase.ServerValue.TIMESTAMP);

You can then get the shows that haven't started yet with:

var shows = ref.child('Shows');
ref.orderByChild('startTimeStamp').startAt(Date.now()).on(...
like image 84
Frank van Puffelen Avatar answered Sep 29 '22 06:09

Frank van Puffelen