Server Side Calculation using Firebase

2019-01-04 14:21发布

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;

2条回答
淡お忘
2楼-- · 2019-01-04 14:43

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.com/docs/functions/

查看更多
对你真心纯属浪费
3楼-- · 2019-01-04 14:45

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:

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(...
查看更多
登录 后发表回答