hebcal/hebcal-js

Get next month/year

atlanteh opened this issue · 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?

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

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

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)

Tested and this works:

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