Exemple #1
0
        /*=================================GetLunarMonthDay==========================
         **Action: Using the Hebrew table (HebrewTable) to get the Hebrew month/day value for Gregorian January 1st
         ** in a given Gregorian year.
         ** Greogrian January 1st falls usually in Tevet (4th month). Tevet has always 29 days.
         **     That's why, there no nead to specify the lunar month in the table.  There are exceptions, and these
         **     are coded by giving numbers above 29 and below 1.
         **     Actual decoding is takenig place in the switch statement below.
         **Returns:
         **     The Hebrew year type. The value is from 1 to 6.
         **     normal years : 1 = 353 days   2 = 354 days   3 = 355 days.
         **     Leap years   : 4 = 383        5   384        6 = 385 days.
         **Arguments:
         **      gregorianYear   The year value in Gregorian calendar.  The value should be between 1500 and 2239.
         **      lunarDate       Object to take the result of the Hebrew year/month/day.
         **Exceptions:
         **============================================================================*/

        internal static int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate)
        {
            //
            //  Get the offset into the LunarMonthLen array and the lunar day
            //  for January 1st.
            //
            int index = gregorianYear - FirstGregorianTableYear;

            if (index < 0 || index > TABLESIZE)
            {
                throw new ArgumentOutOfRangeException(nameof(gregorianYear));
            }

            index        *= 2;
            lunarDate.day = s_hebrewTable[index];

            // Get the type of the year. The value is from 1 to 6
            int LunarYearType = s_hebrewTable[index + 1];

            //
            //  Get the Lunar Month.
            //
            switch (lunarDate.day)
            {
            case (0):                       // 1/1 is on Shvat 1
                lunarDate.month = 5;
                lunarDate.day   = 1;
                break;

            case (30):                      // 1/1 is on Kislev 30
                lunarDate.month = 3;
                break;

            case (31):                      // 1/1 is on Shvat 2
                lunarDate.month = 5;
                lunarDate.day   = 2;
                break;

            case (32):                      // 1/1 is on Shvat 3
                lunarDate.month = 5;
                lunarDate.day   = 3;
                break;

            case (33):                      // 1/1 is on Kislev 29
                lunarDate.month = 3;
                lunarDate.day   = 29;
                break;

            default:                          // 1/1 is on Tevet (This is the general case)
                lunarDate.month = 4;
                break;
            }
            return(LunarYearType);
        }
Exemple #2
0
        private DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
        {
            int          gregorianYear = hebrewYear - 0xeb0;
            __DateBuffer lunarDate     = new __DateBuffer();
            int          lunarMonthDay = this.GetLunarMonthDay(gregorianYear, lunarDate);

            if ((hebrewMonth == lunarDate.month) && (hebrewDay == lunarDate.day))
            {
                return(new DateTime(gregorianYear, 1, 1, hour, minute, second, millisecond));
            }
            int      num3 = this.GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, lunarDate.month, lunarDate.day);
            DateTime time = new DateTime(gregorianYear, 1, 1);

            return(new DateTime((time.Ticks + (num3 * 0xc92a69c000L)) + Calendar.TimeToTicks(hour, minute, second, millisecond)));
        }
Exemple #3
0
        internal int GetResult(__DateBuffer result, int part)
        {
            switch (part)
            {
            case 0:
                return(result.year);

            case 2:
                return(result.month);

            case 3:
                return(result.day);
            }
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DateTimeParsing"));
        }
Exemple #4
0
        internal static int GetResult(__DateBuffer result, int part)
        {
            switch (part)
            {
            case DatePartYear:
                return(result.year);

            case DatePartMonth:
                return(result.month);

            case DatePartDay:
                return(result.day);
            }

            throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
        }
Exemple #5
0
        internal virtual int GetDatePart(long ticks, int part)
        {
            this.CheckTicksRange(ticks);
            DateTime     time      = new DateTime(ticks);
            int          year      = time.Year;
            int          month     = time.Month;
            int          day       = time.Day;
            __DateBuffer lunarDate = new __DateBuffer {
                year = year + 0xeb0
            };
            int          lunarMonthDay = this.GetLunarMonthDay(year, lunarDate);
            __DateBuffer result        = new __DateBuffer {
                year  = lunarDate.year,
                month = lunarDate.month,
                day   = lunarDate.day
            };
            long num5 = GregorianCalendar.GetAbsoluteDate(year, month, day);

            if ((month != 1) || (day != 1))
            {
                long num6 = num5 - GregorianCalendar.GetAbsoluteDate(year, 1, 1);
                if ((num6 + lunarDate.day) <= m_lunarMonthLen[lunarMonthDay, lunarDate.month])
                {
                    result.day += (int)num6;
                    return(this.GetResult(result, part));
                }
                result.month++;
                result.day = 1;
                num6      -= m_lunarMonthLen[lunarMonthDay, lunarDate.month] - lunarDate.day;
                if (num6 > 1L)
                {
                    while (num6 > m_lunarMonthLen[lunarMonthDay, result.month])
                    {
                        num6 -= m_lunarMonthLen[lunarMonthDay, result.month++];
                        if ((result.month > 13) || (m_lunarMonthLen[lunarMonthDay, result.month] == 0))
                        {
                            result.year++;
                            lunarMonthDay = m_HebrewTable[(((year + 1) - 0x62f) * 2) + 1];
                            result.month  = 1;
                        }
                    }
                    result.day += (int)(num6 - 1L);
                }
            }
            return(this.GetResult(result, part));
        }
Exemple #6
0
        internal int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate)
        {
            int index = gregorianYear - 0x62f;

            if ((index < 0) || (index > 0x290))
            {
                throw new ArgumentOutOfRangeException("gregorianYear");
            }
            index        *= 2;
            lunarDate.day = m_HebrewTable[index];
            int num2 = m_HebrewTable[index + 1];

            switch (lunarDate.day)
            {
            case 30:
                lunarDate.month = 3;
                return(num2);

            case 0x1f:
                lunarDate.month = 5;
                lunarDate.day   = 2;
                return(num2);

            case 0x20:
                lunarDate.month = 5;
                lunarDate.day   = 3;
                return(num2);

            case 0x21:
                lunarDate.month = 3;
                lunarDate.day   = 0x1d;
                return(num2);

            case 0:
                lunarDate.month = 5;
                lunarDate.day   = 1;
                return(num2);
            }
            lunarDate.month = 4;
            return(num2);
        }
Exemple #7
0
        /*=================================HebrewToGregorian==========================
        **Action: Convert Hebrew date to Gregorian date.
        **Returns:
        **Arguments:
        **Exceptions:
        **  The algorithm is like this:
        **      The hebrew year has an offset to the Gregorian year, so we can guess the Gregorian year for
        **      the specified Hebrew year.  That is, GreogrianYear = HebrewYear - FirstHebrewYearOf1AD.
        **
        **      From the Gregorian year and HebrewTable, we can get the Hebrew month/day value
        **      of the Gregorian date January 1st.  Let's call this month/day value [hebrewDateForJan1]
        **
        **      If the requested Hebrew month/day is less than [hebrewDateForJan1], we know the result
        **      Gregorian date falls in previous year.  So we decrease the Gregorian year value, and
        **      retrieve the Hebrew month/day value of the Gregorian date january 1st again.
        **
        **      Now, we get the answer of the Gregorian year.
        **
        **      The next step is to get the number of days between the requested Hebrew month/day
        **      and [hebrewDateForJan1].  When we get that, we can create the DateTime by adding/subtracting
        **      the ticks value of the number of days.
        **
        ** ============================================================================*/


        private static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
        {
            // Get the rough Gregorian year for the specified hebrewYear.
            //
            int gregorianYear = hebrewYear - HebrewYearOf1AD;

            __DateBuffer hebrewDateOfJan1 = new __DateBuffer(); // year value is unused.
            int          lunarYearType    = GetLunarMonthDay(gregorianYear, hebrewDateOfJan1);

            if ((hebrewMonth == hebrewDateOfJan1.month) && (hebrewDay == hebrewDateOfJan1.day))
            {
                return(new DateTime(gregorianYear, 1, 1, hour, minute, second, millisecond));
            }

            int days = GetDayDifference(lunarYearType, hebrewMonth, hebrewDay, hebrewDateOfJan1.month, hebrewDateOfJan1.day);

            DateTime gregorianNewYear = new DateTime(gregorianYear, 1, 1);

            return(new DateTime(gregorianNewYear.Ticks + days * TicksPerDay
                                + TimeToTicks(hour, minute, second, millisecond)));
        }
 private DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
 {
     int gregorianYear = hebrewYear - 0xeb0;
     __DateBuffer lunarDate = new __DateBuffer();
     int lunarMonthDay = this.GetLunarMonthDay(gregorianYear, lunarDate);
     if ((hebrewMonth == lunarDate.month) && (hebrewDay == lunarDate.day))
     {
         return new DateTime(gregorianYear, 1, 1, hour, minute, second, millisecond);
     }
     int num3 = this.GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, lunarDate.month, lunarDate.day);
     DateTime time = new DateTime(gregorianYear, 1, 1);
     return new DateTime((time.Ticks + (num3 * 0xc92a69c000L)) + Calendar.TimeToTicks(hour, minute, second, millisecond));
 }
        internal int GetResult(__DateBuffer result, int part)
        {
            switch (part)
            {
                case 0:
                    return result.year;

                case 2:
                    return result.month;

                case 3:
                    return result.day;
            }
            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DateTimeParsing"));
        }
