From aa123eea63124a268be43254f5298428c92af895 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Fri, 19 Apr 2019 13:20:43 +0000 Subject: [eventmanager + configloader] safe time string instead of unix timestamp --- server/api/configloader.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'server/api') 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 } -- cgit v1.2.3-55-g7522