Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get next month/year #65

Open
atlanteh opened this issue May 30, 2019 · 4 comments
Open

Get next month/year #65

atlanteh opened this issue May 30, 2019 · 4 comments

Comments

@atlanteh
Copy link

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?

@Scimonster
Copy link
Contributor

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

@atlanteh
Copy link
Author

atlanteh commented Nov 4, 2019

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

@MDjavaheri
Copy link

MDjavaheri commented Jun 26, 2020

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)

@mjradwin
Copy link
Member

Tested and this works:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants