使用 Firebase 进行服务器端计算 [英] Server Side Calculation using Firebase

查看:30
本文介绍了使用 Firebase 进行服务器端计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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: "?"

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

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); 

客户端 javascript 以确定节目是否已完成运行:

Client-side javascript to determine if the show has finished running yet:

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

推荐答案

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

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(...

这篇关于使用 Firebase 进行服务器端计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