summaryrefslogtreecommitdiffstats
path: root/server/api/configloader.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/api/configloader.js')
-rw-r--r--server/api/configloader.js21
1 files changed, 11 insertions, 10 deletions
diff --git a/server/api/configloader.js b/server/api/configloader.js
index 0e64dcf..6b69a49 100644
--- a/server/api/configloader.js
+++ b/server/api/configloader.js
@@ -115,36 +115,37 @@ noAuthRouter.get('/getconfig/:configId', (req, res) => {
function checkEventNow (times) {
var now = new Date()
+ var start = new Date(times.start)
+ var end = new Date(times.end)
if (!times.repetitive) {
- if (times.start * 1000 <= now && now < times.end * 1000) return true
+ if (start < now && now < end) return true
}
if (times.repetitive) {
- var startHourMinutes = times.startTime.split(':').map(x => parseInt(x, 10))
- var endHourMinutes = times.endTime.split(':').map(x => parseInt(x, 10))
- var startDate = new Date(times.startDate * 1000)
- var endDate = new Date(times.endDate * 1000)
+ var startSplit = times.start.split(' ')
+ var startHourMinutes = startSplit[1].split(':').map(x => parseInt(x, 10))
+ var endSplit = times.end.split(' ')
+ var endHourMinutes = endSplit[1].split(':').map(x => parseInt(x, 10))
+
var startAtDay = new Date()
var endAtDay = new Date()
var overnight = false
- startDate.setHours(startHourMinutes[0], startHourMinutes[1], 0, 0)
- endDate.setHours(endHourMinutes[0], endHourMinutes[1], 0, 0)
startAtDay.setHours(startHourMinutes[0], startHourMinutes[1], 0, 0)
endAtDay.setHours(endHourMinutes[0], endHourMinutes[1], 0, 0)
if (endAtDay > now && startAtDay > now && endAtDay < startAtDay) {
var yesterday = new Date(now)
yesterday.setDate(yesterday.getDate() - 1)
- if (checkEventInterval(startDate, yesterday, times.intervalType, times.interval)) {
+ if (checkEventInterval(start, yesterday, times.intervalType, times.interval)) {
startAtDay.setDate(startAtDay.getDate() - 1)
overnight = true
} else return false
} else if (endAtDay < now && startAtDay > now) endAtDay.setDate(endAtDay.getDate() + 1)
else if (endAtDay < now && startAtDay < now && endAtDay < startAtDay) endAtDay.setDate(endAtDay.getDate() + 1)
- if (!(times.monthMap[now.getMonth()] && (overnight ? times.dayMap[((yesterday.getDay() + 6) % 7)] : times.dayMap[((now.getDay() + 6) % 7)]) && startDate <= now && now < endDate && startAtDay <= now && now < endAtDay)) return false
+ if (!(times.monthMap[now.getMonth()] && (overnight ? times.dayMap[((yesterday.getDay() + 6) % 7)] : times.dayMap[((now.getDay() + 6) % 7)]) && start < now && now < end && startAtDay <= now && now < endAtDay)) return false
- return (overnight ? true : checkEventInterval(startDate, now, times.intervalType, times.interval))
+ return (overnight ? true : checkEventInterval(start, now, times.intervalType, times.interval))
}
return false
}