Exemple #10
0
        internal int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate)
        {
            int index = gregorianYear - 0x62f;
            if ((index < 0) || (index > 0x290))
            {
                throw new ArgumentOutOfRangeException("gregorianYear");
            }
            index *= 2;
            lunarDate.day = m_HebrewTable[index];
            int num2 = m_HebrewTable[index + 1];
            switch (lunarDate.day)
            {
                case 30:
                    lunarDate.month = 3;
                    return num2;

                case 0x1f:
                    lunarDate.month = 5;
                    lunarDate.day = 2;
                    return num2;

                case 0x20:
                    lunarDate.month = 5;
                    lunarDate.day = 3;
                    return num2;

                case 0x21:
                    lunarDate.month = 3;
                    lunarDate.day = 0x1d;
                    return num2;

                case 0:
                    lunarDate.month = 5;
                    lunarDate.day = 1;
                    return num2;
            }
            lunarDate.month = 4;
            return num2;
        }
Exemple #11
0
 internal virtual int GetDatePart(long ticks, int part)
 {
     this.CheckTicksRange(ticks);
     DateTime time = new DateTime(ticks);
     int year = time.Year;
     int month = time.Month;
     int day = time.Day;
     __DateBuffer lunarDate = new __DateBuffer {
         year = year + 0xeb0
     };
     int lunarMonthDay = this.GetLunarMonthDay(year, lunarDate);
     __DateBuffer result = new __DateBuffer {
         year = lunarDate.year,
         month = lunarDate.month,
         day = lunarDate.day
     };
     long num5 = GregorianCalendar.GetAbsoluteDate(year, month, day);
     if ((month != 1) || (day != 1))
     {
         long num6 = num5 - GregorianCalendar.GetAbsoluteDate(year, 1, 1);
         if ((num6 + lunarDate.day) <= m_lunarMonthLen[lunarMonthDay, lunarDate.month])
         {
             result.day += (int) num6;
             return this.GetResult(result, part);
         }
         result.month++;
         result.day = 1;
         num6 -= m_lunarMonthLen[lunarMonthDay, lunarDate.month] - lunarDate.day;
         if (num6 > 1L)
         {
             while (num6 > m_lunarMonthLen[lunarMonthDay, result.month])
             {
                 num6 -= m_lunarMonthLen[lunarMonthDay, result.month++];
                 if ((result.month > 13) || (m_lunarMonthLen[lunarMonthDay, result.month] == 0))
                 {
                     result.year++;
                     lunarMonthDay = m_HebrewTable[(((year + 1) - 0x62f) * 2) + 1];
                     result.month = 1;
                 }
             }
             result.day += (int) (num6 - 1L);
         }
     }
     return this.GetResult(result, part);
 }
