使用Firebase进行服务器端计算 [英] Server Side Calculation using Firebase
本文介绍了使用Firebase进行服务器端计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
finished
,正在进行
或即将到来
- 显示
--duration:144
--startDate:2015-11-10
--startTime:14:00
- 状态: ?
客户端javascript确定展示是否已经开始了
//如果为负,那么show还没有开始
var time =( - (startdate.getTime() - currentdate.getTime()) / 1000/60);
客户端javascript确定展示是否已经完成了运行:
//如果为负数,则显示已经完成
var timeLeft = channelDuration - timerStartTime;
解决方案
无法运行您自己的服务器端Firebase上的代码。见:
但是,您可以存储服务器端的时间戳,看起来您正在尝试做什么:
ref.child('Show / startTimestamp')。set(Firebase.ServerValue.TIMESTAMP);
然后您可以获取尚未开始的演出:
var shows = ref.child('Shows');
ref.orderByChild('startTimeStamp')。startAt(Date.now())。on(...
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;
解决方案
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(...
这篇关于使用Firebase进行服务器端计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文