simlist/pyluach

Not having the year,

Closed this issue · 6 comments

Thank you so much for such a wonderful package.

if I only have the month and day (Yahrzeit of Yusef Hasadik, which is today :) ), how would I calculate when it will be next year ?
I was thinking to

1: Assume it was this year,
Loop
2: if the date does not work try a year before
end of loop

so the birthdays will be correct, but yr is off.

Is this what you're looking for?

from pyluach. dates import HebrewDate

def next_yortzeit(yortzeit_month, yortzeit_day):
    today = HebrewDate.today()
    yortzeit = HebrewDate(today.year, yortzeit_month, yortzeit_day)
    if yortzeit >= today:
        return yortzeit
    else:
        return HebrewDate(today.year + 1, yortzeit_month, yortzeit_day)

So if the heb date is not valid, it will automatically correct it?? ..
like

today = HebrewDate.today()
for i in range(100):
    yortzeit = HebrewDate(today.year+i, 13, 5) #of course we not have Adar2 every year 

No it will not correct it automatically. It will throw a ValueError for a nonexistent date. I might add a method to add years or months to dates to a future version to deal with that, but for now you can either handle the exception or use hebrewcal.Year.leap and len(hebrewcal.Month).

Thank you :)
Assuming " 5th of Adar 2" as a birthday,
how am I supposed to list all Hebrew dates for the next 10 years?

For a specific case like that you can just do:

from pyluach.dates import HebrewDate
from pyluach.hebrewcal import Year

birthdays = [HebrewDate(5782 + i, Year(5782 + i).monthscount(), 5) for i in range(1, 11)]

To generalize though you'd have to handle which Adar you want a regular Adar to become in a leap year, and if you want to round forward or back when the start date is the 30th and the end month is only 29 days.

v2.1.0 now has HebrewDate.add() and HebrewDate.subtract() methods to add or subtract years months and days.