Skip to content

Commit

Permalink
Merge pull request #15 from jeremywillans/master
Browse files Browse the repository at this point in the history
Add Friendly Timestamp Attribute
  • Loading branch information
Gluwc authored Aug 24, 2020
2 parents 5d3a825 + de99f1a commit e2a1d65
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ return msg;
| timeout | string | none | Attribute **required** for `due` config option. `minutes`, `days`, `weeks`, `months`, `years`.
| text | object | none | A list defining the text displayed. `minute(s)`, `day(s)`, `week(s)`, `month(s)`, `year(s)`, `ago`, `less_than`, `more_than`, `due_by`, `over_by`.
| due | boolean | false | Sets the card to display the due time based on `timeout` value set in the config.
| locale | string | 'en-us' | Sets the friendly timestamp locale.
| unit_of_measurement | string | none | Define the unit of measurement of the sensor.
| icon | string | mdi:checkbox-marked | Define a custom icon for this sensor.
| undo_timeout | number | 15 | Time until undo button times out in seconds.
Expand Down
4 changes: 3 additions & 1 deletion src/check-button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class CheckButtonCard extends HTMLElement {
over_by: 'over by'
},
display_limit: null,
due: false
due: false,
locale: 'en-us'
};

// Merge text objects
Expand Down Expand Up @@ -605,6 +606,7 @@ class CheckButtonCard extends HTMLElement {
const config = this._config;
let payload: any = {};
payload.timestamp = timestamp;
payload.timestamp_friendly = new Date(timestamp*1000).toLocaleString(config.locale);
payload.timeout = config.timeout;
if (config.timeout) {
payload.timeout_timestamp = this._convertToSeconds(config.timeout) + Number(timestamp);
Expand Down

0 comments on commit e2a1d65

Please sign in to comment.