Skip to content

Commit

Permalink
add mins for busses
Browse files Browse the repository at this point in the history
  • Loading branch information
JHWelch committed Feb 19, 2024
1 parent d02fd94 commit f80015b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
22 changes: 17 additions & 5 deletions MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})),
})),
};
Expand Down Expand Up @@ -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`;
},
});
16 changes: 13 additions & 3 deletions __tests__/MMM-CTA.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ describe('getTemplateData', () => {
{
route: '152',
direction: 'Westbound',
arrival: '3',
arrival: 'DUE',
},
{
route: '152',
direction: 'Westbound',
arrival: '1',
},
{
route: '152',
Expand All @@ -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: '',
},
],
Expand Down

0 comments on commit f80015b

Please sign in to comment.