【问题标题】:Server Side Calculation using Firebase使用 Firebase 进行服务器端计算
【发布时间】:2016-02-12 02:34:18
【问题描述】:

鉴于开始时间/日期和持续时间,我如何进行服务器端计算来确定对象是"finished""in progress" 还是"upcoming"

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

客户端 javascript 来确定节目是否已经开始:

// if negative, then show hasn't started yet
var time = (-(startdate.getTime() - currentdate.getTime()) / 1000 / 60); 

客户端 javascript 来确定节目是否已经结束运行:

// if negative, then show has finished
var timeLeft = channelDuration - timerStartTime;

【问题讨论】:

标签: javascript firebase


【解决方案1】:

无法在 Firebase 上运行您自己的服务器端代码。见:

但是您可以存储服务器端时间戳,这似乎是您想要做的:

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

然后您可以获取尚未开始的节目:

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

【讨论】:

  • 嘿弗兰克,这些功能将来有可能添加吗?
【解决方案2】:

对于路过的人,我认为现在 Firebase 允许您通过 Cloud Function 执行此操作。对于这种情况,您可以创建一个函数,在将数据添加到您的数据库时,通过其他参数确定状态的status

请结帐

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    • 2018-08-09
    • 2012-03-31
    • 2015-12-11
    • 1970-01-01
    相关资源
    最近更新 更多