mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
I am looking for a jewish calendar mirc script that would post in my chatroom the hebrew date, the readings for that day/week and the holidays .... see Hebcal.com for other information.

I do have a Javascript that is as follows:

This code demonstrates how to convert a Hebrew date into a
' Gregorian date. The code is written in VB6/VBA, but I purposely
' used very generic features so it would be easy to translate
' this into other languages. Also, I avoided using many
' optimization in order to make the logic clearer.

' These functions assume that all the current rules of the
' Hebrew calendar were always in existence (which is not true
' since the Hebrew calendar was not always fixed) and all the
' current rules of the Gregorian calendar were always in existence
' (which is not true).

' Here is a very brief description of the Hebrew calendar.
'
' The Hebrew calendar is a lunisolar calendar. This means that
' the months are in sync with the moon and the years stay in sync
' with the sun. A solar year is approximately 365.25 days. A
' lunar month is approximately 29.5 days. Twelve lunar months is
' approximately 354 days (12 * 29.5=354). Thus, a lunar year of
' twelve months is 11.25 days shorter than the solar year. To make
' up for this shortfall, the Hebrew calendar adds a thirteenth
' month to seven years over a nineteen year period. Therefore, over
' a nineteen year period, the Hebrew calendar is approximately the
' same length as a nineteen year solar calendar.
'
' In order to understand this code, you must know the following
' terms:
' Molad - new moon. Hebrew months start around the day of the
' new moon
' Chalakim - 1 / 1080 of an hour or 3 1/3 seconds
' Tishrei - the first month of the Hebrew year (at least for
' these calculations)
' Rosh Hashanah - The Jewish new year which starts on Tishrei 1.
'
' The Hebrew calendar assumes the period of time between one new
' moon to the next is 29 days, 12 hours and 793 chalakim. The first
' molad after creation occurred on Monday, September, 7th -3760 at 5
' hours and 204 chalakim. Technically, the Gregorian date would be
' in the year 3761 BCE because there was no year 0 in the Gregorian
' calendar, but we will use the year of -3760.

' Sample Usage:
' ' Converts AdarB/7/5765 to 4/6/2005
' MsgBox(HebToGreg(5765, 7, 26))
'

' This function returns how many months there has been from the
' first Molad until the beginning of the year nYearH
Public Function MonSinceFirstMolad(ByVal nYearH As Long) As Long
Dim nMonSinceFirstMolad As Long

' A shortcut to this function can simply be the following formula
' Return Int(((235 * nYearH) - 234) / 19)
' This formula is found in Remy Landau's website and he
' attributes it to Wolfgang Alexander Shochen. I will use a less
' optimized function which I believe shows the underlying logic
' better.

' count how many months there has been in all years up to last
' year. The months of this year hasn't happened yet.
nYearH = nYearH - 1


' In the 19 year cycle, there will always be 235 months. That
' would be 19 years times 12 months plus 7 extra month for the
' leap years. (19 * 12) + 7 = 235.

' Get how many 19 year cycles there has been and multiply it by
' 235

nMonSinceFirstMolad = Int(nYearH / 19) * 235

' Get the remaining years after the last complete 19 year cycle

nYearH = nYearH Mod 19

' Add 12 months for each of those years

nMonSinceFirstMolad = nMonSinceFirstMolad + (12 * nYearH)

' Add the extra months to account for the leap years

If nYearH >= 17 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 6
ElseIf nYearH >= 14 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 5
ElseIf nYearH >= 11 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 4
ElseIf nYearH >= 8 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 3
ElseIf nYearH >= 6 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 2
ElseIf nYearH >= 3 Then
nMonSinceFirstMolad = nMonSinceFirstMolad + 1
End If
MonSinceFirstMolad = nMonSinceFirstMolad
End Function


' This function returns if a given year is a leap year.

Public Function IsLeapYear(ByVal nYearH As Long) As Boolean
Dim nYearInCycle As Long


' Find out which year we are within the cycle. The 19th year of
' the cycle will return 0

nYearInCycle = nYearH Mod 19
IsLeapYear = nYearInCycle = 3 Or _
nYearInCycle = 6 Or _
nYearInCycle = 8 Or _
nYearInCycle = 11 Or _
nYearInCycle = 14 Or _
nYearInCycle = 17 Or _
nYearInCycle = 0
End Function


' This function figures out the Gregorian Date that corresponds to
' the first day of Tishrei, the first month of the Hebrew
' calendar, for a given Hebrew year.

Public Function Tishrei1(ByVal nYearH As Long) As Date
Dim nMonthsSinceFirstMolad As Long
Dim nChalakim As Long
Dim nHours As Long
Dim nDays As Long
Dim nDayOfWeek As Long
Dim dTishrei1 As Date


