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)); }
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))); }
internal static int GetResult(HebrewCalendar.__DateBuffer result, int part) { switch (part) { case 0: return(result.year); case 2: return(result.month); case 3: return(result.day); default: throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_DateTimeParsing")); } }
internal static int GetLunarMonthDay(int gregorianYear, HebrewCalendar.__DateBuffer lunarDate) { int num1 = gregorianYear - 1583; if (num1 < 0 || num1 > 656) { throw new ArgumentOutOfRangeException("gregorianYear"); } int index = num1 * 2; lunarDate.day = HebrewCalendar.HebrewTable[index]; int num2 = HebrewCalendar.HebrewTable[index + 1]; switch (lunarDate.day) { case 0: lunarDate.month = 5; lunarDate.day = 1; break; case 30: lunarDate.month = 3; break; case 31: lunarDate.month = 5; lunarDate.day = 2; break; case 32: lunarDate.month = 5; lunarDate.day = 3; break; case 33: lunarDate.month = 3; lunarDate.day = 29; break; default: lunarDate.month = 4; break; } return(num2); }