Exemple #12
0
        // Returns a given date part of this DateTime. This method is used 
        // to compute the year, day-of-year, month, or day part. 

        internal virtual int GetDatePart(long ticks, int part) { 
            // The Gregorian year, month, day value for ticks.
            int gregorianYear, gregorianMonth, gregorianDay;
            int hebrewYearType;                // lunar year type
            long AbsoluteDate;                // absolute date - absolute date 1/1/1600 

            // 
            //  Make sure we have a valid Gregorian date that will fit into our 
            //  Hebrew conversion limits.
            // 
            CheckTicksRange(ticks);

            DateTime time = new DateTime(ticks);
 
            //
            //  Save the Gregorian date values. 
            // 
            gregorianYear = time.Year;
            gregorianMonth = time.Month; 
            gregorianDay = time.Day;

            __DateBuffer lunarDate = new __DateBuffer();    // lunar month and day for Jan 1
 
            // From the table looking-up value of HebrewTable[index] (stored in lunarDate.day), we get the the
            // lunar month and lunar day where the Gregorian date 1/1 falls. 
            lunarDate.year = gregorianYear + HebrewYearOf1AD; 
            hebrewYearType = GetLunarMonthDay(gregorianYear, lunarDate);
 
            // This is the buffer used to store the result Hebrew date.
            __DateBuffer result = new __DateBuffer();

            // 
            //  Store the values for the start of the new year - 1/1.
            // 
            result.year  = lunarDate.year; 
            result.month = lunarDate.month;
            result.day   = lunarDate.day; 

            //
            //  Get the absolute date from 1/1/1600.
            // 
            AbsoluteDate = GregorianCalendar.GetAbsoluteDate(gregorianYear, gregorianMonth, gregorianDay);
 
            // 
            //  If the requested date was 1/1, then we're done.
            // 
            if ((gregorianMonth == 1) && (gregorianDay == 1)) {
                return (GetResult(result, part));
            }
 
            //
            //  Calculate the number of days between 1/1 and the requested date. 
            // 
            long NumDays;                      // number of days since 1/1
            NumDays = AbsoluteDate - GregorianCalendar.GetAbsoluteDate(gregorianYear, 1, 1); 

            //
            //  If the requested date is within the current lunar month, then
            //  we're done. 
            //
            if ((NumDays + (long)lunarDate.day) <= (long)(LunarMonthLen[hebrewYearType, lunarDate.month])) { 
                result.day += (int)NumDays; 
                return (GetResult(result, part));
            } 

            //
            //  Adjust for the current partial month.
            // 
            result.month++;
            result.day = 1; 
 
            //
            //  Adjust the Lunar Month and Year (if necessary) based on the number 
            //  of days between 1/1 and the requested date.
            //
            //  Assumes Jan 1 can never translate to the last Lunar month, which
            //  is true. 
            //
            NumDays -= (long)(LunarMonthLen[hebrewYearType, lunarDate.month] - lunarDate.day); 
            Contract.Assert(NumDays >= 1, "NumDays >= 1"); 

            // If NumDays is 1, then we are done.  Otherwise, find the correct Hebrew month 
            // and day.
            if (NumDays > 1) {
                //
                //  See if we're on the correct Lunar month. 
                //
                while (NumDays > (long)(LunarMonthLen[hebrewYearType, result.month])) { 
                    // 
                    //  Adjust the number of days and move to the next month.
                    // 
                    NumDays -= (long)(LunarMonthLen[hebrewYearType, result.month++]);

                    //
                    //  See if we need to adjust the Year. 
                    //  Must handle both 12 and 13 month years.
                    // 
                    if ((result.month > 13) || (LunarMonthLen[hebrewYearType, result.month] == 0)) { 
                        //
                        //  Adjust the Year. 
                        //
                        result.year++;
                        hebrewYearType = HebrewTable[(gregorianYear + 1 - FirstGregorianTableYear) * 2 + 1];
 
                        //
                        //  Adjust the Month. 
                        // 
                        result.month = 1;
                    } 
                }
                //
                //  Found the right Lunar month.
                // 
                result.day += (int)(NumDays - 1);
            } 
            return (GetResult(result, part)); 
        }
