[Scheduler] Improve readability of some filters
The common conditions are now in the same ordermaster
parent
797eb12f7b
commit
531cf4b5f9
|
|
@ -8,12 +8,12 @@
|
||||||
var time = new Date();
|
var time = new Date();
|
||||||
var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000);
|
var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000);
|
||||||
var d = time.getDate();
|
var d = time.getDate();
|
||||||
var active = alarms.filter(
|
var active = alarms.filter(a =>
|
||||||
a=>a.on && // enabled
|
a.on // enabled
|
||||||
a.last!=d && // not already fired today
|
&& (a.last != d) // not already fired today
|
||||||
a.t+60000>currentTime && // is not in the past by >1 minute
|
&& (a.t + 60000 > currentTime) // is not in the past by >1 minute
|
||||||
(a.dow>>time.getDay())&1 && // is allowed on this day of the week
|
&& (a.dow >> time.getDay() & 1) // is allowed on this day of the week
|
||||||
(!a.date || a.date==time.toISOString().substr(0,10)) // is allowed on this date
|
&& (!a.date || a.date == time.toISOString().substr(0, 10)) // is allowed on this date
|
||||||
);
|
);
|
||||||
if (active.length) {
|
if (active.length) {
|
||||||
active = active.sort((a,b)=>a.t-b.t); // sort by time
|
active = active.sort((a,b)=>a.t-b.t); // sort by time
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,19 @@ exports.getAlarm = function(id) {
|
||||||
return exports.getAlarms().find(a=>a.id==id);
|
return exports.getAlarms().find(a=>a.id==id);
|
||||||
};
|
};
|
||||||
// Given a list of alarms from getAlarms, return a list of active alarms for the given time (or current time if time not specified)
|
// Given a list of alarms from getAlarms, return a list of active alarms for the given time (or current time if time not specified)
|
||||||
exports.getActiveAlarms = function(alarms, time) {
|
exports.getActiveAlarms = function (alarms, time) {
|
||||||
if (!time) time = new Date();
|
if (!time) time = new Date();
|
||||||
var currentTime = (time.getHours()*3600000)+(time.getMinutes()*60000)+(time.getSeconds()*1000)
|
// get current time 10s in future to ensure we alarm if we've started the app a tad early
|
||||||
+10000;// get current time - 10s in future to ensure we alarm if we've started the app a tad early
|
var currentTime = (time.getHours() * 3600000) + (time.getMinutes() * 60000) + (time.getSeconds() * 1000) + 10000;
|
||||||
return alarms.filter(a=>a.on
|
return alarms
|
||||||
&&(a.t<currentTime)
|
.filter(a =>
|
||||||
&&(a.last!=time.getDate())
|
a.on // enabled
|
||||||
&& (!a.date || a.date==time.toISOString().substr(0,10))
|
&& (a.last != time.getDate()) // not already fired today
|
||||||
&& a.dow >> (time).getDay() & 1)
|
&& (a.t < currentTime)
|
||||||
.sort((a,b)=>a.t-b.t);
|
&& (a.dow >> time.getDay() & 1) // is allowed on this day of the week
|
||||||
|
&& (!a.date || a.date == time.toISOString().substr(0, 10)) // is allowed on this date
|
||||||
|
)
|
||||||
|
.sort((a, b) => a.t - b.t);
|
||||||
}
|
}
|
||||||
// Set an alarm object based on ID. Leave 'alarm' undefined to remove it
|
// Set an alarm object based on ID. Leave 'alarm' undefined to remove it
|
||||||
exports.setAlarm = function(id, alarm) {
|
exports.setAlarm = function(id, alarm) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue