System.Globalization.HebrewCalendar.GetLunarMonthDay C# (CSharp) Method

GetLunarMonthDay() private method

private GetLunarMonthDay ( int gregorianYear, __DateBuffer lunarDate ) : int
gregorianYear int
lunarDate __DateBuffer
return int
        internal int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate) {
            //
            //  Get the offset into the m_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      = m_HebrewTable[index];

            // Get the type of the year. The value is from 1 to 6
            int LunarYearType = m_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);
        }

Usage Example

Example #1
0
        internal virtual int GetDatePart(long ticks, int part)
        {
            HebrewCalendar.CheckTicksRange(ticks);
            DateTime dateTime = new DateTime(ticks);
            int      year     = dateTime.Year;
            int      month    = dateTime.Month;
            int      day      = dateTime.Day;

            HebrewCalendar.__DateBuffer lunarDate = new HebrewCalendar.__DateBuffer();
            lunarDate.year = year + 3760;
            int index1 = HebrewCalendar.GetLunarMonthDay(year, lunarDate);

            HebrewCalendar.__DateBuffer result = new HebrewCalendar.__DateBuffer();
            result.year  = lunarDate.year;
            result.month = lunarDate.month;
            result.day   = lunarDate.day;
            long absoluteDate = GregorianCalendar.GetAbsoluteDate(year, month, day);

            if (month == 1 && day == 1)
            {
                return(HebrewCalendar.GetResult(result, part));
            }
            long num1 = absoluteDate - GregorianCalendar.GetAbsoluteDate(year, 1, 1);

            if (num1 + (long)lunarDate.day <= (long)HebrewCalendar.LunarMonthLen[index1, lunarDate.month])
            {
                result.day += (int)num1;
                return(HebrewCalendar.GetResult(result, part));
            }
            ++result.month;
            result.day = 1;
            long num2 = num1 - (long)(HebrewCalendar.LunarMonthLen[index1, lunarDate.month] - lunarDate.day);

            if (num2 > 1L)
            {
                while (num2 > (long)HebrewCalendar.LunarMonthLen[index1, result.month])
                {
                    long num3 = num2;
                    int[,] numArray = HebrewCalendar.LunarMonthLen;
                    int index2 = index1;
                    HebrewCalendar.__DateBuffer dateBuffer = result;
                    int num4 = dateBuffer.month;
                    int num5 = num4 + 1;
                    dateBuffer.month = num5;
                    int  index3 = num4;
                    long num6   = (long)numArray[index2, index3];
                    num2 = num3 - num6;
                    if (result.month > 13 || HebrewCalendar.LunarMonthLen[index1, result.month] == 0)
                    {
                        ++result.year;
                        index1       = HebrewCalendar.HebrewTable[(year + 1 - 1583) * 2 + 1];
                        result.month = 1;
                    }
                }
                result.day += (int)(num2 - 1L);
            }
            return(HebrewCalendar.GetResult(result, part));
        }
All Usage Examples Of System.Globalization.HebrewCalendar::GetLunarMonthDay