dmfs/lib-recur

How to deal with different month lengths?

Lueton opened this issue · 4 comments

Hi! First of thanks for this awesome lib!

I was wondering how to deal with different month lengths.
Here's an example:
An event with the start date 2022-10-31 (YYYY-MM-DD) with the frequency "MONTHLY".

dtstart: 20221031T000000
rrule: FREQ=MONTHLY;
max_instances: 10

Result:

["20221031T000000","20221231T000000","20230131T000000","20230331T000000","20230531T000000","20230731T000000","20230831T000000","20231031T000000","20231231T000000","20240131T000000"]

You realize that the event is not repeated every month (e.g. not January), because not every month has 31 days.

What is the best way to deal with something like this, if you want to determine the instances? The event should somehow still be included in every month and for example corrected to the last day of the month.

Thanks for any advise :)

I think you have to use another rule for this case.
For Example:
FREQ=MONTHLY;COUNT=30;INTERVAL=1;WKST=MO;BYMONTHDAY=-1

ByMonthDay -1 means the last day of the month.

I think you have to use another rule for this case.

For Example:

FREQ=MONTHLY;COUNT=30;INTERVAL=1;WKST=MO;BYMONTHDAY=-1

ByMonthDay -1 means the last day of the month.

Ah that makes sense, thank you!

dmfs commented

Depending in your use case and environment (if all components support RFC7529) you might also use this rule

RSCALE=GREGORIAN;SKIP=BACKWARD;FREQ=MONTHLY;COUNT=30

When you provide a valid RSCALE you can use SKIP=BACKWARD to use the last valid day when an occurrence falls on an invalid day.

Depending in your use case and environment (if all components support RFC7529) you might also use this rule

RSCALE=GREGORIAN;SKIP=BACKWARD;FREQ=MONTHLY;COUNT=30

When you provide a valid RSCALE you can use SKIP=BACKWARD to use the last valid day when an occurrence falls on an invalid day.

Oh thanks, that sounds even better!