10 internal class __DateBuffer
22 internal const int DatePartYear = 0;
24 internal const int DatePartDayOfYear = 1;
26 internal const int DatePartMonth = 2;
28 internal const int DatePartDay = 3;
30 internal const int DatePartDayOfWeek = 4;
32 private const int HebrewYearOf1AD = 3760;
34 private const int FirstGregorianTableYear = 1583;
36 private const int LastGregorianTableYear = 2239;
38 private const int TABLESIZE = 656;
40 private const int MinHebrewYear = 5343;
42 private const int MaxHebrewYear = 5999;
44 private static readonly
int[] HebrewTable =
new int[1316]
1364 private static readonly
int[,] LunarMonthLen =
new int[7, 14]
1480 internal static readonly
DateTime calendarMinValue =
new DateTime(1583, 1, 1);
1482 internal static readonly
DateTime calendarMaxValue =
new DateTime(
new DateTime(2239, 9, 29, 23, 59, 59, 999).Ticks + 9999);
1484 private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 5790;
1498 internal override int ID => 8;
1502 public override int[]
Eras =>
new int[1]
1515 if (twoDigitYearMax == -1)
1517 twoDigitYearMax =
Calendar.GetSystemTwoDigitYearSetting(ID, 5790);
1519 return twoDigitYearMax;
1526 CheckHebrewYearValue(value,
HebrewEra,
"value");
1528 twoDigitYearMax = value;
1532 private static void CheckHebrewYearValue(
int y,
int era,
string varName)
1535 if (y > 5999 || y < 5343)
1541 private void CheckHebrewMonthValue(
int year,
int month,
int era)
1544 if (month < 1 || month > monthsInYear)
1546 throw new ArgumentOutOfRangeException(
"month",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, monthsInYear));
1550 private void CheckHebrewDayValue(
int year,
int month,
int day,
int era)
1553 if (day < 1 || day > daysInMonth)
1555 throw new ArgumentOutOfRangeException(
"day",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, daysInMonth));
1559 internal static void CheckEraRange(
int era)
1563 throw new ArgumentOutOfRangeException(
"era", Environment.GetResourceString(
"ArgumentOutOfRange_InvalidEraValue"));
1567 private static void CheckTicksRange(
long ticks)
1569 if (ticks < calendarMinValue.Ticks || ticks > calendarMaxValue.Ticks)
1571 throw new ArgumentOutOfRangeException(
"time",
string.
Format(CultureInfo.InvariantCulture, Environment.GetResourceString(
"ArgumentOutOfRange_CalendarRange"), calendarMinValue, calendarMaxValue));
1575 internal static int GetResult(__DateBuffer result,
int part)
1582 return result.month;
1586 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_DateTimeParsing"));
1590 internal static int GetLunarMonthDay(
int gregorianYear, __DateBuffer lunarDate)
1592 int num = gregorianYear - 1583;
1593 if (num < 0 || num > 656)
1595 throw new ArgumentOutOfRangeException(
"gregorianYear");
1598 lunarDate.day = HebrewTable[num];
1599 int result = HebrewTable[num + 1];
1600 switch (lunarDate.day)
1603 lunarDate.month = 5;
1607 lunarDate.month = 3;
1610 lunarDate.month = 5;
1614 lunarDate.month = 5;
1618 lunarDate.month = 3;
1622 lunarDate.month = 4;
1628 internal virtual int GetDatePart(
long ticks,
int part)
1630 CheckTicksRange(ticks);
1632 int year = dateTime.Year;
1633 int month = dateTime.Month;
1634 int day = dateTime.Day;
1635 __DateBuffer _DateBuffer =
new __DateBuffer();
1636 _DateBuffer.year = year + 3760;
1637 int num = GetLunarMonthDay(year, _DateBuffer);
1638 __DateBuffer _DateBuffer2 =
new __DateBuffer();
1639 _DateBuffer2.year = _DateBuffer.year;
1640 _DateBuffer2.month = _DateBuffer.month;
1641 _DateBuffer2.day = _DateBuffer.day;
1642 long absoluteDate = GregorianCalendar.GetAbsoluteDate(year, month, day);
1643 if (month == 1 && day == 1)
1645 return GetResult(_DateBuffer2, part);
1647 long num2 = absoluteDate - GregorianCalendar.GetAbsoluteDate(year, 1, 1);
1648 if (num2 + _DateBuffer.day <= LunarMonthLen[num, _DateBuffer.month])
1650 _DateBuffer2.day += (int)num2;
1651 return GetResult(_DateBuffer2, part);
1653 _DateBuffer2.month++;
1654 _DateBuffer2.day = 1;
1655 num2 -= LunarMonthLen[num, _DateBuffer.month] - _DateBuffer.day;
1658 while (num2 > LunarMonthLen[num, _DateBuffer2.month])
1660 num2 -= LunarMonthLen[num, _DateBuffer2.month++];
1661 if (_DateBuffer2.month > 13 || LunarMonthLen[num, _DateBuffer2.month] == 0)
1663 _DateBuffer2.year++;
1664 num = HebrewTable[(year + 1 - 1583) * 2 + 1];
1665 _DateBuffer2.month = 1;
1668 _DateBuffer2.day += (int)(num2 - 1);
1670 return GetResult(_DateBuffer2, part);
1684 int num = GetDatePart(time.
Ticks, 0);
1685 int datePart = GetDatePart(time.
Ticks, 2);
1686 int num2 = GetDatePart(time.
Ticks, 3);
1691 for (num3 = datePart + months; num3 > (monthsInYear =
GetMonthsInYear(num, 0)); num3 -= monthsInYear)
1696 else if ((num3 = datePart + months) <= 0)
1705 months -= monthsInYear;
1708 num3 = monthsInYear - months;
1711 if (num2 > daysInMonth)
1730 int datePart = GetDatePart(time.
Ticks, 0);
1731 int num = GetDatePart(time.
Ticks, 2);
1732 int num2 = GetDatePart(time.
Ticks, 3);
1734 CheckHebrewYearValue(datePart, 0,
"years");
1736 if (num > monthsInYear)
1741 if (num2 > daysInMonth)
1755 return GetDatePart(time.
Ticks, 3);
1766 internal static int GetHebrewYearType(
int year,
int era)
1768 CheckHebrewYearValue(year, era,
"year");
1769 return HebrewTable[(year - 3760 - 1583) * 2 + 1];
1781 return (
int)((time.
Ticks - dateTime.
Ticks) / 864000000000
L) + 1;
1794 int hebrewYearType = GetHebrewYearType(year, era);
1795 CheckHebrewMonthValue(year, month, era);
1796 int num = LunarMonthLen[hebrewYearType, month];
1813 int hebrewYearType = GetHebrewYearType(year, era);
1814 if (hebrewYearType < 4)
1816 return 352 + hebrewYearType;
1818 return 382 + (hebrewYearType - 3);
1836 return GetDatePart(time.
Ticks, 2);
1861 return GetDatePart(time.
Ticks, 0);
1873 public override bool IsLeapDay(
int year,
int month,
int day,
int era)
1877 CheckHebrewDayValue(year, month, day, era);
1880 if (
IsLeapYear(year, 0) && month == 6 && day == 30)
1884 CheckHebrewDayValue(year, month, day, era);
1915 CheckHebrewMonthValue(year, month, era);
1916 if (flag && month == 7)
1932 CheckHebrewYearValue(year, era,
"year");
1933 return (7
L * (
long)year + 1) % 19 < 7;
1936 private static int GetDayDifference(
int lunarYearType,
int month1,
int day1,
int month2,
int day2)
1938 if (month1 == month2)
1942 bool flag = month1 > month2;
1952 int num3 = LunarMonthLen[lunarYearType, month1] - day1;
1954 while (month1 < month2)
1956 num3 += LunarMonthLen[lunarYearType, month1++];
1966 private static DateTime HebrewToGregorian(
int hebrewYear,
int hebrewMonth,
int hebrewDay,
int hour,
int minute,
int second,
int millisecond)
1968 int num = hebrewYear - 3760;
1969 __DateBuffer _DateBuffer =
new __DateBuffer();
1970 int lunarMonthDay = GetLunarMonthDay(num, _DateBuffer);
1971 if (hebrewMonth == _DateBuffer.month && hebrewDay == _DateBuffer.day)
1973 return new DateTime(num, 1, 1, hour, minute, second, millisecond);
1975 int dayDifference = GetDayDifference(lunarMonthDay, hebrewMonth, hebrewDay, _DateBuffer.month, _DateBuffer.day);
1976 return new DateTime(
new DateTime(num, 1, 1).Ticks + dayDifference * 864000000000L +
Calendar.TimeToTicks(hour, minute, second, millisecond));
1995 public override DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era)
1997 CheckHebrewYearValue(year, era,
"year");
1998 CheckHebrewMonthValue(year, month, era);
1999 CheckHebrewDayValue(year, month, day, era);
2000 DateTime result = HebrewToGregorian(year, month, day, hour, minute, second, millisecond);
2001 CheckTicksRange(result.
Ticks);
2019 return base.ToFourDigitYear(year);
2021 if (year > 5999 || year < 5343)
override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
Returns a T:System.DateTime that is set to the specified date and time in the specified era.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
override bool IsLeapMonth(int year, int month, int era)
Determines whether the specified month in the specified year in the specified era is a leap month.
Represents time in divisions, such as weeks, months, and years.
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime.
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
override DateTime AddMonths(DateTime time, int months)
Returns a T:System.DateTime that is the specified number of months away from the specified T:System....
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year in the specified era.
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
static readonly int HebrewEra
Represents the current era. This field is constant.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Calendar()
Initializes a new instance of the T:System.Globalization.Calendar class.
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date in the specified era is a leap day.
A type representing a date and time value.
override int [] Eras
Gets the list of eras in the T:System.Globalization.HebrewCalendar.
Provides information about, and means to manipulate, the current environment and platform....
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.HebrewCalendar type.
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
Format character that affects the layout of text or the operation of text processes,...
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.
override int GetDaysInMonth(int year, int month, int era)
Returns the number of days in the specified month in the specified year in the specified era.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.HebrewCalendar type.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime value.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
Specifies that the class can be serialized.
override DateTime AddYears(DateTime time, int years)
Returns a T:System.DateTime that is the specified number of years away from the specified T:System....
Represents the Hebrew calendar.
Provides information about a specific culture (called a locale for unmanaged code development)....
DayOfWeek
Specifies the day of the week.
override int ToFourDigitYear(int year)
Converts the specified year to a 4-digit year by using the P:System.Globalization....
long Ticks
Gets the number of ticks that represent the date and time of this instance.
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.