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;
For someone passing by, I think now Firebase allow you to do this by
Cloud Function
. For this case, you can create the function that determine thestatus
of the status by other parameter when the data is added to you database.Please checkout
https://firebase.google.com/docs/functions/
There is no way to run your own server-side code on Firebase. See:
But you can store a server-side timestamp, which seems what you're trying to do:
You can then get the shows that haven't started yet with: