From 5e9ca6d4587215cc0ce33b3971f53f734f789327 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Mon, 22 Jan 2024 21:09:59 -0600 Subject: [PATCH] if time 0, show "DUE" --- MMM-CTA.js | 3 ++- __tests__/MMM-CTA.spec.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/MMM-CTA.js b/MMM-CTA.js index 958d2df..c08aaaf 100644 --- a/MMM-CTA.js +++ b/MMM-CTA.js @@ -90,7 +90,8 @@ Module.register('MMM-CTA', { getMinutesUntil(arrivalTime) { const now = new Date(); const diffInMilliseconds = new Date(arrivalTime) - now; + const diffInMinutes = Math.floor(diffInMilliseconds / 1000 / 60); - return Math.floor(diffInMilliseconds / 1000 / 60); + return diffInMinutes === 0 ? 'DUE' : diffInMinutes.toString(); }, }); diff --git a/__tests__/MMM-CTA.spec.js b/__tests__/MMM-CTA.spec.js index 885cfbf..c19529f 100644 --- a/__tests__/MMM-CTA.spec.js +++ b/__tests__/MMM-CTA.spec.js @@ -139,7 +139,8 @@ describe('getTemplateData', () => { describe('train information', () => { beforeEach(() => { - jest.useFakeTimers().setSystemTime(new Date()); // Ensures time is consistent + now = new Date(); + jest.useFakeTimers().setSystemTime(now); // Ensures time is consistent threeMinutes = new Date(); threeMinutes.setMinutes(threeMinutes.getMinutes() + 3); twelveMinutes = new Date(); @@ -149,6 +150,10 @@ describe('getTemplateData', () => { type: 'train', name: 'Mock Stop', arrivals: [ + { + direction: '95th/Dan Ryan', + time: now, + }, { direction: '95th/Dan Ryan', time: threeMinutes, @@ -172,11 +177,15 @@ describe('getTemplateData', () => { arrivals: [ { direction: '95th/Dan Ryan', - arrival: 3, + arrival: 'DUE', + }, + { + direction: '95th/Dan Ryan', + arrival: '3', }, { direction: 'Howard', - arrival: 12, + arrival: '12', }, ], }],