From 307535206f33839ed96cce5e05c1f0a6f243ce6a Mon Sep 17 00:00:00 2001 From: Zacqary Adam Xeper Date: Wed, 17 May 2023 12:50:22 -0500 Subject: [PATCH] [8.8] [RAM] Fix snooze scheduler timezone handling (#157338) (#158011) # Backport This will backport the following commits from `main` to `8.8`: - [[RAM] Fix snooze scheduler timezone handling (#157338)](https://github.com/elastic/kibana/pull/157338) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) --- .../components/rule_snooze/scheduler.tsx | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rule_snooze/scheduler.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rule_snooze/scheduler.tsx index 1520255f21a80..917e232e3f0f3 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rule_snooze/scheduler.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/rules_list/components/rule_snooze/scheduler.tsx @@ -146,9 +146,21 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent = ({ ...(initialSchedule.rRule.until ? { until: moment(initialSchedule.rRule.until) } : {}), } as RecurrenceSchedule); + // Ensure intitial datetimes are displayed in the initial timezone + const startMoment = moment(initialSchedule.rRule.dtstart).tz(initialSchedule.rRule.tzid); + const dtstartOffsetToKibanaTz = moment() + .tz(defaultTz) + .year(startMoment.year()) + .month(startMoment.month()) + .date(startMoment.date()) + .hour(startMoment.hour()) + .minute(startMoment.minute()) + .second(startMoment.second()) + .millisecond(startMoment.millisecond()) + .toISOString(); return { - startDT: moment(initialSchedule.rRule.dtstart), - endDT: moment(initialSchedule.rRule.dtstart).add(initialSchedule.duration, 'ms'), + startDT: moment(dtstartOffsetToKibanaTz), + endDT: moment(dtstartOffsetToKibanaTz).add(initialSchedule.duration, 'ms'), isRecurring, recurrenceSchedule, selectedTimezone: [{ label: initialSchedule.rRule.tzid }], @@ -218,6 +230,19 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent = ({ const onClickSaveSchedule = useCallback(() => { if (!startDT || !endDT) return; + + const tzid = selectedTimezone[0].label ?? defaultTz; + // Convert the dtstart from Kibana timezone to the selected timezone + const dtstart = moment() + .tz(tzid) + .year(startDT.year()) + .month(startDT.month()) + .date(startDT.date()) + .hour(startDT.hour()) + .minute(startDT.minute()) + .second(startDT.second()) + .toISOString(); + const recurrence = isRecurring && recurrenceSchedule ? recurrenceSchedule @@ -227,8 +252,8 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent = ({ onSaveSchedule({ id: initialSchedule?.id ?? uuidv4(), rRule: { - dtstart: startDT.toISOString(), - tzid: selectedTimezone[0].label ?? defaultTz, + dtstart, + tzid, ...recurrence, }, duration: endDT.valueOf() - startDT.valueOf(),