fix: relativeTime didn't support to set the first letter uppercase

Fix #735
This commit is contained in:
Jérôme Wiedemann 2023-07-28 11:12:28 +00:00
parent 1638cf8121
commit f8b9b09169
2 changed files with 3 additions and 2 deletions

View File

@ -368,7 +368,7 @@ Inside the javascript code, you'll have access to those variables:
- `helpers.formatShortDateTime(datetime)`: August 9, 2021, 8:23:15 AM
- `helpers.formatShortDateTimeWithYear(datetime)`: 9/8/2021, 8:23 AM
- Example: `return helpers.formatDateTime(entity.attribute.last_changed)`
- `helpers.relativeTime(date)`: Returns an lit-html template which will render a relative time and update automatically. `date` should be a string. Usage for eg.: `return helpers.relativeTime(entity.last_changed)`
- `helpers.relativeTime(date, capitalize? = false)`: Returns an lit-html template which will render a relative time and update automatically. `date` should be a string. `capitalize` is an optional boolean, if set to `true`, the first letter will be uppercase. Usage for eg.: `return helpers.relativeTime(entity.last_changed)`
See [here](#templates-support) for some examples or [here](#custom-fields) for some crazy advanced stuff using templates!

View File

@ -337,7 +337,7 @@ class ButtonCard extends LitElement {
);
}
private _relativeTime(date: string | undefined) {
private _relativeTime(date: string | undefined, capitalize: boolean = false) {
if (date) {
return html`
<ha-relative-time
@ -345,6 +345,7 @@ class ButtonCard extends LitElement {
class="ellipsis"
.hass="${this._hass}"
.datetime="${date}"
.capitalize="${capitalize}"
></ha-relative-time>
`;
}