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 507 forks source link

`before` should return previous timestamp #576

Open denbon05 opened 1 year ago

denbon05 commented 1 year ago

Reporting an issue

Should exist ability to take previous timestamp.

 const { rrulestr } = require('rrule')

const rruleStr = `DTSTART:20230227T125217Z\nRRULE:FREQ=MINUTELY;INTERVAL=10`
const r = rrulestr(rruleStr);
const nextTime = new Date('2023-02-27T12:52:17.000Z')

console.log({ nextTime }) // { nextTime: '2023-02-27T12:52:17.000Z' }

console.log('previousTime', r.before(nextTime)) // previousTime null
// expected '2023-02-27T12:42:17.000Z'
console.log('previousTime', r.before(nextTime, true)) // previousTime 2023-02-27T12:52:17.000Z
jecsham commented 1 year ago

The before() method returns the previous occurrence of a recurring event based on the specified date. In your case, r.before(nextTime) returned null because nextTime was the same as the first occurrence of the event.