Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAM] Fix snooze scheduler timezone handling #157338

Merged
merged 1 commit into from
May 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,21 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent<PanelOpts> = ({
...(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 }],
Expand Down Expand Up @@ -218,6 +230,19 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent<PanelOpts> = ({

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
Expand All @@ -227,8 +252,8 @@ const RuleSnoozeSchedulerPanel: React.FunctionComponent<PanelOpts> = ({
onSaveSchedule({
id: initialSchedule?.id ?? uuidv4(),
rRule: {
dtstart: startDT.toISOString(),
tzid: selectedTimezone[0].label ?? defaultTz,
dtstart,
tzid,
...recurrence,
},
duration: endDT.valueOf() - startDT.valueOf(),
Expand Down