Add relative timestamp state_content for input_datetime (#24135)
* Fix digit grouping in input_datetime `year` * Display `input_datetime`s `timestamp` attribute as relative time instead of numberpull/26786/head
parent
0e8e054db1
commit
04b01d2cd9
|
@ -115,6 +115,9 @@ export const DOMAIN_ATTRIBUTES_FORMATERS: Record<
|
|||
return formatDurationDigital(locale, { hours, minutes, seconds })!;
|
||||
},
|
||||
},
|
||||
input_datetime: {
|
||||
year: (value) => value.toString(),
|
||||
},
|
||||
};
|
||||
|
||||
export const NON_NUMERIC_ATTRIBUTES = [
|
||||
|
|
|
@ -104,7 +104,7 @@ class StateDisplay extends LitElement {
|
|||
return html`${this.name || computeStateName(stateObj)}`;
|
||||
}
|
||||
|
||||
let relativeDateTime: string | undefined;
|
||||
let relativeDateTime: string | Date | undefined;
|
||||
|
||||
// Check last-changed for backwards compatibility
|
||||
if (content === "last_changed" || content === "last-changed") {
|
||||
|
@ -114,6 +114,9 @@ class StateDisplay extends LitElement {
|
|||
if (content === "last_updated" || content === "last-updated") {
|
||||
relativeDateTime = stateObj.last_updated;
|
||||
}
|
||||
if (domain === "input_datetime" && content === "timestamp") {
|
||||
relativeDateTime = new Date(stateObj.attributes.timestamp * 1000);
|
||||
}
|
||||
|
||||
if (
|
||||
content === "last_triggered" ||
|
||||
|
|
Loading…
Reference in New Issue