Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude date in RRule.js?

Suspected code:

<script src="https://jakubroztocil.github.io/rrule/dist/es5/rrule.min.js"></script>
// Create a rule:
        const rule = new rrule.RRule({
            freq: rrule.RRule.DAILY,
            dtstart: new Date('{{ date('Y-m-d', strtotime($product->details->date_from . ' -1 day'))}}'),
            until: new Date('{{$product->details->date_to_1 ? date('Y-m-d', strtotime($product->details->date_to_1 . ' +1 day'))  : date('Y-m-d', strtotime($product->details->date_to . ' +1 day'))}}'),
        });

        rule.exdate(new Date("2020-06-25"));

Console got that:

TypeError: rule.exdate is not a function

But if we follow the official guide RRule repo manual

We can observe the solution as :)

// Add a exclusion date to rruleSet
rruleSet.exdate(new Date(Date.UTC(2012, 5, 1, 10, 30)))

I'm unable to figured it out where am i wrong ?

Thanks in advance.

Regards,
Aizaz

like image 956
ForWebTech Avatar asked Sep 02 '25 16:09

ForWebTech


2 Answers

const rruleSet = new RRuleSet();
rruleSet.rrule(
  new RRule({
    freq: RRule.DAILY,
    count: 5,
    dtstart: new Date("Aug 2020 10 10:30 am"),
  })
);
rruleSet.exdate(new Date("Aug 2020 12 10:30 am"));

Here, it will exclude 12th Aug and gives back (10,11,13,14 of Aug).

like image 61
Kisore Avatar answered Sep 05 '25 04:09

Kisore


RRuleSet is a different object to RRule. You will find exdate on the RRuleSet object and not on the RRule.

  1. Create a RRuleSet
  2. Add add your RRule
  3. Add your exclusion on the RRuleSet
like image 20
Piotr Stulinski Avatar answered Sep 05 '25 06:09

Piotr Stulinski