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

recurrence.next(1) hangs #89

Open
zhex900 opened this issue Mar 1, 2018 · 9 comments
Open

recurrence.next(1) hangs #89

zhex900 opened this issue Mar 1, 2018 · 9 comments

Comments

@zhex900
Copy link

zhex900 commented Mar 1, 2018

Hi,

var start = moment("01/01/2018", "MM/DD/YYYY");
var end = moment("12/06/2018", "MM/DD/YYYY");

var recurrence = moment().recur( start, end ).every(["Tuesday"]).daysOfWeek().every(3).weeks();

console.log('d');
if (typeof recurrence !== 'undefined' ){
    console.log('defined');
   console.log( recurrence.next(1) );
}else{
    console.log( 'nothing');
}

This script hangs the browser. Is there a bug?

Jake He #

@zhex900
Copy link
Author

zhex900 commented Mar 1, 2018

I guess it is not possible to have compound intervals.

// It is NOT possible to create compound intervals. The following will never match.

@Hyperblaster
Copy link

Hyperblaster commented Mar 8, 2018

Just hit this bug also! Such a pain in the neck.

Rolling back to version 1.0.5 it works fine

@jefbarn
Copy link

jefbarn commented Apr 8, 2018

You are starting your recurrence on a Monday and asking for every 3 weeks, which will always be a Monday, but then also saying to only match Tuesdays, so it will never match anything.
Try starting from 01/02/2018

@Hyperblaster
Copy link

Wouldn’t the expected behaviour be to throw an error? Currently it freezes the entite process or crashes the browser.

In version 1.0.5 it works perfectly.

@jefbarn
Copy link

jefbarn commented Apr 8, 2018

I think expected result would be to return an empty array (nothing matches this query).
The reason it never returns is the code is busy looking for a date that will match these conditions that doesn't exist and will try all dates until the end date.

@Hyperblaster
Copy link

Hyperblaster commented Apr 8, 2018 via email

@Hyperblaster
Copy link

Any response to this? It works perfectly in 1.0.5 but crashes javascript 1.0.7

@YaoHuiJi
Copy link

YaoHuiJi commented Jul 12, 2018

I find that the recur.maches function works perfectly ,so I use my own next function to solve this issue temporary, maybe it's helpful for someone, you can change the function to return an array if you need

    function next(start, end, recur) {
        let result = null, cur = start;

        while (cur < end) {

            if (recur.matches(cur)) {
                result = cur;
                break;
            }

            cur.add(1, 'day');
        }

        return result;
    }

@joaom182
Copy link

joaom182 commented Jul 21, 2018

@Hyperblaster thanks! I've rollback to version 1.0.5 and works perfectly.

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

5 participants