hebcal-js icon indicating copy to clipboard operation
hebcal-js copied to clipboard

Get next month/year

Open atlanteh opened this issue 5 years ago • 4 comments

Is there any easy way to get next month/year? Let say I have an HDate and I want to add 3 months. How would I do that?

atlanteh avatar May 30 '19 08:05 atlanteh

Untested: var date = new Hebcal.HDate(); date.setMonth(date.getMonth() + 3);

Scimonster avatar Jun 18 '19 08:06 Scimonster

This doesn't work in case you want to add 1 month, you are in Adar and it's not leap year. In this case it reverts it back to Adar

atlanteh avatar Nov 04 '19 22:11 atlanteh

let currentYear = ... ;
const increment = 1
let [d, m, y] = [currentYear.day, currentYear.month, currentYear.year]; 
let nextMonth = new Hebcal.HDate(d, m + increment, y)
let nextYear = new Hebcal.HDate(d, m, y + increment)

MDjavaheri avatar Jun 26 '20 15:06 MDjavaheri

Tested and this works:

let hd = new Hebcal.HDate();
for (let i = 0; i < 3; i++) {
  hd = new Hebcal.HDate(hd.abs() + hd.daysInMonth());
}

mjradwin avatar Jun 28 '20 14:06 mjradwin