rrule icon indicating copy to clipboard operation
rrule copied to clipboard

EXDATE not working if used together with RRULE in set

Open pasevin opened this issue 5 years ago • 9 comments

Hi, i've spent hours trying to figure out what am I doing wrong, but it looks like there's an issue with the library itself.

Bellow you can see my code snippet. A few things to have in mind:

  • i tried to generate RRuleSet manually (same thing):
set.exdate(new Date(Date.UTC(2019, 5, 20, 0, 0)));
  • when i drop RRULE and instead use multiple RDATE, then EXDATE works!

My snippet:

const str = 'RRULE:FREQ=DAILY;UNTIL=20200630T000000\nEXDATE:20190619T000000'
const set: RRuleSet = rrulestr(str) as RRuleSet;
const rdates = set.all();
console.log(rdates);

Expected output:

Every single day except 2019-06-19

Actual output:

Every single day, with no exclusion...

Version of rrule:

2.6.0

Operatin system:

Mac OS

Local Timezone:

PDT

pasevin avatar Jun 07 '19 08:06 pasevin

Im having issues with trying to pass EXDATE in a rule. I just get Error: Unknown RRULE property 'EXDATE' This also happens on the demo when using the string input

DeanOutlaw avatar Jun 14 '19 12:06 DeanOutlaw

@DeanOutlaw This is because EXDATE is not an RRULE property. It is a top-level property (alongside, not nested under, RRULE). For example:

DTSTART:20190101T120000Z
RRULE:FREQ=WEEKLY
EXDATE:20190108T120000Z

davidgoli avatar Jul 02 '19 22:07 davidgoli

Yeah, this is not the same issue I have @DeanOutlaw @davidgoli

pasevin avatar Jul 05 '19 23:07 pasevin

Hi, interestingly if we use .all method before using EXDATE the exclusions don't work. I'm not sure whether the library is using some catching mechanism to catch the result of .all operation.

ashishhrt avatar Jul 26 '19 10:07 ashishhrt

@DeanOutlaw This is because EXDATE is not an RRULE property. It is a top-level property (alongside, not nested under, RRULE). For example:

DTSTART:20190101T120000Z
RRULE:FREQ=WEEKLY
EXDATE:20190108T120000Z

How do I add an exdate then? dtstart is an rrule property on the rrule object. I do not want to use an rrule set - I should be able to do this just with toString() and fromString()

stclairdaniel avatar Aug 30 '19 18:08 stclairdaniel

@stclairdaniel rrulejs is largely based on the iCal spec. dtstart is an rrule property out of necessity. Many rrules can only be interpreted in the context of their dtstart.

For example,

DTSTART:20190101T120000Z
RRULE:FREQ=WEEKLY

What day of the week are occurrences on? The dtstart tells you.

In contrast, EXDATE does not affect the RRULE, it affects the VEVENT object. Technically, a VEVENT can have multiple RRULEs associated with it. The occurrences associated with the VEVENT are the distinct union of all the occurrences produced by its RRULEs, minus the occurrences produced by the EXRULEs, plus the RDATEs, minus the EXDATEs. In rrulejs, RRuleSet approximates the VEVENT recurrence logic.

I should be able to do this just with toString() and fromString()

Try the rrulestr function on your ical fragment. You should get back an RRuleSet object.

const str = `DTSTART:20190101T120000Z
RRULE:FREQ=WEEKLY
EXDATE:20190108T120000Z`;

const rruleset = rrulestr(str);

I do not want to use an rrule set

¯_(ツ)_/¯

jorroll avatar Aug 31 '19 05:08 jorroll

I'm not sure if this is related but we seem to be having problems with exdate on OSX specifically. On windows and our linux environment there are no problems but on OSX we get rules.exdate is not a function

mortocks avatar Dec 04 '20 05:12 mortocks

use second RRuleSet() and get the difference.

 const tempRule = {
   freq: RRule.WEEKLY,
   byweekday: [RRule.MO, RRule.FR],
   dtstart: new Date(2021, 1, 1, 10, 30),
   until: new Date(2021, 2, 2, 14, 30),
 };

 const tempExRule = new RRule({
   freq: RRule.WEEKLY,
   byweekday: [RRule.MO],
   dtstart: new Date(2021, 1, 8, 10, 30),
   until: new Date(2021, 1, 26, 14, 30),
 });

 const rule = new RRule(tempRule);
 const ruleSet = new RRuleSet();
 ruleSet.rrule(rule);
 
 const exRule = new RRule(tempExRule);
 const exRuleSet = new RRuleSet();
 exRuleSet.rrule(tempExRule);
 
 let arr1 = ruleSet.all().map((x) => JSON.stringify(x));
 let arr2 = exRuleSet.all().map((x) => JSON.stringify(x))

 let difference = arr1.filter((x) => !arr2.includes(x));
 difference = difference.map((x) => new Date(x.slice(1, -1)));
 
 console.log(difference)

DanielBarbakadze avatar Feb 10 '21 20:02 DanielBarbakadze

I'm not sure if this is related but we seem to be having problems with exdate on OSX specifically. On windows and our linux environment there are no problems but on OSX we get rules.exdate is not a function

I am still getting this same error. In the js code I can see there is reference to exdate but when I use it in the tule string I receive the error listed above.

jaredgibb avatar May 08 '21 12:05 jaredgibb