' We want to calculate how many days, hours and chalakim it has
' been from the time of 0 days, 0 hours and 0 chalakim to the
' molad at the beginning of year nYearH.
'
' The period between one new moon to the next is 29 days, 12
' hours and 793 chalakim. We must multiply that by the amount
' of months that transpired since the first molad. Then we add
' the time of the first molad (Monday, 5 hours and 204 chalakim)

nMonthsSinceFirstMolad = MonSinceFirstMolad(nYearH)
nChalakim = 793 * nMonthsSinceFirstMolad
nChalakim = nChalakim + 204

' carry the excess Chalakim over to the hours

nHours = Int(nChalakim / 1080)
nChalakim = nChalakim Mod 1080

nHours = nHours + (nMonthsSinceFirstMolad * 12)
nHours = nHours + 5

' carry the excess hours over to the days

nDays = Int(nHours / 24)
nHours = nHours Mod 24

nDays = nDays + (29 * nMonthsSinceFirstMolad)
nDays = nDays + 2


' figure out which day of the week the molad occurs.
' Sunday = 1, Moday = 2 ..., Shabbos = 0

nDayOfWeek = nDays Mod 7


' In a perfect world, Rosh Hashanah would be on the day of the
' molad. The Hebrew calendar makes four exceptions where we
' push off Rosh Hashanah one or two days. This is done to
' prevent three situation. Without explaining why, the three
' situations are:
' 1) We don't want Rosh Hashanah to come out on Sunday,
' Wednesday or Friday
' 2) We don't want Rosh Hashanah to be on the day of the
' molad if the molad occurs after the beginning of 18th
' hour.
' 3) We want to limit years to specific lengths. For non-leap
' years, we limit it to either 353, 354 or 355 days. For
' leap years, we limit it to either 383, 384 or 385 days.
' If setting Rosh Hashanah to the day of the molad will
' cause this year, or the previous year to fall outside
' these lengths, we push off Rosh Hashanah to get the year
' back to a valid length.
' This code handles these exceptions.


If Not IsLeapYear(nYearH) And _
nDayOfWeek = 3 And _
(nHours * 1080) + nChalakim >= _
(9 * 1080) + 204 Then

' This prevents the year from being 356 days. We have to push
' Rosh Hashanah off two days because if we pushed it off only
' one day, Rosh Hashanah would comes out on a Wednesday. Check
' the Hebrew year 5745 for an example.

nDayOfWeek = 5
nDays = nDays + 2
ElseIf IsLeapYear(nYearH - 1) And _
nDayOfWeek = 2 And _
(nHours * 1080) + nChalakim >= _
(15 * 1080) + 589 Then

' This prevents the previous year from being 382 days. Check
' the Hebrew Year 5766 for an example. If Rosh Hashanah was not
' pushed off a day then 5765 would be 382 days

nDayOfWeek = 3
nDays = nDays + 1
Else

' see rule 2 above. Check the Hebrew year 5765 for an example

If nHours >= 18 Then
nDayOfWeek = nDayOfWeek + 1
nDayOfWeek = nDayOfWeek Mod 7
nDays = nDays + 1
End If

' see rule 1 above. Check the Hebrew year 5765 for an example

If nDayOfWeek = 1 Or _
nDayOfWeek = 4 Or _
nDayOfWeek = 6 Then
nDayOfWeek = nDayOfWeek + 1
nDayOfWeek = nDayOfWeek Mod 7
nDays = nDays + 1
End If
End If


' Here we want to add nDays to creation
' dTishrie1 = creation + nDays
' Unfortunately, VB doesn't handle negative years very well.
' I therefore picked a Random date (1/1/1900) and figured out how
' many days it is after the creation (2067025). Then I subtracted
' 2067025 from nDays.

nDays = nDays - 2067025
dTishrei1 = #1/1/1900#
' 2067025 days after creation
dTishrei1 = dTishrei1 + nDays
Tishrei1 = dTishrei1
End Function


' This function gets the length of a Hebrew year.

Public Function LengthOfYear(ByVal nYearH As Long) As Long
Dim dThisTishrei1 As Date
Dim dNextTishrei1 As Date
Dim diff As Long


' subtract the date of this year from the date of next year

dThisTishrei1 = Tishrei1(nYearH)
dNextTishrei1 = Tishrei1(nYearH + 1)
diff = dNextTishrei1 - dThisTishrei1
LengthOfYear = diff
End Function


