Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min to bus #13

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading