diff --git a/x-pack/plugins/alerting/server/lib/is_rule_snoozed.ts b/x-pack/plugins/alerting/server/lib/is_rule_snoozed.ts index 927a21cd8cb14..a950171beb291 100644 --- a/x-pack/plugins/alerting/server/lib/is_rule_snoozed.ts +++ b/x-pack/plugins/alerting/server/lib/is_rule_snoozed.ts @@ -10,6 +10,8 @@ import { SanitizedRule, RuleTypeParams } from '../../common/rule'; type RuleSnoozeProps = Pick, 'muteAll' | 'snoozeSchedule'>; +const WEEKDAY_CODES = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA']; + export function getRuleSnoozeEndTime(rule: RuleSnoozeProps): Date | null { if (rule.snoozeSchedule == null) { return null; @@ -59,7 +61,8 @@ export function isRuleSnoozed(rule: RuleSnoozeProps) { function parseByWeekday(byweekday: Array): ByWeekday[] { return byweekday.map((w) => { if (typeof w === 'number') return w; - if (['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'].includes(w)) return w as WeekdayStr; + if (WEEKDAY_CODES.includes(w)) return w as WeekdayStr; + // Handle nth day codes, for example, +1MO means the first Monday of the month, -1FR means the last Friday, -2TH means second to last Thursday const dayOfWeek = w.slice(-2) as WeekdayStr; const nthDay = w.slice(0, 2); return RRule[dayOfWeek].nth(Number(nthDay));