' This function converts a Hebrew date into the Gregorian date
' nYearH - is the Hebrew year
' nMonth - Tishrei=1
' Cheshvon=2
' Kislev=3
' Teyvet=4
' Shevat=5
' Adar A=6 (only valid on leap years)
' Adar=7 (Adar B for leap years)
' Nison=8
' Iyar=9
' Sivan=10
' Tamuz=11
' Av=12
' Elul=13

Public Function HebToGreg(ByVal nYearH As Long, _
ByVal nMonthH As Long, _
ByVal nDateH As Long) As Date
Dim nLengthOfYear As Long
Dim bLeap As Boolean
Dim dGreg As Date
Dim nMonth As Long
Dim nMonthLen As Long
Dim bHaser As Boolean
Dim bShalem As Boolean

bLeap = IsLeapYear(nYearH)
nLengthOfYear = LengthOfYear(nYearH)


' The regular length of a non-leap year is 354 days.
' The regular length of a leap year is 384 days.
' On regular years, the length of the months are as follows
' Tishrei (1) 30
' Cheshvon(2) 29
' Kislev (3) 30
' Teyvet (4) 29
' Shevat (5) 30
' Adar A (6) 30 (only valid on leap years)
' Adar (7) 29 (Adar B for leap years)
' Nison (8) 30
' Iyar (9) 29
' Sivan (10) 30
' Tamuz (11) 29
' Av (12) 30
' Elul (13) 29
' If the year is shorter by one less day, it is called a haser
' year. Kislev on a haser year has 29 days. If the year is longer
' by one day, it is called a shalem year. Cheshvon on a shalem
' year is 30 days.

bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385

' get the date for Tishrei 1

dGreg = Tishrei1(nYearH)
' Now count up days within the year

For nMonth = 1 To nMonthH - 1
Select Case nMonth
Case 1, 5, 8, 10, 12 ' 30 day months
nMonthLen = 30
Case 4, 7, 9, 11, 13 ' 29 day months
nMonthLen = 29
Case 6 ' There is only an Adar A on a leap years
nMonthLen = IIf(bLeap, 30, 0)
Case 2 ' Cheshvon, see note above
nMonthLen = IIf(bShalem, 30, 29)
Case 3 ' Kislev, see note above
nMonthLen = IIf(bHaser, 29, 30)
End Select
dGreg = dGreg + nMonthLen
Next
dGreg = dGreg + (nDateH - 1)
HebToGreg = dGreg
End Function


' This function converts a Gregorian date into the Hebrew date. The
' function returns the hebrew month as a string in the format MM/DD/YYYY.
' Also, the parameters nYearH, nMonthH and hDateH, which are sent by
' reference, will get set the Hebrew year, month and date. See function
' HebToGreg() for the definition of the month numbers.

Public Function GregToHeb(ByVal dGreg As Date, _
ByRef nYearH As Long, _
ByRef nMonthH As Long, _
ByRef nDateH As Long) As String
Dim nOneMolad As Double
Dim nAvrgYear As Double
Dim nDays As Long
Dim dTishrei1 As Date
Dim nLengthOfYear As Long
Dim bLeap As Boolean
Dim bHaser As Boolean
Dim bShalem As Boolean
Dim nMonthLen As Long
Dim bWhile As Boolean


' The basic algorythm to get Hebrew date for the Gregorian date dGreg.
' 1) Find out how many days dGreg is after creation.
' 2) Based on those days, estimate the Hebrew year
' 3) Now that we a good estimate of the Hebrew year, use brute force to
' find the Gregorian date for Tishrei 1 prior to or equal to dGreg
' 4) Add to Tishrei 1 the amount of days dGreg is after Tishrei 1

' Figure out how many days are in a month.
' 29 days + 12 hours + 793 chalakim

nOneMolad = 29 + (12 / 24) + (793 / (1080 * 24))

' Figure out the average length of a year. The hebrew year has exactly
' 235 months over 19 years.

nAvrgYear = nOneMolad * (235 / 19)

' Get how many days dGreg is after creation. See note as to why I
' use 1/1/1900 and add 2067025

nDays = dGreg - #1/1/1900#
nDays = nDays + 2067025 ' 2067025 days after creation
' Guess the Hebrew year. This should be a pretty accurate guess.

nYearH = Int(CDbl(nDays) / nAvrgYear) + 1

' Use brute force to find the exact year nYearH. It is the Tishrei 1 in
' the year <= dGreg.

dTishrei1 = Tishrei1(nYearH)
If dTishrei1 = dGreg Then

' If we got lucky and landed on the exact date, we can stop here

nMonthH = 1
nDateH = 1
Else

' Here is the brute force. Either count up or count down nYearH
' until Tishrei 1 is <= dGreg.

If dTishrei1 < dGreg Then

' If Tishrei 1, nYearH is less than dGreg, count nYearH up.

Do While Tishrei1(nYearH + 1) <= dGreg
nYearH = nYearH + 1
Loop
Else

' If Tishrei 1, nYearH is greater than dGreg, count nYearH down.

nYearH = nYearH - 1
Do While Tishrei1(nYearH) > dGreg
nYearH = nYearH - 1
Loop
End If


' Subtract Tishrei 1, nYearH from dGreg. That should leave us with
' how many days we have to add to Tishrei 1

nDays = dGreg - Tishrei1(nYearH)


' Find out what type of year it is so that we know the length of the
' months

nLengthOfYear = LengthOfYear(nYearH)
bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385
bLeap = IsLeapYear(nYearH)


' Add nDays to Tishrei 1.

nMonthH = 1
Do
Select Case nMonthH
Case 1, 5, 8, 10, 12' 30 day months
nMonthLen = 30
Case 4, 7, 9, 11, 13' 29 day months
nMonthLen = 29
Case 6 ' Adar A (6) will be skipped on non-leap years
nMonthLen = 30
Case 2 ' Cheshvon, see note above
nMonthLen = IIf(bShalem, 30, 29)
Case 3 ' Kislev, see note above
nMonthLen = IIf(bHaser, 29, 30)
End Select
If nDays >= nMonthLen Then
bWhile = True
If bLeap Or nMonthH <> 5 Then
nMonthH = nMonthH + 1
Else

' We can skip Adar A (6) if its not a leap year

nMonthH = nMonthH + 2
End If
nDays = nDays - nMonthLen
Else
bWhile = False
End If
Loop While bWhile

' Add the remaining days to Date

nDateH = nDays + 1
End If
GregToHeb = CStr(nMonthH) & "/" & CStr(nDateH) & "/" & CStr(nYearH)
End Function

Public Function FormatDateH(nYearH, nMonthH, nDateH)
Dim sMonth As String
Select Case nMonthH
Case 1
sMonth = "Tishrei"
Case 2
sMonth = "Cheshvan"
Case 3
sMonth = "Kislev"
Case 4
sMonth = "Teves"
Case 5
sMonth = "Shevat"
Case 6
sMonth = "Adar A"
Case 7
sMonth = IIf(IsLeapYear(nYearH), "Adar B", "Adar")
Case 8
sMonth = "Nisan"
Case 9
sMonth = "Iyar"
Case 10
sMonth = "Sivan"
Case 11
sMonth = "Tamuz"
Case 12
sMonth = "Av"
Case 13
sMonth = "Elul"
End Select
FormatDateH = sMonth & " " & CStr(nDateH) & " " & CStr(nYearH)
End Function

Public Function TodayHeb()
Dim nYearH As Long
Dim nMonthH As Long
Dim nDateH As Long
Dim dToday As Date

dToday = Int(Now())
GregToHeb dToday, nYearH, nMonthH, nDateH
TodayHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function

Public Function DateToHeb(dDate)
Dim nYearH As Long
Dim nMonthH As Long
Dim nDateH As Long

dDate = CDate(dDate)
GregToHeb dDate, nYearH, nMonthH, nDateH
DateToHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function

I am not a programer and my knowledge of scripting is enough to be dangerous.... Thanks for your help.

Joined: Feb 2005
Posts: 16
J
jkouzes Offline OP
Pikka bird
OP Offline
Pikka bird
J
Joined: Feb 2005
Posts: 16
Here is a smaller version:

