From 07ad5141a413ca37b4d761901ce582521aa380be Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Wed, 31 May 2023 23:11:12 -0500 Subject: [PATCH] fix radar timestamp sorting --- server/scripts/modules/radar.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/scripts/modules/radar.mjs b/server/scripts/modules/radar.mjs index dcbf608..1bd6cb1 100644 --- a/server/scripts/modules/radar.mjs +++ b/server/scripts/modules/radar.mjs @@ -91,7 +91,7 @@ class Radar extends WeatherDisplay { const anchors = xmlDoc.querySelectorAll('a'); const urls = []; Array.from(anchors).forEach((elem) => { - if (elem.innerHTML?.includes('.png') && elem.innerHTML?.includes('n0r_')) { + if (elem.innerHTML?.match(/n0r_\d{12}\.png/)) { urls.push(elem.href); } }); @@ -99,7 +99,8 @@ class Radar extends WeatherDisplay { }); // get the last few images - const sortedPngs = pngs.sort((a, b) => (Date(a) < Date(b) ? -1 : 1)); + const timestampRegex = /_(\d{12})\.png/; + const sortedPngs = pngs.sort((a, b) => (a.match(timestampRegex)[1] < b.match(timestampRegex)[1] ? -1 : 1)); const urls = sortedPngs.slice(-(this.dopplerRadarImageMax)); // calculate offsets and sizes