Skip to content

Commit

Permalink
Added ability to configure format for travel time
Browse files Browse the repository at this point in the history
  • Loading branch information
jclarke0000 committed Aug 1, 2017
1 parent 7ff719f commit 2f736b3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 4 additions & 3 deletions MMM-MyCommute.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Module.register('MMM-MyCommute', {
moderateTimeThreshold: 1.1,
poorTimeThreshold: 1.3,
nextTransitVehicleDepartureFormat: "[next at] h:mm a",
travelTimeFormat: "m [min]",
destinations: [
{
destination: '40 Bay St, Toronto, ON M5J 2X2',
Expand Down Expand Up @@ -55,7 +56,7 @@ Module.register('MMM-MyCommute', {

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

// Define required styles.
Expand Down Expand Up @@ -294,7 +295,7 @@ Module.register('MMM-MyCommute', {
var timeEl = document.createElement("span");
timeEl.classList.add("travel-time");
if (timeInTraffic != null) {
timeEl.innerHTML = Math.floor(Number(timeInTraffic) / 60) + " min";
timeEl.innerHTML = moment.duration(Number(timeInTraffic), "seconds").format(this.config.travelTimeFormat);

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

} else {
timeEl.innerHTML = Math.floor(Number(time) / 60) + " min";
timeEl.innerHTML = moment.duration(Number(time), "seconds").format(this.config.travelTimeFormat);
timeEl.classList.add("status-good");
}

Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ If you don’t want a header, then just omit it.
<td><code>colorCodeTravelTime</code></td>
<td>Whether to colour-code the travel time red, yellow, or green based on traffic.<br><br><strong>Type:</strong> <code>boolean</code><br>Defaults to <code>true</code></td>
</tr>
<tr>
<td><code>travelTimeFormat</code></td>
<td>How the module should format your total travel time.<br><br><strong>Type:</strong> <code>string</code><br>Defaults to <code>m [min]</code> (e.g. 86 min). Some other examples are <code>h[h] m[m]</code> (e.g.: 1h 26min), <code>h:mm</code> (e.g. 1:26). This uses the <code>moment-duration-format</code> plugin's templating feature. https://github.com/jsmreese/moment-duration-format#template</td>
</tr>
<tr>
<td><code>moderateTimeThreshold</code></td>
<td>The amount of variance between time in traffic vs absolute fastest time after which the time is coloured yellow<br><br><strong>Type:</strong> <code>float</code><br>Defaults to <code>1.1</code> (i.e.: 10% longer than fastest time)</td>
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"homepage": "https://github.com/jclarke0000/MMM-MyCommute#readme",
"dependencies": {
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0",
"request": "^2.81.0"
}
}

0 comments on commit 2f736b3

Please sign in to comment.