<script LANGUAGE="JavaScript">
<!-- to hide script contents from old browsers
var GREG_SDN_OFFSET = 32045,
DAYS_PER_5_MONTHS = 153,
DAYS_PER_4_YEARS = 1461,
DAYS_PER_400_YEARS = 146097;
var HALAKIM_PER_HOUR = 1080,
HALAKIM_PER_DAY = 25920,
HALAKIM_PER_LUNAR_CYCLE = ((29 * HALAKIM_PER_DAY) + 13753),
HALAKIM_PER_METONIC_CYCLE = (HALAKIM_PER_LUNAR_CYCLE * (12 * 19 + 7));
var HEB_SDN_OFFSET = 347997,
NEW_MOON_OF_CREATION = 31524,
NOON = (18 * HALAKIM_PER_HOUR),
AM3_11_20 = ((9 * HALAKIM_PER_HOUR) + 204),
AM9_32_43 = ((15 * HALAKIM_PER_HOUR) + 589);
var SUN = 0,
MON = 1,
TUES = 2,
WED = 3,
THUR = 4,
FRI = 5,
SAT = 6;
var today = null,
afterSundown = false,
hebrewMonth = 0,
hebrewDate = 0,
hebrewYear = 0,
metonicCycle = 0,
metonicYear = 0,
moladDay = 0,
moladHalakim = 0;
var gMonth = new gregmontharr("January","February","March","April","May","June","July","August","September","October","November","December");
var hMonth = new hebrewmontharr("Tishri","Heshvan","Kislev","Tevet","Shevat","Adar","AdarII","Nisan","Iyyar","Sivan","Tammuz","Av","Elul");
var mpy = new monthsperyeararr(12,12,13,12,12,13,12,13,12,12,13,12,12,13,12,12,13,12,13);
function weekdayarr(d0,d1,d2,d3,d4,d5,d6)
{
this[0] = d0; this[1] = d1; this[2] = d2; this[3] = d3;
this[4] = d4; this[5] = d5; this[6] = d6;
}
function gregmontharr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11)
{
this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
}
function hebrewmontharr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13)
{
this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
this[12] = m12; this[13] = m13;
}
function monthsperyeararr(m0,m1,m2,m3,m4,m5,m6,m7,m8,m9,
m10,m11,m12,m13,m14,m15,m16,m17,m18)
{
this[0] = m0; this[1] = m1; this[2] = m2; this[3] = m3;
this[4] = m4; this[5] = m5; this[6] = m6; this[7] = m7;
this[8] = m8; this[9] = m9; this[10] = m10; this[11] = m11;
this[12] = m8; this[13] = m13; this[14] = m14; this[15] = m15;
this[16] = m16; this[17] = m17; this[18] = m18;
}
function getToday()
{
if(today == null) {
today = new Date();
// afterSundown = (today.getHours() >= 19);
}
}
function displayWeekday()
{
}
function displayGregorianDate()
{
tryear = today.getYear()
if (tryear < 200) tryear += 1900;
document.writeln(today.getDate() + " " + gMonth[today.getMonth()] + " " + (tryear));
}
function displayHebrewDate()
{
if(hebrewDate != 0 && hebrewMonth != 0 && hebrewYear != 0)
document.writeln(hebrewDate + " " + hMonth[hebrewMonth-1] + " " + hebrewYear);
}
function GregorianToSdn(inputYear,inputMonth,inputDay)
{
var year = 0,
month = 0,
sdn;
// Make year a positive number
if (inputYear < 0)
year = inputYear + 4801;
else
year = inputYear + 4800;
// Adjust the start of the year
if (inputMonth > 2) {
month = inputMonth - 3;
}
else {
month = inputMonth + 9;
year--;
}
sdn = Math.floor((Math.floor(year / 100) * DAYS_PER_400_YEARS) / 4);
sdn += Math.floor(((year % 100) * DAYS_PER_4_YEARS) / 4);
sdn += Math.floor((month * DAYS_PER_5_MONTHS + 2) / 5);
sdn += inputDay - GREG_SDN_OFFSET;
if(afterSundown) {
sdn++;
}
return sdn;
}
function SdnToHebrew(sdn)
{
var inputDay,
tishri1 = 0,
tishri1After = 0,
yearLength = 0,
inputDay = sdn - HEB_SDN_OFFSET;
FindTishriMolad(inputDay);
tishri1 = Tishri1(metonicYear,moladDay,moladHalakim);
if (inputDay >= tishri1) {
// It found Tishri 1 at the start of the year.
hebrewYear = metonicCycle * 19 + metonicYear + 1;
if (inputDay < tishri1 + 59) {
if (inputDay < tishri1 + 30) {
hebrewMonth = 1;
hebrewDate = inputDay - tishri1 + 1;
}
else {
hebrewMonth = 2;
hebrewDate = inputDay - tishri1 - 29;
}

return;
}
// We need the length of the year to figure this out,so find Tishri 1 of the next year.
moladHalakim += HALAKIM_PER_LUNAR_CYCLE * mpy[metonicYear];
moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
moladHalakim = moladHalakim % HALAKIM_PER_DAY;
tishri1After = Tishri1((metonicYear + 1) % 19,moladDay,moladHalakim);
}
else {
// It found Tishri 1 at the end of the year.
hebrewYear = metonicCycle * 19 + metonicYear;
if (inputDay >= tishri1 - 177) {
// It is one of the last 6 months of the year.
if (inputDay > tishri1 - 30) {
hebrewMonth = 13;
hebrewDate = inputDay - tishri1 + 30;
}
else if (inputDay > tishri1 - 60) {
hebrewMonth = 12;
hebrewDate = inputDay - tishri1 + 60;
}
else if (inputDay > tishri1 - 89) {
hebrewMonth = 11;
hebrewDate = inputDay - tishri1 + 89;
}
else if (inputDay > tishri1 - 119) {
hebrewMonth = 10;
hebrewDate = inputDay - tishri1 + 119;
}
else if (inputDay > tishri1 - 148) {
hebrewMonth = 9;
hebrewDate = inputDay - tishri1 + 148;
}
else {
hebrewMonth = 8;
hebrewDate = inputDay - tishri1 + 178;
}
return;
}
else {
if (mpy[(hebrewYear - 1) % 19] == 13) {
hebrewMonth = 7;
hebrewDate = inputDay - tishri1 + 207;
if (hebrewDate > 0)
return;

hebrewMonth--;
hebrewDate += 30;
if (hebrewDate > 0)
return;

hebrewMonth--;
hebrewDate += 30;
}
else {
hebrewMonth = 6;
hebrewDate = inputDay - tishri1 + 207;
if (hebrewDate > 0)
return;

hebrewMonth--;
hebrewDate += 30;
}
if (hebrewDate > 0)
return;

hebrewMonth--;
hebrewDate += 29;
if (hebrewDate > 0)
return;
// We need the length of the year to figure this out,so find Tishri 1 of this year.
tishri1After = tishri1;
FindTishriMolad(moladDay - 365);
tishri1 = Tishri1(metonicYear,moladDay,moladHalakim);
}
}
yearLength = tishri1After - tishri1;
moladDay = inputDay - tishri1 - 29;
if (yearLength == 355 || yearLength == 385) {
// Heshvan has 30 days
if (moladDay <= 30) {
hebrewMonth = 2;
hebrewDate = moladDay;
return;
}
moladDay -= 30;
}
else {
// Heshvan has 29 days
if (moladDay <= 29) {
hebrewMonth = 2;
hebrewDate = moladDay;
return;
}
moladDay -= 29;
}
// It has to be Kislev.
hebrewMonth = 3;
hebrewDate = moladDay;
}
function FindTishriMolad(inputDay)
{
// Estimate the metonic cycle number. Note that this may be an under
// estimate because there are 6939.6896 days in a metonic cycle not
// 6940,but it will never be an over estimate. The loop below will
// correct for any error in this estimate.
metonicCycle = Math.floor((inputDay + 310) / 6940);
// Calculate the time of the starting molad for this metonic cycle.
MoladOfMetonicCycle();
// If the above was an under estimate,increment the cycle number until
// the correct one is found. For modern dates this loop is about 98.6%
// likely to not execute,even once,because the above estimate is
// really quite close.
while (moladDay < inputDay - 6940 + 310) {
metonicCycle++;
moladHalakim += HALAKIM_PER_METONIC_CYCLE;
moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
moladHalakim = moladHalakim % HALAKIM_PER_DAY;
}
// Find the molad of Tishri closest to this date.
for (metonicYear = 0; metonicYear < 18; metonicYear++) {
if (moladDay > inputDay - 74)
break;
moladHalakim += HALAKIM_PER_LUNAR_CYCLE * mpy[metonicYear];
moladDay += Math.floor(moladHalakim / HALAKIM_PER_DAY);
moladHalakim = moladHalakim % HALAKIM_PER_DAY;
}
}
function MoladOfMetonicCycle()
{
var r1,r2,d1,d2;
// Start with the time of the first molad after creation.
r1 = NEW_MOON_OF_CREATION;
// Calculate gMetonicCycle * HALAKIM_PER_METONIC_CYCLE. The upper 32
// bits of the result will be in r2 and the lower 16 bits will be in r1.
r1 += metonicCycle * (HALAKIM_PER_METONIC_CYCLE & 0xFFFF);
r2 = r1 >> 16;
r2 += metonicCycle * ((HALAKIM_PER_METONIC_CYCLE >> 16) & 0xFFFF);
// Calculate r2r1 / HALAKIM_PER_DAY. The remainder will be in r1,the
// upper 16 bits of the quotient will be in d2 and the lower 16 bits
// will be in d1.
d2 = Math.floor(r2 / HALAKIM_PER_DAY);
r2 -= d2 * HALAKIM_PER_DAY;
r1 = (r2 << 16) | (r1 & 0xFFFF);
d1 = Math.floor(r1 / HALAKIM_PER_DAY);
r1 -= d1 * HALAKIM_PER_DAY;
moladDay = (d2 << 16) | d1;
moladHalakim = r1;
}
function Tishri1(metonicYear,moladDay,moladHalakim)
{
var tishri1 = moladDay;
var dow = tishri1 % 7;
var leapYear = metonicYear == 2 || metonicYear == 5 || metonicYear == 7 || metonicYear == 10 ||
metonicYear == 13 || metonicYear == 16 || metonicYear == 18;

var lastWasLeapYear = metonicYear == 3 || metonicYear == 6 || metonicYear == 8 || metonicYear == 11 ||
metonicYear == 14 || metonicYear == 17 || metonicYear == 0;
// Apply rules 2,3 and 4
if ((moladHalakim >= NOON) ||
((!leapYear) && dow == TUES && moladHalakim >= AM3_11_20) ||
(lastWasLeapYear && dow == MON && moladHalakim >= AM9_32_43))
{
tishri1++;
dow++;
if (dow == 7)
dow = 0;
}
// Apply rule 1 after the others because it can cause an additional delay of one day.
if (dow == WED || dow == FRI || dow == SUN) {
tishri1++;
}
return tishri1;
}
function ShowJewDate(){
document.jdate.jewdate.value="Please enter a valid date.......";
var SJYear = 0;
var SJMonth = 0;
var SJDay = 0;
SJYear=parseInt(document.jdate.myYear.value);
SJMonth=parseInt(document.jdate.myMonth.value);
SJDay=parseInt(document.jdate.myDay.value);
if (hebrewDate == 0 || hebrewMonth == 0 || hebrewYear == 0)
{
alert("Please enter a valid date.......");
return;
}
if (SJYear < 1900)
{
alert("The year must be greater than 1900...");
return;
}
if (SJMonth < 1 || SJMonth > 12)
{
alert("The month must be from 1 to 12...");
return;
}
if (SJDay < 1 || SJDay > 31)
{
alert("The day must be from 1 to 31...");
return;
}
SdnToHebrew(GregorianToSdn(SJYear,SJMonth,SJDay));
if(hebrewDate != 0 && hebrewMonth != 0 && hebrewYear != 0)
document.jdate.jewdate.value = SJDay + " " + gMonth[SJMonth-1] + " " + SJYear + " = " + hebrewDate + " " + hMonth[hebrewMonth-1] + " " + hebrewYear;
}
// end hiding contents from old browsers -->
</script>
<!-- End Hebrew Date Script -->
</head>



