所有设备按店铺营业时段访问台账
This commit is contained in:
1 parent
67b145c4b8
commit
76db0e0277
10 files changed
+223
-22
No files matched your search
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
// 北京时间的每日半开区间;跨午夜时,凌晨部分属于前一天开始的营业时段。
|
||||
function accessWindow(hours,now=Date.now()){
|
||||
if(!hours)return {state:'unset'};
|
||||
const day=86400000;
|
||||
const midnight=Math.floor((now+8*3600000)/day)*day-8*3600000;
|
||||
const millis=time=>(Number(time.slice(0,2))*60+Number(time.slice(3)))*60000;
|
||||
const open=millis(hours.open),close=millis(hours.close),elapsed=now-midnight;
|
||||
const active=open<close?elapsed>=open&&elapsed<close:elapsed>=open||elapsed<close;
|
||||
if(!active)return {state:'closed',message:'现在是非营业时间。每日开放时段为北京时间 '+hours.open+' 至 '+(close<open?'次日 ':'')+hours.close+'。'};
|
||||
return {state:'open',serverTime:now,closesAt:midnight+close+(close<open&&elapsed>=open?day:0)};
|
||||
}
|
||||
module.exports={accessWindow};
|
||||
Reference in new issue
Block a user