最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

dart - How to add months to a JewishDate with kosher_dart - Stack Overflow

programmeradmin1浏览0评论

I'm using kosher_dart with JewishDate and JewishCalendar.

I want to add days, months and years to my JewishDate.

Adding days works Fine - I convert the JewishDate into DateTime, add days, and convert it back. Adding years also works – I just use jewishDate.setJewishDate(jewishYear + years, jewishMonth, jewishDayOfMonth).

But I'm stuck on adding months.

Since the Jewish calendar has both 12-month and 13-month years (leap years), simply adding months can result in invalid dates, especially if the target month doesn't exist in a non-leap year (e.g., Adar II).

I want to add months efficiently, in O(1) time – without using loops or checking year-by-year.

Is there a reliable way to calculate the resulting Jewish date after adding a number of months, while properly handling leap years and varying month lengths?

I'm using kosher_dart with JewishDate and JewishCalendar.

I want to add days, months and years to my JewishDate.

Adding days works Fine - I convert the JewishDate into DateTime, add days, and convert it back. Adding years also works – I just use jewishDate.setJewishDate(jewishYear + years, jewishMonth, jewishDayOfMonth).

But I'm stuck on adding months.

Since the Jewish calendar has both 12-month and 13-month years (leap years), simply adding months can result in invalid dates, especially if the target month doesn't exist in a non-leap year (e.g., Adar II).

I want to add months efficiently, in O(1) time – without using loops or checking year-by-year.

Is there a reliable way to calculate the resulting Jewish date after adding a number of months, while properly handling leap years and varying month lengths?

Share Improve this question asked 22 hours ago נתן אנטרנתן אנטר 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Being unfamiliar with the Jewish calendar, I apologize if I miss something, but it would seem like the intended way to offset a JewishDate is by using the forward method:

JewishDate date = JewishDate();
date.forward(Calendar.MONTH, 1);

Note that this edits the date in-place. If you want to get a new instance, you will have to use the clone method, then call forward on the clone:

JewishDate today = JewishDate();
JewishDate nextMonth = date.clone()..forward(Calendar.MONTH, 1);
发布评论

评论列表(0)

  1. 暂无评论