<body bgcolor="ffffff" text="0000ff" link="0000ff" vlink="0000ff">

<center>
<table width=800><tr><td>
<img src="../main/mimages/bsd.gif" ALT="BS'D" width="48" height="30" align="right"><br clear="all">
</td></tr></table>
</center>

<center>
<table width="800">
<tr><td width="120" valign="top" align="center">

<table cellpadding="5" cellspacing="5" border="0" width="100%">
<tr><td align="center">
<a href="../main/about.php">
<img src="../main/mimages/ai_logo.gif" alt="Ahavat Israel" border="1" width="50" height="52"></a>
</td></tr></table>

<table border="0" cellpadding="5" cellspacing="5" bgcolor="#ccccff" width=100%>
<tr><td align="center"><h5><a href="/index.php">Ahavat Israel</a></td></tr>
<tr><td align="center"><h5><a href="/am/index.php">Am Israel</a></td></tr>
<tr><td align="center"><h5><a href="/torat/index.php">Torat Israel</a></td></tr>
<tr><td align="center"><h5><a href="/eretz/index.php">Eretz Israel</a></td></tr>
<tr><td align="center"><h5><a href="../protest/index.php">Love Protest</a></td></tr>



<tr><td align="center"><h5><a href="shabbat.php">Shabbat</a></td></tr>
<tr><td align="center"><h5><a href="kosher.php">Kosher Food</a></td></tr>
<tr><td align="center"><h5><a href="treif.php">Treif</a></td></tr>
<tr><td align="center"><h5><a href="festivals.php">Festivals</a></td></tr>
<tr><td align="center"><h5><a href="prayer.php">Prayer</a></td></tr>
<tr><td align="center"><h5><a href="calendar.php">Calendar</a></td></tr>
<tr><td align="center"><h5><a href="lifecycle.php">Life Cycle</a></td></tr>
<tr><td align="center"><h5><a href="britmila.php">Brit Milah</a></td></tr>
<tr><td align="center"><h5><a href="barmitzva.php">Bar Mitzvah</a></td></tr>
<tr><td align="center"><h5><a href="marriage.php">Marriage</a></td></tr>
<tr><td align="center"><h5><a href="divorce.php">Divorce</a></td></tr>
<tr><td align="center"><h5><a href="death.php">Death</a></td></tr>
<tr><td align="center"><h5><a href="signs.php">Signs & Symbols</a></td></tr>
<tr><td align="center"><h5><a href="tefillin.php">Tefillin</a></td></tr>
<tr><td align="center"><h5><a href="mezuza.php">Mezuza</a></td></tr>
<tr><td align="center"><h5><a href="tzitzit.php">Tzitzit</a></td></tr>
<tr><td align="center"><h5><a href="temple.php">Temple</a></td></tr>
<tr><td align="center"><h5><a href="kisui.php">Kisui Rosh</a></td></tr>
<tr><td align="center"><h5><a href="roshhashana.php">Rosh Hashana</a></td></tr>
<tr><td align="center"><h5><a href="yomkippur.php">Yom Kippur</a></td></tr>
<tr><td align="center"><h5><a href="sukkot.php">Sukkot</a></td></tr>
<tr><td align="center"><h5><a href="shminiatzeret.php">Simchat Torah</a></td></tr>
<tr><td align="center"><h5><a href="pesach.php">Pesach</a></td></tr>
<tr><td align="center"><h5><a href="omer.php">HaOmer</a></td></tr>
<tr><td align="center"><h5><a href="shavuot.php">Shavuot</a></td></tr>
<tr><td align="center"><h5><a href="chanukah.php">Chanukah</a></td></tr>
<tr><td align="center"><h5><a href="tubishvat.php">Tu BiShvat</a></td></tr>
<tr><td align="center"><h5><a href="purim.php">Purim</a></td></tr>
<tr><td align="center"><h5><a href="lagbaomer.php">Lag BaOmer</a></td></tr>
<tr><td align="center"><h5><a href="tishabeav.php">Tisha BeAv Fast</a></td></tr>

