diff --git a/MMM-CTA.js b/MMM-CTA.js index 4a5cacd..f0c4cd9 100644 --- a/MMM-CTA.js +++ b/MMM-CTA.js @@ -56,7 +56,9 @@ Module.register('MMM-CTA', { arrivals: stop.arrivals?.map((arrival) => ({ direction: arrival.direction, routeColor: arrival.routeColor ? `cta-${arrival.routeColor}` : '', - arrival: arrival.arrival ?? this.getMinutesUntil(arrival.time), + arrival: arrival.arrival + ? this.formatMinutes(arrival.arrival) + : this.getMinutesUntil(arrival.time), })), })), }; @@ -95,12 +97,22 @@ Module.register('MMM-CTA', { const diffInMilliseconds = new Date(arrivalTime) - now; const diffInMinutes = Math.floor(diffInMilliseconds / 1000 / 60); - if (diffInMinutes === 0) { + return this.formatMinutes(diffInMinutes); + }, + + formatMinutes(minutes) { + const minutesInt = parseInt(minutes, 10); + + if (Number.isNaN(minutesInt)) { + return minutes; + } + if (minutesInt === 0) { return 'DUE'; - } if (diffInMinutes === 1) { - return `${diffInMinutes.toString()} min`; + } + if (minutesInt === 1) { + return `${minutesInt.toString()} min`; } - return `${diffInMinutes.toString()} mins`; + return `${minutesInt.toString()} mins`; }, }); diff --git a/__tests__/MMM-CTA.spec.js b/__tests__/MMM-CTA.spec.js index 09b7563..1944173 100644 --- a/__tests__/MMM-CTA.spec.js +++ b/__tests__/MMM-CTA.spec.js @@ -104,7 +104,12 @@ describe('getTemplateData', () => { { route: '152', direction: 'Westbound', - arrival: '3', + arrival: 'DUE', + }, + { + route: '152', + direction: 'Westbound', + arrival: '1', }, { route: '152', @@ -127,12 +132,17 @@ describe('getTemplateData', () => { arrivals: [ { direction: 'Westbound', - arrival: '3', + arrival: 'DUE', + routeColor: '', + }, + { + direction: 'Westbound', + arrival: '1 min', routeColor: '', }, { direction: 'Westbound', - arrival: '27', + arrival: '27 mins', routeColor: '', }, ], diff --git a/screenshot.png b/screenshot.png index 0862da9..1267e84 100644 Binary files a/screenshot.png and b/screenshot.png differ