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.24k stars 506 forks source link

RRule is missing next occurrence #621

Open synappsysai opened 3 months ago

synappsysai commented 3 months ago

Reporting an issue

I have an RRule setup to daily recurrence, but somehow when getting the next occurrence it skips the correct one and gives me the one after. My code sample is here

const { RRule } = require("rrule");
const { DateTime } = require("luxon");

function getRrule() {
    rruleObject = null;

    rruleObject = {
                "_cache": {
                    "all": false,
                    "after": [],
                    "before": [],
                    "between": []
                },
                "options": {
                    "freq": 3,
                    "tzid": null,
                    "wkst": 0,
                    "count": 15,
                    "byhour": [
                        19
                    ],
                    "bymonth": null,
                    "dtstart": "2024-03-08T23:50:59.000Z", 
                    "byeaster": null,
                    "byminute": [
                        50
                    ],
                    "bysecond": [
                        59
                    ],
                    "bysetpos": null,
                    "byweekno": null,
                    "interval": 1,
                    "byweekday": null,
                    "byyearday": null,
                    "bymonthday": [],
                    "bynweekday": null,
                    "bynmonthday": []
                },
                "origOptions": {
                    "freq": 3,
                    "count": 15,
                    "dtstart": "2024-03-08T23:50:59.000Z",
                    "interval": 1
                }
            };

    console.log("start date raw: ", new Date(rruleObject.options.dtstart));

    rruleObject.options.dtstart = DateTime.fromISO(rruleObject.options.dtstart).toUTC().toJSDate();

    console.log("start date from Luxon: ", rruleObject.options.dtstart);

    const rrule = new RRule(rruleObject.options);

    const currentDate = DateTime.fromJSDate(new Date())
                                .toUTC()
                                .setZone('local', { keepLocalTime: true })
                                .toJSDate();
    console.log("current date from Luxon: ", currentDate);
    console.log("current date from JS: ", new Date());

    nextOccurrence = rrule.after(currentDate);
    return nextOccurrence;
}

 function main() {
    const nextOccurrence =  getRrule();

    const s = DateTime.fromJSDate(nextOccurrence)
                                .toUTC()
                                .setZone('local', { keepLocalTime: true })
                                .toJSDate();
    console.log("Next Occurrence raw: ",nextOccurrence);
    console.log("Next Occurrence from Luxon: ",s);

}

main();

Expected Next occurrence should be March 20 at 23:50

Actual Occurrence is coming as March 21

RRule version 2.8.1

OS Macos

Timezone EDT

mmarcoux09 commented 3 months ago

You have the same issue as I do, RRule seems to convert the EDT to UTC, therefore your next occurence is March 21st 03:50 instead of March 20th... I cannot find a solution to this :'(