Skip to content

Commit

Permalink
fix: relativeTime didn't support to set the first letter uppercase
Browse files Browse the repository at this point in the history
Fix #735
  • Loading branch information
RomRider committed Jul 28, 2023
1 parent 1638cf8 commit f8b9b09
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
3 changes: 2 additions & 1 deletion src/button-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,15 @@ class ButtonCard extends LitElement {
);
}

private _relativeTime(date: string | undefined) {
private _relativeTime(date: string | undefined, capitalize: boolean = false) {
if (date) {
return html`
<ha-relative-time
id="relative-time"
class="ellipsis"
.hass="${this._hass}"
.datetime="${date}"
.capitalize="${capitalize}"
></ha-relative-time>
`;
}
Expand Down

0 comments on commit f8b9b09

Please sign in to comment.