Skip to content

Commit

Permalink
Calendar trigger: Handle optional offset better (#23474)
Browse files Browse the repository at this point in the history
Calendar empty offset
  • Loading branch information
silamon authored Dec 27, 2024
1 parent 1b9cbe4 commit cf91e6a
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/data/automation_i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,18 +737,22 @@ const tryDescribeTrigger = (
? computeStateName(hass.states[trigger.entity_id])
: trigger.entity_id;

let offsetChoice = trigger.offset.startsWith("-") ? "before" : "after";
let offset: string | string[] = trigger.offset.startsWith("-")
? trigger.offset.substring(1).split(":")
: trigger.offset.split(":");
const duration = {
hours: offset.length > 0 ? +offset[0] : 0,
minutes: offset.length > 1 ? +offset[1] : 0,
seconds: offset.length > 2 ? +offset[2] : 0,
};
offset = formatDurationLong(hass.locale, duration);
if (offset === "") {
offsetChoice = "other";
let offsetChoice: string = "other";
let offset: string | string[] = "";
if (trigger.offset) {
offsetChoice = trigger.offset.startsWith("-") ? "before" : "after";
offset = trigger.offset.startsWith("-")
? trigger.offset.substring(1).split(":")
: trigger.offset.split(":");
const duration = {
hours: offset.length > 0 ? +offset[0] : 0,
minutes: offset.length > 1 ? +offset[1] : 0,
seconds: offset.length > 2 ? +offset[2] : 0,
};
offset = formatDurationLong(hass.locale, duration);
if (offset === "") {
offsetChoice = "other";
}
}

return hass.localize(
Expand Down

0 comments on commit cf91e6a

Please sign in to comment.