GetLunarMonthDay() private method

private GetLunarMonthDay ( int gregorianYear, __DateBuffer lunarDate ) : int
gregorianYear int
lunarDate __DateBuffer
return int
Esempio n. 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));
        }
Esempio n. 2
0
        private static DateTime HebrewToGregorian(int hebrewYear, int hebrewMonth, int hebrewDay, int hour, int minute, int second, int millisecond)
        {
            int num = hebrewYear - 3760;

            HebrewCalendar.__DateBuffer lunarDate = new HebrewCalendar.__DateBuffer();
            int lunarMonthDay = HebrewCalendar.GetLunarMonthDay(num, lunarDate);

            if (hebrewMonth == lunarDate.month && hebrewDay == lunarDate.day)
            {
                return(new DateTime(num, 1, 1, hour, minute, second, millisecond));
            }
            int dayDifference = HebrewCalendar.GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, lunarDate.month, lunarDate.day);

            return(new DateTime(new DateTime(num, 1, 1).Ticks + (long)dayDifference * 864000000000L + Calendar.TimeToTicks(hour, minute, second, millisecond)));
        }