rrule icon indicating copy to clipboard operation
rrule copied to clipboard

RRule is missing next occurrence

Open synappsysai opened this issue 11 months ago • 1 comments

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

synappsysai avatar Mar 21 '24 16:03 synappsysai

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 :'(

mmarcoux09 avatar Apr 11 '24 22:04 mmarcoux09