Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RRule not setting correct time if dtstart is set

Tags:

reactjs

rrule

I try to make an rrule instance and then set the start date/time (dtstart) but the events get the wrong time.

  1. I initialize a rrule instance with a basis rrule string: RRULE:FREQ=WEEKLY;INTERVAL=1;WKST=MO;COUNT=20
  2. I set the dtstart date in the rrule.options like so: rrule.options.dtstart = new Date(Date.UTC(2019, 1, 4, 12, 30, 0))
  3. I console.log rrule.all() to see the generated events. All events now have the current time instead of the time set via dtstart. It should show 12:30 instead

I made this sandbox demonstrating the problem.

Now, when I do exactly the same in rrule.js demo page, I get correct results. On this demo page, do the following to see what I mean: enter image description here

These are the results:

enter image description here

As you can see, time of the events is set correctly!

Any advice appreciated!

like image 358
Dany Dhondt Avatar asked Nov 18 '25 04:11

Dany Dhondt


1 Answers

Found the answer:

If you set distart explicitly in the constructor, then the problem is solved.

Compare these examples:

Example one: gives correct results:

const rrule = new RRule({
  freq: RRule.WEEKLY, 
  interval: 1, 
  wkst: RRule.MO, 
  count: 20,
  dtstart: new Date(Date.UTC(2019, 1, 4, 12, 30, 0))})

Example two: gives wrong results

const rrule = new RRule({
  freq: RRule.WEEKLY, 
  interval: 1, 
  wkst: RRule.MO, 
  count: 20})
rrule.options.dtstart = new Date(Date.UTC(2019, 1, 4, 14, 30, 0));

To me, this looks a bit counter intuitive because setting dtstart should always give the same result whether you set it in the constructor or set it afterwards.

like image 143
Dany Dhondt Avatar answered Nov 21 '25 09:11

Dany Dhondt