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

Fix formatting time diffs and remove dependency on moment-duration #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions MMM-MyCommute.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Module.register('MMM-MyCommute', {

// Define required scripts.
getScripts: function() {
return ["moment.js", this.file("node_modules/moment-duration-format/lib/moment-duration-format.js")];
return ["moment.js"];
},

// Define required styles.
Expand Down Expand Up @@ -281,12 +281,21 @@ Module.register('MMM-MyCommute', {
return(svg);
},

formatTimeString: function (time) {
var start = moment();
var end = start.clone();
end = end.add(Number(time), 's');
var diff = end.diff(start);

return moment.utc(diff).format(this.config.travelTimeFormat, {trim: this.config.travelTimeFormatTrim});
},

formatTime: function(time, timeInTraffic) {

var timeEl = document.createElement("span");
timeEl.classList.add("travel-time");
if (timeInTraffic != null) {
timeEl.innerHTML = moment.duration(Number(timeInTraffic), "seconds").format(this.config.travelTimeFormat, {trim: this.config.travelTimeFormatTrim});
timeEl.innerHTML = this.formatTimeString(timeInTraffic);

var variance = timeInTraffic / time;
if (this.config.colorCodeTravelTime) {
Expand All @@ -300,7 +309,7 @@ Module.register('MMM-MyCommute', {
}

} else {
timeEl.innerHTML = moment.duration(Number(time), "seconds").format(this.config.travelTimeFormat, {trim: this.config.travelTimeFormatTrim});
timeEl.innerHTML = this.formatTimeString(time);
timeEl.classList.add("status-good");
}

Expand Down
8 changes: 5 additions & 3 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
},
"homepage": "https://github.com/jclarke0000/MMM-MyCommute#readme",
"dependencies": {
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0",
"request": "^2.81.0"
"moment": "^2.29.4",
"request": "^2.88.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}