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

Add count to between functionality #491

Open
MosheLOptimove opened this issue Nov 17, 2021 · 0 comments
Open

Add count to between functionality #491

MosheLOptimove opened this issue Nov 17, 2021 · 0 comments

Comments

@MosheLOptimove
Copy link

Hi,

I would like to recommend adding a count parameter to the "Between" functionality. This functionality exists in the Python version and is quite useful here.

I've seen it while trying to check if today is in the recurrence. The standard way to do that is using "after", testing for null and then checking it happens today:

function isDayInRole(roleSettings, timestamp) {
    const startOfDay = moment(timestamp).startOf('day');
    const rule = new RRule(roleSettings);
    const next = rule.after(start);
    return next && moment(next).isSame(startOfDay, 'day');
}

Which prevent the simple one-liner of the logic (the last two lines).

A second approach is to use Between and see we got results:

function isDayInRole(roleSettings, timestamp) {
    const startOfDay = moment(timestamp).startOf('day');
    const endOfDay = moment(timestamp).endOf('day');
    const rule = new RRule(roleSettings);
    return rule.between(startOfDay, endOfDay).length > 0;
}

But this can take a long time since it runs on all occurrences (think of minutely).

Given the option of count can help these kind of test as between(after,before,count=1) will act as isBetween functionality withouth the overhead of converting/running a long loop.
On the same note, isBetween will also help me with my need, but count can also help the issue of infinite loop I've seen:
#481

Thanks,
Moshe

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

1 participant