Server Side Computation Using Firebase

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

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

Client-side javascript to determine if a 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 a show has ended yet:

 // if negative, then show has finished var timeLeft = channelDuration - timerStartTime; 
+7
javascript firebase
source share
2 answers

Unable to run native Firebase server code. Cm:

But you can save the timestamp on the server side, which seems like you're trying to do:

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

Then you can get impressions that have not started yet:

 var shows = ref.child('Shows'); ref.orderByChild('startTimeStamp').startAt(Date.now()).on(... 
+10
source share

For someone passing by, I think Firebase will now let you do this with Cloud Function . In this case, you can create a function that determines the status status with another parameter when the data is added to your database.

Please check

https://firebase.google.com/docs/functions/

+3
source share

All Articles