jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
https://jkbrzt.github.io/rrule
Other
3.27k stars 506 forks source link

rrule do not handle day not existent in the next month in monthly frequency #569

Closed daniloab closed 1 year ago

daniloab commented 1 year ago

Hi, there. I have a simple script that:

I expect the return for the next months, even if a day does not exist in the next month, to be 4 dates.

But, when the start date is at the end of the month, I have some problems.

With this script, I identified that if the start day not existing in the next month the rrule ignores it.

Is there a way to handle this? some config?

(() => {
  const dateStart = moment(new Date('2023-01-31'))
    .startOf('day')
    .toDate();
  const dateEnd = moment(dateStart)
    .add(4, 'month')
    .endOf('day')
    .toDate();

  console.log({ dateStart, dateEnd });

  const rule = new RRule({
    freq: RRule.MONTHLY,
    dtstart: dateStart,
    until: dateEnd,
  });

  console.log(rule.all());
})() 

the date start and date end generated:

{
  dateStart: 2023-01-30T03:00:00.000Z,
  dateEnd: 2023-05-31T02:59:59.999Z
}

Expected output

The expected output is an array of four dates from January to april

[
  2023-01-30T03:00:00.000Z,
  2023-02-28T03:00:00.000Z,
  2023-03-30T03:00:00.000Z,
  2023-04-30T03:00:00.000Z
]

Actual output

Today, is ignoring February and adding may

[
  2023-01-30T03:00:00.000Z,
  2023-03-30T03:00:00.000Z,
  2023-04-30T03:00:00.000Z,
  2023-05-30T03:00:00.000Z
]

The version of rrule you are using

2.7.2

Your operating system

macos

Your local timezone (run $ date from the command line of the machine showing the bug)

Tue Feb 28 19:45:48 -03 2023

daniloab commented 1 year ago

Looks like passing bymonthday: -1 solves this problem