Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RRule is missing next occurrence #621

Open
synappsysai opened this issue Mar 21, 2024 · 1 comment
Open

RRule is missing next occurrence #621

synappsysai opened this issue Mar 21, 2024 · 1 comment

Comments

@synappsysai
Copy link

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
Copy link

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

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

No branches or pull requests

2 participants