From 54c3e8118bad7337fdcea62786c0158eb103dd5c Mon Sep 17 00:00:00 2001 From: Ian Moffitt Date: Thu, 20 Jan 2022 06:45:30 -0500 Subject: [PATCH] feat: Improve weather alerts. --- modules/weather.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/weather.js b/modules/weather.js index 5356903..f31c40f 100644 --- a/modules/weather.js +++ b/modules/weather.js @@ -92,20 +92,36 @@ module.exports = { let diff = (currDate.getTime() - alertDate.getTime()) / 1000 / 60; // Minutes - let recent = (diff > 10); + let recent = (diff > 5); const key = breiutil.slugify(x['start'] + '-' + x['end'] + '-' + x['event']); let spentAlert = this.sentAlerts.filter(y => y === key); - return (recent && spentAlert.length === 0) || allAlerts; // More than 10 minute difference + return (recent && spentAlert.length === 0) || allAlerts; // More than 5 minute difference }); if (alerts.length > 0) { + // The API seems to mush all the alerts together anyway, but we'll loop through this anyway + // just in case it ever returns more than one. for (var i in alerts) { + + let aStart = 0; + let aEnd = 0; + if (alerts.hasOwnProperty(i)) { + if (i > 0) { + response.push('-----'); + } + response.push('*' + alerts[i]['sender_name'] + '*: ' + alerts[i]['description']); + + aStart = new Date(parseInt(alerts[i]['start'], 10) * 1000); + aEnd = new Date(parseInt(alerts[i]['end'], 10) * 1000); + + response.push('*In Effect:* ' + aStart.toString()); + response.push('*Expires:* ' + aEnd.toString()); } }