bunkat / later

A javascript library for defining recurring schedules and calculating future (or past) occurrences for them. Includes support for using English phrases and Cron schedules. Works in Node and in the browser.
http://bunkat.github.io/later/
MIT License
2.42k stars 245 forks source link

Every 3 and 6 Months Recurrence on later.js stating from a particular date #232

Open aravind2base opened 6 years ago

aravind2base commented 6 years ago

I am trying to create recurrence every 3 and 6 months using the later.js(https://github.com/bunkat/later).

This is my code

// My value.scheduled_date is 2018-09-06
var d = new Date(value.scheduled_date);
var day = d.getDate();
// month count will be -1 as it starts from 0
var month = d.getMonth();
var year = d.getFullYear();
var recurSched = later.parse.recur().on(day).dayOfMonth().every(3).month();
var schedules = later.schedule(recurSched).next(5);
console.log(schedules)

This gives 3 months recurrence starting from the current month, but I want the recurrence to start from the scheduled_date. When I add starting On to the code

var recurSched = later.parse.recur().on(day).dayOfMonth().every(3).month().startingOn(month + 1);
var schedules = later.schedule(recurSched).next(5);
console.log(schedules)

Recurrence is staring only after that month for every year. I want recurrence to start from a particular date so that the recurrence of other years won't be affected.

The same is the case with my 6 months code

var recurSched = later.parse.recur().on(day).dayOfMonth().every(6).month().startingOn(month+1);
var schedules = later.schedule(recurSched).next(5);
console.log(schedules);