Skip to content

fix: rrule.all() hangs with odd byhour and even interval#622

Open
huaichaow wants to merge 1 commit intojkbrzt:masterfrom
huaichaow:master
Open

fix: rrule.all() hangs with odd byhour and even interval#622
huaichaow wants to merge 1 commit intojkbrzt:masterfrom
huaichaow:master

Conversation

@huaichaow
Copy link

@huaichaow huaichaow commented Mar 26, 2024

the below code hangs:

const rrule = new RRule({
  freq: Frequency.HOURLY,
  interval: 2,
  byhour: [1]
})

console.log(rrule.all())

the root cause:

the 'DateTime.addHours()' function creates an infinite loop when hours is even and byhour contains only odd numbers, because includes(byhour, this.hour) is always falsy.
the same goes for 'addMinutes' and 'addSeconds'.

public addHours(
    hours: number,
    filtered: boolean,
    byhour: number[]
  ) {
   ...
    for (;;) {
      this.hour += hours
     ...

      if (empty(byhour) || includes(byhour, this.hour)) break
    }
  }

should fix this issue: #468

Thanks for contributing to rrule!

To submit a pull request, please verify that you have done the following:

  • Merged in or rebased on the latest master commit
  • Linked to an existing bug or issue describing the bug or feature you're
    addressing
  • Written one or more tests showing that your change works as advertised

@huaichaow huaichaow changed the title fix: DateTime.add() hangs when interval generates sequences never overlap byhour fix: rrule.all() hangs with odd byhour and even interval Mar 26, 2024
@huaichaow
Copy link
Author

@david-golightly-leapyear

this is a critical bug that easily leads to an infinite loop, could we prioritize this PR?

thank you!

@ggaabe
Copy link

ggaabe commented Jul 15, 2025

Hi, this library isn't maintained anymore. A new one has been built following the original maintainer's suggestions, with the full RFC 5545 implementation:

https://github.com/ggaabe/rrule-temporal

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants