javascript - How to exclude date in RRule.js? - Stack Overflow

Suspected code:<script src=".min.js"><script> Create a rule:const rule = new

Suspected code:

<script src=".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

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

Share Improve this question asked Jun 23, 2020 at 11:07 ForWebTechForWebTech 1402 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2
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).

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

The EXDATE prop will only work in RRuleSet. So, after including rrule.js script, you can exclude a single date or multiple dates like this:

const RRuleSet = rrule.RRuleSet;
const rruleSet = new RRuleSet();

rruleSet.rrule(
  new RRule({
    freq: RRule.DAILY,
    count: 5,
    dtstart: new Date("2022-04-15"),
  })
);

rruleSet.exdate(new Date("2022-04-25"));

// Again add 'exdate()' to exclude another date
rruleSet.exdate(new Date("2022-04-28"));

After that, convert rruleSet into string using toString()

let rruleStr = rruleSet.toString();

So, to check recurrence you should first convert rruleStr string to object using rrulestr() and than iterate rule using all(), before(), after() or between() retrival methods:

let ruleSetObj = rrule.rrulestr(rruleStr);
let ruleNextOccurrence = ruleSetObj.after(new Date('2022-04-25'), true);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745458280a4628588.html

相关推荐

  • javascript - How to exclude date in RRule.js? - Stack Overflow

    Suspected code:<script src=".min.js"><script> Create a rule:const rule = new

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信