Exemple #13
0
        /*=================================GetLunarMonthDay========================== 
        **Action: Using the Hebrew table (HebrewTable) to get the Hebrew month/day value for Gregorian January 1st 
        ** in a given Gregorian year.
        ** Greogrian January 1st falls usually in Tevet (4th month). Tevet has always 29 days. 
        **     That's why, there no nead to specify the lunar month in the table.  There are exceptions, and these
        **     are coded by giving numbers above 29 and below 1.
        **     Actual decoding is takenig place in the switch statement below.
        **Returns: 
        **     The Hebrew year type. The value is from 1 to 6.
        **     normal years : 1 = 353 days   2 = 354 days   3 = 355 days. 
        **     Leap years   : 4 = 383        5   384        6 = 385 days. 
        **Arguments:
        **      gregorianYear   The year value in Gregorian calendar.  The value should be between 1500 and 2239. 
        **      lunarDate       Object to take the result of the Hebrew year/month/day.
        **Exceptions:
        ============================================================================*/
 
        static internal int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate) {
            // 
            //  Get the offset into the LunarMonthLen array and the lunar day 
            //  for January 1st.
            // 
            int index = gregorianYear - FirstGregorianTableYear;
            if (index < 0 || index > TABLESIZE) {
                throw new ArgumentOutOfRangeException("gregorianYear");
            } 

            index *= 2; 
            lunarDate.day      = HebrewTable[index]; 

            // Get the type of the year. The value is from 1 to 6 
            int LunarYearType = HebrewTable[index + 1];

            //
            //  Get the Lunar Month. 
            //
            switch (lunarDate.day) { 
                case ( 0 ) :                   // 1/1 is on Shvat 1 
                    lunarDate.month = 5;
                    lunarDate.day = 1; 
                    break;
                case ( 30 ) :                  // 1/1 is on Kislev 30
                    lunarDate.month = 3;
                    break; 
                case ( 31 ) :                  // 1/1 is on Shvat 2
                    lunarDate.month = 5; 
                    lunarDate.day = 2; 
                    break;
                case ( 32 ) :                  // 1/1 is on Shvat 3 
                    lunarDate.month = 5;
                    lunarDate.day = 3;
                    break;
                case ( 33 ) :                  // 1/1 is on Kislev 29 
                    lunarDate.month = 3;
                    lunarDate.day = 29; 
                    break; 
                default :                      // 1/1 is on Tevet (This is the general case)
                    lunarDate.month = 4; 
                    break;
            }
            return (LunarYearType);
        } 
Exemple #14
0
        static internal int GetResult(__DateBuffer result, int part) {
            switch (part) {
                case DatePartYear: 
                    return (result.year);
                case DatePartMonth: 
                    return (result.month); 
                case DatePartDay:
                    return (result.day); 
            }

            throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DateTimeParsing"));
        } 
        static internal int GetResult(__DateBuffer result, int part)
        {
            switch (part)
            {
                case DatePartYear:
                    return (result.year);
                case DatePartMonth:
                    return (result.month);
                case DatePartDay:
                    return (result.day);
            }

            throw new InvalidOperationException(SR.InvalidOperation_DateTimeParsing);
        }
