Home > Back-end >  Find nth week recurrence on week days with moment js
Find nth week recurrence on week days with moment js

Time:05-16

I have just started moment js, I'm trying to generate recurrence for every nth week for defined week days

I have tried this code so far but not getting True for defined week days

// Create a date to start from
let date = moment(new Date("05-12-2022"));

let rInterval = moment(date).recur().every(["Saturday"]).daysOfWeek().every(2).week();

console.log(rInterval.matches(new Date("05-21-2022"))) //saturday at 21 may

output: false

but as of now that week() function matches exactly 2 week

EXPECTED OUTPUT: TRUE

This should match Saturday in every 2 weeks from the start date

CodePudding user response:

This will work perfectly

moment('05-14-2022', 'MM-DD-YYYY').recur().every(2).day().every([5]).daysOfWeek();

Now it is recurring for every 2 weeks on Saturday from the start date.

  • Related