<tr><td align="center"><h5><a href="../main/classads.php">ClassAds</a></td></tr>
<tr><td align="center"><h5><a href="/postcard/index.php">Postcard</a></td></tr>
<tr><td align="center"><h5><a href="../main/forum.php">Forum</a></td></tr>
<tr><td align="center"><h5><a href="/ahavat/music/index.php">Music</a></td></tr>
<tr><td align="center"><h5><a href="/ahavat/humor/index.php">Humor</a></td></tr>
<tr><td align="center"><h5><a href="/ahavat/games/index.php">Games</a></td></tr>
<tr><td align="center"><h5><a href="../main/links.php">Links</a></td></tr>
<tr><td align="center"><h5><a href="../main/bookstore.php">Books</a></td></tr>
<tr><td align="center"><h5><a href="../main/about.php">About</a></td></tr>
<tr><td align="center"><h5><a href="../main/feedback.php">Feedback</a></td></tr>
<tr><td align="center"><h5><a href="http://www.free-cgi.com/freecgi/recomend/recomend.php?User=ahavat">Recommend</a></td></tr>
<tr><td align="center"><h5><a href="../main/wallpaper.php">Wallpaper</a></td></tr>
<tr><td align="center"><h5><a href="../main/privacy.php">Privacy</a></td></tr>
<tr><td align="center"><h5><a href="../main/copyright.php">Copyright</a></td></tr>
</table>