Exemple #16
0
        // Returns a given date part of this DateTime. This method is used
        // to compute the year, day-of-year, month, or day part.

        internal virtual int GetDatePart(long ticks, int part)
        {
            // The Gregorian year, month, day value for ticks.
            int  gregorianYear, gregorianMonth, gregorianDay;
            int  hebrewYearType;              // lunar year type
            long AbsoluteDate;                // absolute date - absolute date 1/1/1600

            //
            //  Make sure we have a valid Gregorian date that will fit into our
            //  Hebrew conversion limits.
            //
            CheckTicksRange(ticks);

            DateTime time = new DateTime(ticks);

            //
            //  Save the Gregorian date values.
            //
            time.GetDatePart(out gregorianYear, out gregorianMonth, out gregorianDay);

            __DateBuffer lunarDate = new __DateBuffer();    // lunar month and day for Jan 1

            // From the table looking-up value of HebrewTable[index] (stored in lunarDate.day), we get the the
            // lunar month and lunar day where the Gregorian date 1/1 falls.
            lunarDate.year = gregorianYear + HebrewYearOf1AD;
            hebrewYearType = GetLunarMonthDay(gregorianYear, lunarDate);

            // This is the buffer used to store the result Hebrew date.
            __DateBuffer result = new __DateBuffer();

            //
            //  Store the values for the start of the new year - 1/1.
            //
            result.year  = lunarDate.year;
            result.month = lunarDate.month;
            result.day   = lunarDate.day;

            //
            //  Get the absolute date from 1/1/1600.
            //
            AbsoluteDate = GregorianCalendar.GetAbsoluteDate(gregorianYear, gregorianMonth, gregorianDay);

            //
            //  If the requested date was 1/1, then we're done.
            //
            if ((gregorianMonth == 1) && (gregorianDay == 1))
            {
                return(GetResult(result, part));
            }

            //
            //  Calculate the number of days between 1/1 and the requested date.
            //
            long NumDays;                      // number of days since 1/1

            NumDays = AbsoluteDate - GregorianCalendar.GetAbsoluteDate(gregorianYear, 1, 1);

            //
            //  If the requested date is within the current lunar month, then
            //  we're done.
            //
            if ((NumDays + (long)lunarDate.day) <= (long)(s_lunarMonthLen[hebrewYearType * MaxMonthPlusOne + lunarDate.month]))
            {
                result.day += (int)NumDays;
                return(GetResult(result, part));
            }

            //
            //  Adjust for the current partial month.
            //
            result.month++;
            result.day = 1;

            //
            //  Adjust the Lunar Month and Year (if necessary) based on the number
            //  of days between 1/1 and the requested date.
            //
            //  Assumes Jan 1 can never translate to the last Lunar month, which
            //  is true.
            //
            NumDays -= (long)(s_lunarMonthLen[hebrewYearType * MaxMonthPlusOne + lunarDate.month] - lunarDate.day);
            Debug.Assert(NumDays >= 1, "NumDays >= 1");

            // If NumDays is 1, then we are done.  Otherwise, find the correct Hebrew month
            // and day.
            if (NumDays > 1)
            {
                //
                //  See if we're on the correct Lunar month.
                //
                while (NumDays > (long)(s_lunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month]))
                {
                    //
                    //  Adjust the number of days and move to the next month.
                    //
                    NumDays -= (long)(s_lunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month++]);

                    //
                    //  See if we need to adjust the Year.
                    //  Must handle both 12 and 13 month years.
                    //
                    if ((result.month > 13) || (s_lunarMonthLen[hebrewYearType * MaxMonthPlusOne + result.month] == 0))
                    {
                        //
                        //  Adjust the Year.
                        //
                        result.year++;
                        hebrewYearType = s_hebrewTable[(gregorianYear + 1 - FirstGregorianTableYear) * 2 + 1];

                        //
                        //  Adjust the Month.
                        //
                        result.month = 1;
                    }
                }
                //
                //  Found the right Lunar month.
                //
                result.day += (int)(NumDays - 1);
            }
            return(GetResult(result, part));
        }
Exemple #17
0
        /*=================================HebrewToGregorian==========================
        **Action: Convert Hebrew date to Gregorian date. 
        **Returns: 
        **Arguments:
        **Exceptions: 
        **  The algorithm is like this:
        **      The hebrew year has an offset to the Gregorian year, so we can guess the Gregorian year for
        **      the specified Hebrew year.  That is, GreogrianYear = HebrewYear - FirstHebrewYearOf1AD.
        ** 
        **      From the Gregorian year and HebrewTable, we can get the Hebrew month/day value
        **      of the Gregorian date January 1st.  Let's call this month/day value [hebrewDateForJan1] 
        ** 
        **      If the requested Hebrew month/day is less than [hebrewDateForJan1], we know the result
        **      Gregorian date falls in previous year.  So we decrease the Gregorian year value, and 
        **      retrieve the Hebrew month/day value of the Gregorian date january 1st again.
        **
        **      Now, we get the answer of the Gregorian year.
        ** 
        **      The next step is to get the number of days between the requested Hebrew month/day
        **      and [hebrewDateForJan1].  When we get that, we can create the DateTime by adding/subtracting 
        **      the ticks value of the number of days. 
        **
        ============================================================================*/ 


        static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond) {
            // Get the rough Gregorian year for the specified hebrewYear. 
            //
            int gregorianYear = hebrewYear - HebrewYearOf1AD; 
 
            __DateBuffer hebrewDateOfJan1 = new __DateBuffer(); // year value is unused.
            int lunarYearType = GetLunarMonthDay(gregorianYear, hebrewDateOfJan1); 

            if ((hebrewMonth == hebrewDateOfJan1.month) && (hebrewDay == hebrewDateOfJan1.day)) {
                return (new DateTime(gregorianYear, 1, 1, hour, minute, second, millisecond));
            } 

            int days = GetDayDifference(lunarYearType, hebrewMonth, hebrewDay, hebrewDateOfJan1.month, hebrewDateOfJan1.day); 
 
            DateTime gregorianNewYear = new DateTime(gregorianYear, 1, 1);
            return (new DateTime(gregorianNewYear.Ticks + days * TicksPerDay 
                + TimeToTicks(hour, minute, second, millisecond)));
        }