1 import { omit } from '../../helpers/object';
2 import type { VcalRrulePropertyValue, VcalVeventComponent } from '../../interfaces/calendar/VcalModel';
3 import { VcalDays } from '../../interfaces/calendar/VcalModel';
4 import { FREQUENCY } from '../constants';
5 import { numericDayToDay } from '../vcalConverter';
8 * WKST is significant when a WEEKLY "RRULE" has an interval greater than 1,
9 * and a BYDAY rule part is specified. This is also significant when
10 * in a YEARLY "RRULE" when a BYWEEKNO rule part is specified. The
11 * default value is MO. From rfc5545
13 export const withRruleWkst = (rrule: VcalRrulePropertyValue, wkst = VcalDays.MO): VcalRrulePropertyValue => {
14 if (wkst !== VcalDays.MO) {
15 const isWeeklySignificant =
16 rrule.freq === FREQUENCY.WEEKLY && (rrule.interval ?? 0) >= 1 && rrule.byday !== undefined;
18 const isYearlySignificant = rrule.freq === FREQUENCY.YEARLY && rrule.byweekno !== undefined;
20 if (isWeeklySignificant || isYearlySignificant) {
23 wkst: numericDayToDay(wkst),
32 return omit(rrule, ['wkst']);
35 const withVeventRruleWkst = <T>(vevent: VcalVeventComponent & T, wkst?: VcalDays): VcalVeventComponent & T => {
41 rrule: { value: withRruleWkst(vevent.rrule.value, wkst) },
45 export default withVeventRruleWkst;