<table><tr><td align="center">
<a href="../main/about.php"><img src="../main/mimages/madelove.gif" width="78" height="36"></a>
</td></tr></table>

</td><td width="20" valign="top"><br>
</td><td width="800" valign="top">

<center>
<a href=http://www.hatufim.org target=_blank><img src=../images/baner-hatufim10.jpg></a>
</center>






<center><i><font size="7" color="0000ff">Jewish Calendar</font></i>

<table border="0" cellpadding="0" cellspacing="0" width="460">
<tr><td align="center" bgcolor="#A5D2FC"><font color="ffffff">
<font face="Rockwell" color="0000ff" align="left" size="-1">
<b>Today's date:</b></font></td><td><br></td>
<script LANGUAGE="JavaScript">
<!-- to hide script contents from old browsers
getToday();
document.writeln("<td bgcolor=#A5D2FC>");
document.writeln("<center><small><font face=Rockwell color=0000ff><strong>");
displayGregorianDate();
document.writeln("</font></strong>");
document.writeln("</td>");
document.writeln("<td><br></td>");
document.writeln("<td bgcolor=#A5D2FC>");
tryear = today.getYear()
if (tryear < 200) tryear += 1900;
SdnToHebrew(GregorianToSdn(tryear,today.getMonth()+1,today.getDate()));
document.writeln("<center><small><font face=Rockwell color=0000ff><strong>");
displayHebrewDate();
document.writeln("</td></tr>");
// end hiding contents from old browsers -->
</script>


Link Copied to Clipboard