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

查看:159
本文介绍了使用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:

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天全站免登陆