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 "uping"
--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;
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 "uping"
--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;
Share
Improve this question
edited Nov 11, 2015 at 20:28
Kato
40.6k6 gold badges122 silver badges149 bronze badges
asked Nov 11, 2015 at 2:12
OnichanOnichan
4,5166 gold badges33 silver badges61 bronze badges
1
- Possible duplicate of How would I run server-side code in Firebase? – Kato Commented Nov 11, 2015 at 20:29
2 Answers
Reset to default 10There 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(...
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 the status
of the status by other parameter when the data is added to you database.
Please checkout
https://firebase.google./docs/functions/