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

Added absoluteTime as config option #3

Open
wants to merge 8 commits 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
Binary file removed .github/preview.png
Binary file not shown.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Add module configuration to config.js.
|`destination`|The target location.<br><br>**Example:** `Frankfurt HBF`<br>This value is **REQUIRED**|
|`maxConnections`|How many connections should be displayed?<br><br>**Default value:** `3`|
|`updateInterval`|How often does the content needs to be fetched? (Minutes)<br><br>**Default value:** `5`|
|`absoluteTime`|If `true` displays the departure time as 'at hh:mm', if `false` displays 'in xx mins'<br><br>**Default value:** `false`|
|`showDuration`|If `true` displays the trip duration following the departure time<br><br>**Default value:** `false`|
|`animationSpeed`|Speed of the update animation. (Seconds)<br><br>**Default value:** `1`|

## Special Thanks
Expand Down
Binary file added i18n/.AppleDouble/.Parent
Binary file not shown.
Binary file added i18n/.AppleDouble/en.json
Binary file not shown.
3 changes: 2 additions & 1 deletion i18n/de.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"LOADING_CONNECTIONS": "Lade Verbindungen ..."
"LOADING_CONNECTIONS": "Lade Verbindungen ...",
"ABSOLUTE_PREFIX": "um "
}
4 changes: 4 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"LOADING_CONNECTIONS": "Loading Connections...",
"ABSOLUTE_PREFIX": "at "
}
23 changes: 18 additions & 5 deletions localtransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Module.register('localtransport', {
units: 'metric',
alternatives: true,
maxAlternatives: 3,
absoluteTime: false,
showDuration: false,
apiBase: 'https://maps.googleapis.com/',
apiEndpoint: 'maps/api/directions/json'
},
Expand All @@ -41,16 +43,26 @@ Module.register('localtransport', {
params += '&destination=' + this.config.destination;
params += '&key=' + this.config.api_key;
params += '&traffic_model=' + this.config.traffic_model;
params += '&departure_time=now';
params += '&alternatives=true';
params += '&departure_time=' + this.config.departure_time;
params += '&alternatives=' + this.config.alternatives;
return params;
},
renderLeg: function(wrapper, leg){
var depature = leg.departure_time.value * 1000;
var arrival = leg.arrival_time.value * 1000;
var span = document.createElement("div");
span.innerHTML =
moment(depature).fromNow()
if (!this.config.absoluteTime) {
span.innerHTML = moment(depature).fromNow()
} else {
if (config.timeFormat !== 24) {
span.innerHTML = this.translate('ABSOLUTE_PREFIX') + moment(depature).format('h:mm A')
} else {
span.innerHTML = this.translate('ABSOLUTE_PREFIX') + moment(depature).format('HH:mm')
}
}
if (this.config.showDuration) {
span.innerHTML += "(" + moment.duration(moment(arrival).diff(depature, 'minutes'), 'minutes').humanize() + ")";
}
// + this.translate('TRAVEL_TIME') + ": "
// + moment.duration(moment(arrival).diff(depature, 'minutes'), 'minutes').humanize()
;
Expand Down Expand Up @@ -89,7 +101,8 @@ Module.register('localtransport', {
},
getTranslations: function() {
return {
de: "i18n/de.json"
de: "i18n/de.json",
en: "i18n/en.json"
};
},
getDom: function() {
Expand Down