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 parameter showRelativeTimeOnlyUnder #45

Merged
merged 1 commit into from
Mar 9, 2022
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
1 change: 1 addition & 0 deletions MMM-PublicTransportHafas.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Module.register("MMM-PublicTransportHafas", {
showColoredLineSymbols: true, // Want colored line symbols?
useColorForRealtimeInfo: true, // Want colored real time information (timeToStation, early)?
showAbsoluteTime: true, // How should the departure time be displayed? "15:10" (absolute) or "in 5 minutes" (relative)
showRelativeTimeOnlyUnder: 10*60*1000, // Display the time only relatively if the departure takes place in less than 10 minutes (600000 milliseconds). The value is only relevant if showAbsoluteTime: false.
showTableHeaders: true, // Show table headers?
showTableHeadersAsSymbols: true, // Table Headers as symbols or written?
showWarningRemarks: true, // Show warning remarks?
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ These are the possible options:
| `showColoredLineSymbols` | <p>A boolean value indicating whether the line symbols should be colored or black and white.</p><p>**Type:** `boolean`<br>**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `true` it is possible to decorate the line labels with the colors which are used in your town. This module comes with decorations for Leipzig. To provide your own colors see [Providing a custom CSS file](#providing-a-custom-css-file).</p>|
| `useColorForRealtimeInfo` | <p>A boolean value indicating whether delays should be displayed in color.</p><p>**Type:** `boolean`**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `true` a delay will be displayed in red. Values `<= 0` (transport arrives in time or early) will be displayed in green. If you want to customize that see [Providing a custom CSS file](#customizing-the-color-for-delays).</p>|
| `showAbsoluteTime` | <p>A boolean indicating whether the departure time should be displayed as an absolute value or not.</p><p>**Type:** `boolean`<br>**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `true` the departure time would be displayed as “10:15+0”. If set to `false` the departure time would be displayed in a relative manner like so: `in 5 minutes`. The displayed string is determined by your locale. If your locale is set to `de` the string would be `in 5 Minuten`.</p> |
| `showRelativeTimeOnlyUnder` | <p>Display the time only relatively if the departure takes place in less than 10 minutes (600000 milliseconds).</p><p>**Type:** `integer`<br>**Default value:** `10*60*1000` (10 minutes)<br></p><p>**Note:** The value is only relevant if `showAbsoluteTime: false`.</p> |
| `showTableHeaders` | <p>A boolean indicating whether a table header should be shown or not.</p><p>**Type:** `boolean`<br>**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `false` no table headings like “time” or “direction” will be shown. Also no symbols are shown.</p>|
| `showTableHeadersAsSymbols` | <p>A boolean value indicating whether table headers should be shown as symbols or text.</p><p>**Type:** `boolean`<br>**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `true` table headers will use symbols, else text will be shown. This setting is only effective if `showTableHeaders` is set to `true`. The shown text is available in English and German. Feel free to add translations to this project.</p> |
| `showWarningRemarks` | <p>A boolean value indicating whether warnings attached to a trip should be shown.</p><p>**Type:** `boolean`<br>**Default value:** `true`<br>**Possible values:** `true` and `false`</p><p>**Note:** If set to `true` and a warning is attached to a trip it will be shown in a additional row. This default width of this row is `80ch`, the whole table is then given this width. If you want to change that, set a different value in your `custom.css` such as: `.mmm-pth-warning-remarks { width: 70ch; }`.</p> |
Expand Down
8 changes: 6 additions & 2 deletions core/PTHAFASTableBodyBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ class PTHAFASTableBodyBuilder {
}

getDisplayDepartureTime(when, delay) {
let time = dayjs(when);

if (this.config.showAbsoluteTime) {
const time = dayjs(when).subtract(delay, "seconds");
time = dayjs(when).subtract(delay, "seconds");
return time.format("LT");
}
if (dayjs(when).diff(dayjs()) > this.config.showRelativeTimeOnlyUnder) {
return time.format("LT");
}
const time = dayjs(when);
return time.fromNow();
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mmm-publictransporthafas",
"version": "1.5.0",
"version": "1.5.1",
"description": "Public transport module for MagicMirror² driven by hafas-client data.",
"repository": {
"type": "git",
Expand Down