moment-recur icon indicating copy to clipboard operation
moment-recur copied to clipboard

recurrence.next(1) hangs

Open zhex900 opened this issue 6 years ago • 9 comments

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 avatar Mar 01 '18 02:03 zhex900

I guess it is not possible to have compound intervals.

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

zhex900 avatar Mar 01 '18 02:03 zhex900

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

Rolling back to version 1.0.5 it works fine

Hyperblaster avatar Mar 08 '18 04:03 Hyperblaster

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

jefbarn avatar Apr 08 '18 17:04 jefbarn

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.

Hyperblaster avatar Apr 08 '18 20:04 Hyperblaster

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.

jefbarn avatar Apr 08 '18 20:04 jefbarn

That makes sense. What is different between 1.0.5 and current version?

On 9 Apr 2018, at 6:18 am, Jeff Barnes [email protected] wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Hyperblaster avatar Apr 08 '18 20:04 Hyperblaster

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

Hyperblaster avatar Apr 23 '18 05:04 Hyperblaster

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;
    }

YaoHuiJi avatar Jul 12 '18 10:07 YaoHuiJi

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

joaom182 avatar Jul 21 '18 22:07 joaom182