Skip to content

Bug in BYSETPOS #960

Description

@woldaker

This is regarding the latest tagged release v2.2.1, which is the same as is currently being used (as of writing this, on 2026-02-08) on your tester tool page https://kewisch.github.io/ical.js/recur-tester.html.

I cannot get any BYSETPOS values to work.

The use case I ran into this with was in trying to create a recurrence rule which effectively meant "Give me the Nth day of each month, or the last day of that month if there are less than N days in that month."

The correct answer to this (for values of N >= 28 anyway, done for brevity's sake in this example), at least according to how I understand the iCalendar/RFC5545 standard, is:
RRULE:FREQ=MONTHLY;BYMONTHDAY={28..N};BYSETPOS=-1
where the {28..N} is meant to say "the list of numbers from 28 to N"

So if you wanted the 30 day of the month, or the last day of the month for months that don't have that many days, it would be:
RRULE:FREQ=MONTHLY;BYMONTHDAY=28,29,30;BYSETPOS=-1

but I was puzzled by what I saw in the results:

Image

As you can see, yes it did produce the correct result, but it was mixed in with invalid results as well. I thought at first I had my logic in constructing the RRULE string wrong, but I've double and triple-checked; it's right. (I checked with other implementations which validate this).

What I've come to realize is that it appears as though the BYSETPOS portion of the rule is simply ignored completely. Look at those results again and think what would happen if that BYSETPOS simply wasn't there... then the results would be 100% correct.

I verified this by giving it a simpler test (notice I changed the start and end dates to be New Year's at midnight to make it as simple as possible to reason about):

Image

And again, it appears as if the BYSETPOS portion of the RRULE is just completely ignored.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions