fitnr / convertdate

Utils for converting between date formats and calculating holidays
MIT License
47 stars 26 forks source link

Hebrew Calendar should include method to return date where Tishrei is 1 #36

Open snoopyjc opened 3 years ago

snoopyjc commented 3 years ago

The first month of civil year is Tishrei, and that is also when the year changes, so please add another method to return that method of month counting (Tishrei=1). This is also consistent with the Jewish calendar in Excel.

Per Wikipedia:

Nowadays, the day most commonly referred to as the "New Year" is 1 Tishrei (Rosh Hashanah, lit. "head of the year"), even though Tishrei is the seventh month of the ecclesiastical year. 1 Tishrei is the civil new year, and the date on which the year number advances. Tishrei marks the end of one agricultural year and the beginning of another,[31] and thus 1 Tishrei is considered the new year for most agriculture-related commandments, including Shmita, Yovel, Maaser Rishon, Maaser Sheni, and Maaser Ani.

fitnr commented 3 years ago

Should be a relatively straight-forward addition

snoopyjc commented 3 years ago

Thanks!! Here is the mapping, which is different in Leap years:

    ecclesiastical_to_civil = {7: 1, 8: 2, 9: 3, 10: 4, 11: 5, 12: 6, 1: 7, 2: 8, 3: 9, 4: 10, 5: 11, 6: 12}
    ecclesiastical_leap_to_civil = {7: 1, 8: 2, 9: 3, 10: 4, 11: 5, 12: 6, 13: 7, 1: 8, 2: 9, 3: 10, 4: 11, 5: 12, 6: 13}
fitnr commented 3 years ago

Took me a second to figure out what this is. I think that the modulo operator (%) is more useful for this kind of thing than hard-coding a dictionary.

snoopyjc commented 3 years ago

Yes that will work too - just watch the leap years!

-joe Sent from my AT&T iPhone

On Oct 23, 2020, at 7:36 PM, Neil Freeman notifications@github.com wrote:

 Took me a second to figure out what this is. I think that the modulo operator (%) is more useful for this kind of thing than hard-coding a dictionary.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

fitnr commented 3 years ago

While this is easy to add mathematically, I'm going to spend a little more time figuring out the best way to handle it in a backward-compatible way in the existing function calls. I'll try to get it in the next release.

snoopyjc commented 3 years ago

How about: year, month, day = hebrew.from_gregorian(*ymd, civil=True)

fitnr commented 3 years ago

Yeah, that's probably the most straightforward way. There are several supporting functions, so the cleanest way to incorporate will probably involve some refactoring.

In the meantime, the hebrew.to_civil function added v2.3.0 should be useful