diff --git a/tests/recurrence/monthly.spec.ts b/tests/recurrence/monthly.spec.ts index f9fd344..f2b5c8a 100644 --- a/tests/recurrence/monthly.spec.ts +++ b/tests/recurrence/monthly.spec.ts @@ -89,6 +89,67 @@ describe('Monthly', () => { expect([...set]).toEqual(dates); }); + it('every friday the 13th for 5 occurrences', () => { + const rrule = new RRule(Frequency.Monthly) + .setCount(5) + .setByWeekday([Weekday.Friday]) + .setByMonthday([13]); + const set = new RRuleSet( + DateTime.create(1997, 9, 2, 9, 0, 0, false), + 'America/New_York', + ) + .addRrule(rrule) + .addExdate(DateTime.create(1998, 11, 13, 9, 0, 0, false)); + + const asString = set.toString(); + const dates = set.all(); + + expect(asString).toBe( + 'DTSTART;TZID=America/New_York:19970902T090000\nRRULE:FREQ=MONTHLY;COUNT=5;BYMONTHDAY=13;BYDAY=FR\nEXDATE:19981113T090000', + ); + expect(dates).toEqual([ + DateTime.create(1998, 2, 13, 9, 0, 0, false), + DateTime.create(1998, 3, 13, 9, 0, 0, false), + DateTime.create(1999, 8, 13, 9, 0, 0, false), + DateTime.create(2000, 10, 13, 9, 0, 0, false), + ]); + expect([...set]).toEqual(dates); + }); + + it('the second-to-last weekday of the month', () => { + const rrule = new RRule(Frequency.Monthly) + .setCount(7) + .setByWeekday([ + Weekday.Monday, + Weekday.Tuesday, + Weekday.Wednesday, + Weekday.Thursday, + Weekday.Friday, + ]) + .setBySetpos([-2]); + const set = new RRuleSet( + DateTime.create(1997, 9, 29, 9, 0, 0, false), + 'America/New_York', + ).addRrule(rrule); + + const asString = set.toString(); + const dates = set.all(); + + expect(asString).toBe( + 'DTSTART;TZID=America/New_York:19970929T090000\nRRULE:FREQ=MONTHLY;COUNT=7;BYSETPOS=-2;BYDAY=MO,TU,WE,TH,FR', + ); + expect(dates).toEqual([ + DateTime.create(1997, 9, 29, 9, 0, 0, false), + DateTime.create(1997, 10, 30, 9, 0, 0, false), + DateTime.create(1997, 11, 27, 9, 0, 0, false), + DateTime.create(1997, 12, 30, 9, 0, 0, false), + DateTime.create(1998, 1, 29, 9, 0, 0, false), + DateTime.create(1998, 2, 26, 9, 0, 0, false), + DateTime.create(1998, 3, 30, 9, 0, 0, false), + ]); + expect([...set]).toEqual(dates); + }); + it('monthly on the second to last Monday of the month for 6 months', () => { const rrule = new RRule(Frequency.Monthly) .setCount(6) diff --git a/tests/recurrence/weekly.spec.ts b/tests/recurrence/weekly.spec.ts index 2082582..329d20f 100644 --- a/tests/recurrence/weekly.spec.ts +++ b/tests/recurrence/weekly.spec.ts @@ -141,4 +141,56 @@ describe('Weekly', () => { ]); expect([...set]).toEqual(dates); }); + + it('every other week for 4 occurrences when week starts on Monday', () => { + const rrule = new RRule(Frequency.Weekly) + .setInterval(2) + .setCount(4) + .setByWeekday([Weekday.Tuesday, Weekday.Sunday]) + .setWeekstart(Weekday.Monday); + const set = new RRuleSet( + DateTime.create(1997, 8, 5, 9, 0, 0, false), + 'America/New_York', + ).addRrule(rrule); + + const asString = set.toString(); + const dates = set.all(); + + expect(asString).toBe( + 'DTSTART;TZID=America/New_York:19970805T090000\nRRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO', + ); + expect(dates).toEqual([ + DateTime.create(1997, 8, 5, 9, 0, 0, false), + DateTime.create(1997, 8, 10, 9, 0, 0, false), + DateTime.create(1997, 8, 19, 9, 0, 0, false), + DateTime.create(1997, 8, 24, 9, 0, 0, false), + ]); + expect([...set]).toEqual(dates); + }); + + it('every other week for 4 occurrences when week starts on Sunday', () => { + const rrule = new RRule(Frequency.Weekly) + .setInterval(2) + .setCount(4) + .setByWeekday([Weekday.Tuesday, Weekday.Sunday]) + .setWeekstart(Weekday.Sunday); + const set = new RRuleSet( + DateTime.create(1997, 8, 5, 9, 0, 0, false), + 'America/New_York', + ).addRrule(rrule); + + const asString = set.toString(); + const dates = set.all(); + + expect(asString).toBe( + 'DTSTART;TZID=America/New_York:19970805T090000\nRRULE:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU', + ); + expect(dates).toEqual([ + DateTime.create(1997, 8, 5, 9, 0, 0, false), + DateTime.create(1997, 8, 17, 9, 0, 0, false), + DateTime.create(1997, 8, 19, 9, 0, 0, false), + DateTime.create(1997, 8, 31, 9, 0, 0, false), + ]); + expect([...set]).toEqual(dates); + }); });