Skip to content

Commit

Permalink
Clarify isRuleSnoozed
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacqary committed May 18, 2022
1 parent 22e839e commit 25f8f7d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion x-pack/plugins/alerting/server/lib/is_rule_snoozed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { SanitizedRule, RuleTypeParams } from '../../common/rule';

type RuleSnoozeProps = Pick<SanitizedRule<RuleTypeParams>, '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;
Expand Down Expand Up @@ -59,7 +61,8 @@ export function isRuleSnoozed(rule: RuleSnoozeProps) {
function parseByWeekday(byweekday: Array<string | number>): 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));
Expand Down

0 comments on commit 25f8f7d

Please sign in to comment.