moment-recur
moment-recur copied to clipboard
recurrence.next(1) hangs
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 #
I guess it is not possible to have compound intervals.
// It is NOT possible to create compound intervals. The following will never match.
Just hit this bug also! Such a pain in the neck.
Rolling back to version 1.0.5 it works fine
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
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.
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.
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.
Any response to this? It works perfectly in 1.0.5 but crashes javascript 1.0.7
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;
}
@Hyperblaster thanks! I've rollback to version 1.0.5 and works perfectly.