3

I have a web project where I need a function either server-side using php or client-side using javascript where I can pass in a Georgian date and have month(s) or years added to it according to the Hebrew calendar, and return a Julian date.

for example the date 12/8/2014 which is 15 Kislev when adding a month it should return 1/7/2014 which is the Hebrew date of 15 Tevet instead of 1/8/2014 which is returned by regular date add functions which is actually 16 Tevet.

I've searched around and couldn't find anything, Hebcal doesn't seem to have any of these params.

4

Check out my hebcal-js library, the perfect thing you need for this. Include it, and then you can use one of the following snippets:

This is only if you will never have dates in Elul (due to a bug):

var hebDate = new Hebcal.HDate(new Date(2014, 11 /* meaning 12 */, 8));
hebDate.setMonth(hebDate.getMonth() + 1);
var gregDate = hebDate.greg(); // a javascript Date object

This will work for any date:

var hebDate = new Hebcal.HDate(new Date(2014, 11 /* meaning 12 */, 8));
var gregDate = hebDate.getMonthObject().next().getDay(hebDate.getDate()).greg(); // a javascript Date object
  • Nice library. But don't you still need to account for wrapping years like I did in my answer? – yydl Dec 8 '14 at 6:39
  • Nope! Comes built in. – Scimonster Dec 8 '14 at 6:45
  • So how does the library know if I want Tishri of this year or the next? – yydl Dec 8 '14 at 6:54
  • It goes by Nisan as the first month, actually, so i'll assume you mean that. A month of 1 is Nisan this year, a month of 13 is Nisan next year. 25 is two years from now, etc. – Scimonster Dec 8 '14 at 6:57
  • My code also assumes that Nisan == 1. The problem is that the year doesn't start at 1, it starts at 7. So if we take (y/m/d) 5773/6/1 and add 1 we get 5773/7/1. Which is not correct! It should be 5774/7/1. Does your code handle this? – yydl Dec 8 '14 at 7:03
1

Looking at your example, you can simply take advantage of the date conversion functions built into whichever library you are using. So if you want to add a Hebrew month to a Julian date, you can:

  1. Convert the Julian date into a Hebrew date (i.e. Hebrew Year / Month / Day)
  2. Take the Hebrew month value and add 1. Just keep in mind that if you are in Elul and add 1, you end up in Tishrei of the next year (the year wraps). Also, only allow it to go to Adar Sheini if it is a Hebrew leap year (once again, your library should be able to tell you if it is)
  3. Now use a function to convert this new Hebrew date (made up of y/m/d) back into Julian

Here's some pseudo-ish code (not tested):

function addAHebrewMonth(julianDate):
    hebrew_year, hebrew_month, hebrew_day = julianToHebrew(julianDate)
    hebrew_month += 1
    if hebrew_month == 7: //Tishrei wrap
        hebrew_year += 1

    //Adar II (this will depend on how your library deals with leap years...)
    if hebrew_month == 13 and not isHebrewLeapYear(hebrew_year):
        hebrew_month = 1 //wrap back to Nisan

    return hebrewToJulian(hebrew_year, hebrew_month, hebrew_day)

Voila!

  • Of course, because converting Hebrew and Julian dates are so simple. – Scimonster Dec 8 '14 at 6:27
  • @Scimonster Is that sarcasm I detect? – yydl Dec 8 '14 at 6:40
  • Yes it is. ;) I know how much code it was to do that (my answer). – Scimonster Dec 8 '14 at 6:45
  • @Scimonster My answer is assuming he has such functions (his question seemed to be emphasizing the need to calculate time differences as opposed to the actual conversion. I therefore assumed he already had such functions). – yydl Dec 8 '14 at 6:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .