jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.

Home Page:https://jkbrzt.github.io/rrule

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`before` should return previous timestamp

denbon05 opened this issue · comments

Reporting an issue

  • Verify that you've looked through existing issues for duplicates before
    creating a new one
  • Code sample reproducing the issue. Be sure to include all input values you
    are using such as the exact RRule string and dates.
  • Expected output
  • Actual output
  • The version of rrule you are using
  • Your operating system
  • Your local timezone (run $ date from the command line
    of the machine showing the bug)
  • "rrule": "^2.6.9"
  • Ubuntu 20.04
  • Mon 3 Apr 12:01:05 CEST 2023

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

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.