mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 12:56:37 +00:00
Catch error if input_datetime state is incorrect (#10237)
This commit is contained in:
parent
2c2809573f
commit
05711b4636
@ -39,7 +39,7 @@ export const computeStateDisplay = (
|
|||||||
const domain = computeStateDomain(stateObj);
|
const domain = computeStateDomain(stateObj);
|
||||||
|
|
||||||
if (domain === "input_datetime") {
|
if (domain === "input_datetime") {
|
||||||
if (state) {
|
if (state !== undefined) {
|
||||||
// If trying to display an explicit state, need to parse the explict state to `Date` then format.
|
// If trying to display an explicit state, need to parse the explict state to `Date` then format.
|
||||||
// Attributes aren't available, we have to use `state`.
|
// Attributes aren't available, we have to use `state`.
|
||||||
try {
|
try {
|
||||||
@ -63,7 +63,7 @@ export const computeStateDisplay = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return state;
|
return state;
|
||||||
} catch {
|
} catch (_e) {
|
||||||
// Formatting methods may throw error if date parsing doesn't go well,
|
// Formatting methods may throw error if date parsing doesn't go well,
|
||||||
// just return the state string in that case.
|
// just return the state string in that case.
|
||||||
return state;
|
return state;
|
||||||
@ -71,20 +71,7 @@ export const computeStateDisplay = (
|
|||||||
} else {
|
} else {
|
||||||
// If not trying to display an explicit state, create `Date` object from `stateObj`'s attributes then format.
|
// If not trying to display an explicit state, create `Date` object from `stateObj`'s attributes then format.
|
||||||
let date: Date;
|
let date: Date;
|
||||||
if (!stateObj.attributes.has_time) {
|
if (stateObj.attributes.has_date && stateObj.attributes.has_time) {
|
||||||
date = new Date(
|
|
||||||
stateObj.attributes.year,
|
|
||||||
stateObj.attributes.month - 1,
|
|
||||||
stateObj.attributes.day
|
|
||||||
);
|
|
||||||
return formatDate(date, locale);
|
|
||||||
}
|
|
||||||
if (!stateObj.attributes.has_date) {
|
|
||||||
date = new Date();
|
|
||||||
date.setHours(stateObj.attributes.hour, stateObj.attributes.minute);
|
|
||||||
return formatTime(date, locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
date = new Date(
|
date = new Date(
|
||||||
stateObj.attributes.year,
|
stateObj.attributes.year,
|
||||||
stateObj.attributes.month - 1,
|
stateObj.attributes.month - 1,
|
||||||
@ -94,6 +81,21 @@ export const computeStateDisplay = (
|
|||||||
);
|
);
|
||||||
return formatDateTime(date, locale);
|
return formatDateTime(date, locale);
|
||||||
}
|
}
|
||||||
|
if (stateObj.attributes.has_date) {
|
||||||
|
date = new Date(
|
||||||
|
stateObj.attributes.year,
|
||||||
|
stateObj.attributes.month - 1,
|
||||||
|
stateObj.attributes.day
|
||||||
|
);
|
||||||
|
return formatDate(date, locale);
|
||||||
|
}
|
||||||
|
if (stateObj.attributes.has_time) {
|
||||||
|
date = new Date();
|
||||||
|
date.setHours(stateObj.attributes.hour, stateObj.attributes.minute);
|
||||||
|
return formatTime(date, locale);
|
||||||
|
}
|
||||||
|
return stateObj.state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (domain === "humidifier") {
|
if (domain === "humidifier") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user