Skip to content

Commit

Permalink
Merge pull request #13 from JHWelch/add-min-to-bus
Browse files Browse the repository at this point in the history
Add min to bus
  • Loading branch information
JHWelch authored Feb 19, 2024
2 parents d02fd94 + bc95ec4 commit a9079fa
Show file tree
Hide file tree
Showing 3 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
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a9079fa

Please sign in to comment.