We need you! We're working hard on the next version of Developer Fusion -
Let us know what you think we should be up to!
- namespace System.Globalization
- {
- using System;
- using System.Text;
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ////////////////////////////////////////////////////////////////////////////
-
-
-
-
-
-
- [Serializable()]
- [System.Runtime.InteropServices.ComVisible(true)]
- public class HebrewCalendar : Calendar
- {
-
-
- public static readonly int HebrewEra = 1;
-
- internal const int DatePartYear = 0;
- internal const int DatePartDayOfYear = 1;
- internal const int DatePartMonth = 2;
- internal const int DatePartDay = 3;
- internal const int DatePartDayOfWeek = 4;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- private const int HebrewYearOf1AD = 3760;
-
-
- private const int FirstGregorianTableYear = 1583;
-
-
- private const int LastGregorianTableYear = 2239;
-
- private const int TABLESIZE = (LastGregorianTableYear - FirstGregorianTableYear);
-
- private const int m_minHebrewYear = HebrewYearOf1AD + FirstGregorianTableYear;
-
- private const int m_maxHebrewYear = HebrewYearOf1AD + LastGregorianTableYear;
-
- private static readonly int[] m_HebrewTable = {7, 3, 17, 3, 0, 4, 11, 2, 21, 6,
- 1, 3, 13, 2, 25, 4, 5, 3, 16, 2,
- 27, 6, 9, 1, 20, 2, 0, 6, 11, 3,
- 23, 4, 4, 2, 14, 3, 27, 4, 8, 2,
- 18, 3, 28, 6, 11, 1, 22, 5, 2, 3,
- 12, 3, 25, 4, 6, 2, 16, 3, 26, 6,
- 8, 2, 20, 1, 0, 6, 11, 2, 24, 4,
- 4, 3, 15, 2, 25, 6, 8, 1, 19, 2,
- 29, 6, 9, 3, 22, 4, 3, 2, 13, 3,
- 25, 4, 6, 3, 17, 2, 27, 6, 7, 3,
- 19, 2, 31, 4, 11, 3, 23, 4, 5, 2,
- 15, 3, 25, 6, 6, 2, 19, 1, 29, 6,
- 10, 2, 22, 4, 3, 3, 14, 2, 24, 6,
- 6, 1, 17, 3, 28, 5, 8, 3, 20, 1,
- 32, 5, 12, 3, 22, 6, 4, 1, 16, 2,
- 26, 6, 6, 3, 17, 2, 0, 4, 10, 3,
- 22, 4, 3, 2, 14, 3, 24, 6, 5, 2,
- 17, 1, 28, 6, 9, 2, 19, 3, 31, 4,
- 13, 2, 23, 6, 3, 3, 15, 1, 27, 5,
- 7, 3, 17, 3, 29, 4, 11, 2, 21, 6,
- 3, 1, 14, 2, 25, 6, 5, 3, 16, 2,
- 28, 4, 9, 3, 20, 2, 0, 6, 12, 1,
- 23, 6, 4, 2, 14, 3, 26, 4, 8, 2,
- 18, 3, 0, 4, 10, 3, 21, 5, 1, 3,
- 13, 1, 24, 5, 5, 3, 15, 3, 27, 4,
- 8, 2, 19, 3, 29, 6, 10, 2, 22, 4,
- 3, 3, 14, 2, 26, 4, 6, 3, 18, 2,
- 28, 6, 10, 1, 20, 6, 2, 2, 12, 3,
- 24, 4, 5, 2, 16, 3, 28, 4, 8, 3,
- 19, 2, 0, 6, 12, 1, 23, 5, 3, 3,
- 14, 3, 26, 4, 7, 2, 17, 3, 28, 6,
- 9, 2, 21, 4, 1, 3, 13, 2, 25, 4,
- 5, 3, 16, 2, 27, 6, 9, 1, 19, 3,
- 0, 5, 11, 3, 23, 4, 4, 2, 14, 3,
- 25, 6, 7, 1, 18, 2, 28, 6, 9, 3,
- 21, 4, 2, 2, 12, 3, 25, 4, 6, 2,
- 16, 3, 26, 6, 8, 2, 20, 1, 0, 6,
- 11, 2, 22, 6, 4, 1, 15, 2, 25, 6,
- 6, 3, 18, 1, 29, 5, 9, 3, 22, 4,
- 2, 3, 13, 2, 23, 6, 4, 3, 15, 2,
- 27, 4, 7, 3, 19, 2, 31, 4, 11, 3,
- 21, 6, 3, 2, 15, 1, 25, 6, 6, 2,
- 17, 3, 29, 4, 10, 2, 20, 6, 3, 1,
- 13, 3, 24, 5, 4, 3, 16, 1, 27, 5,
- 7, 3, 17, 3, 0, 4, 11, 2, 21, 6,
- 1, 3, 13, 2, 25, 4, 5, 3, 16, 2,
- 29, 4, 9, 3, 19, 6, 30, 2, 13, 1,
- 23, 6, 4, 2, 14, 3, 27, 4, 8, 2,
- 18, 3, 0, 4, 11, 3, 22, 5, 2, 3,
- 14, 1, 26, 5, 6, 3, 16, 3, 28, 4,
- 10, 2, 20, 6, 30, 3, 11, 2, 24, 4,
- 4, 3, 15, 2, 25, 6, 8, 1, 19, 2,
- 29, 6, 9, 3, 22, 4, 3, 2, 13, 3,
- 25, 4, 7, 2, 17, 3, 27, 6, 9, 1,
- 21, 5, 1, 3, 11, 3, 23, 4, 5, 2,
- 15, 3, 25, 6, 6, 2, 19, 1, 29, 6,
- 10, 2, 22, 4, 3, 3, 14, 2, 24, 6,
- 6, 1, 18, 2, 28, 6, 8, 3, 20, 4,
- 2, 2, 12, 3, 24, 4, 4, 3, 16, 2,
- 26, 6, 6, 3, 17, 2, 0, 4, 10, 3,
- 22, 4, 3, 2, 14, 3, 24, 6, 5, 2,
- 17, 1, 28, 6, 9, 2, 21, 4, 1, 3,
- 13, 2, 23, 6, 5, 1, 15, 3, 27, 5,
- 7, 3, 19, 1, 0, 5, 10, 3, 22, 4,
- 2, 3, 13, 2, 24, 6, 4, 3, 15, 2,
- 27, 4, 8, 3, 20, 4, 1, 2, 11, 3,
- 22, 6, 3, 2, 15, 1, 25, 6, 7, 2,
- 17, 3, 29, 4, 10, 2, 21, 6, 1, 3,
- 13, 1, 24, 5, 5, 3, 15, 3, 27, 4,
- 8, 2, 19, 6, 1, 1, 12, 2, 22, 6,
- 3, 3, 14, 2, 26, 4, 6, 3, 18, 2,
- 28, 6, 10, 1, 20, 6, 2, 2, 12, 3,
- 24, 4, 5, 2, 16, 3, 28, 4, 9, 2,
- 19, 6, 30, 3, 12, 1, 23, 5, 3, 3,
- 14, 3, 26, 4, 7, 2, 17, 3, 28, 6,
- 9, 2, 21, 4, 1, 3, 13, 2, 25, 4,
- 5, 3, 16, 2, 27, 6, 9, 1, 19, 6,
- 30, 2, 11, 3, 23, 4, 4, 2, 14, 3,
- 27, 4, 7, 3, 18, 2, 28, 6, 11, 1,
- 22, 5, 2, 3, 12, 3, 25, 4, 6, 2,
- 16, 3, 26, 6, 8, 2, 20, 4, 30, 3,
- 11, 2, 24, 4, 4, 3, 15, 2, 25, 6,
- 8, 1, 18, 3, 29, 5, 9, 3, 22, 4,
- 3, 2, 13, 3, 23, 6, 6, 1, 17, 2,
- 27, 6, 7, 3, 20, 4, 1, 2, 11, 3,
- 23, 4, 5, 2, 15, 3, 25, 6, 6, 2,
- 19, 1, 29, 6, 10, 2, 20, 6, 3, 1,
- 14, 2, 24, 6, 4, 3, 17, 1, 28, 5,
- 8, 3, 20, 4, 1, 3, 12, 2, 22, 6,
- 2, 3, 14, 2, 26, 4, 6, 3, 17, 2,
- 0, 4, 10, 3, 20, 6, 1, 2, 14, 1,
- 24, 6, 5, 2, 15, 3, 28, 4, 9, 2,
- 19, 6, 1, 1, 12, 3, 23, 5, 3, 3,
- 15, 1, 27, 5, 7, 3, 17, 3, 29, 4,
- 11, 2, 21, 6, 1, 3, 12, 2, 25, 4,
- 5, 3, 16, 2, 28, 4, 9, 3, 19, 6,
- 30, 2, 12, 1, 23, 6, 4, 2, 14, 3,
- 26, 4, 8, 2, 18, 3, 0, 4, 10, 3,
- 22, 5, 2, 3, 14, 1, 25, 5, 6, 3,
- 16, 3, 28, 4, 9, 2, 20, 6, 30, 3,
- 11, 2, 23, 4, 4, 3, 15, 2, 27, 4,
- 7, 3, 19, 2, 29, 6, 11, 1, 21, 6,
- 3, 2, 13, 3, 25, 4, 6, 2, 17, 3,
- 27, 6, 9, 1, 20, 5, 30, 3, 10, 3,
- 22, 4, 3, 2, 14, 3, 24, 6, 5, 2,
- 17, 1, 28, 6, 9, 2, 21, 4, 1, 3,
- 13, 2, 23, 6, 5, 1, 16, 2, 27, 6,
- 7, 3, 19, 4, 30, 2, 11, 3, 23, 4,
- 3, 3, 14,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static readonly int[,] m_lunarMonthLen = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0}, {0, 30, 29, 29, 29, 30, 29, 30, 29, 30,
- 29, 30, 29, 0}, {0, 30, 29, 30, 29, 30, 29, 30, 29, 30,
- 29, 30, 29, 0}, {0, 30, 30, 30, 29, 30, 29, 30, 29, 30,
- 29, 30, 29, 0}, {0, 30, 29, 29, 29, 30, 30, 29, 30, 29,
- 30, 29, 30, 29}, {0, 30, 29, 30, 29, 30, 30, 29, 30, 29,
- 30, 29, 30, 29}, {0, 30, 30, 30, 29, 30, 30, 29, 30, 29,
-
-
- 30, 29, 30, 29}};
-
-
-
- static internal readonly DateTime calendarMinValue = new DateTime(1583, 1, 1);
-
-
- static internal readonly DateTime calendarMaxValue = new DateTime((new DateTime(2239, 9, 29, 23, 59, 59, 999)).Ticks + 9999);
-
-
-
- public override DateTime MinSupportedDateTime {
- get { return (calendarMinValue); }
- }
-
-
-
- public override DateTime MaxSupportedDateTime {
- get { return (calendarMaxValue); }
- }
-
-
-
-
-
-
- public override CalendarAlgorithmType AlgorithmType {
- get { return CalendarAlgorithmType.LunisolarCalendar; }
- }
-
-
-
-
-
-
-
-
- public HebrewCalendar()
- {
- }
-
- internal override int ID {
- get { return (CAL_HEBREW); }
- }
-
-
-
-
- private void CheckHebrewYearValue(int y, int era, string varName)
- {
- CheckEraRange(era);
- if (y > m_maxHebrewYear || y < m_minHebrewYear) {
- throw new ArgumentOutOfRangeException(varName, String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), m_minHebrewYear, m_maxHebrewYear));
- }
- }
-
-
-
- private void CheckHebrewMonthValue(int year, int month, int era)
- {
- int monthsInYear = GetMonthsInYear(year, era);
- if (month < 1 || month > monthsInYear) {
- throw new ArgumentOutOfRangeException("month", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, monthsInYear));
- }
- }
-
-
-
- private void CheckHebrewDayValue(int year, int month, int day, int era)
- {
- int daysInMonth = GetDaysInMonth(year, month, era);
- if (day < 1 || day > daysInMonth) {
- throw new ArgumentOutOfRangeException("day", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, daysInMonth));
- }
- }
-
- internal void CheckEraRange(int era)
- {
- if (era != CurrentEra && era != HebrewEra) {
- throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"));
- }
- }
-
- private void CheckTicksRange(long ticks)
- {
- if (ticks < calendarMinValue.Ticks || ticks > calendarMaxValue.Ticks) {
-
- throw new ArgumentOutOfRangeException("time", String.Format(CultureInfo.InvariantCulture, Environment.GetResourceString("ArgumentOutOfRange_CalendarRange"), calendarMinValue, calendarMaxValue));
- }
- }
-
- 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"));
- }
-
-
-
- internal int GetLunarMonthDay(int gregorianYear, __DateBuffer lunarDate)
- {
-
-
-
-
- int index = gregorianYear - FirstGregorianTableYear;
- if (index < 0 || index > TABLESIZE) {
- throw new ArgumentOutOfRangeException("gregorianYear");
- }
-
- index *= 2;
- lunarDate.day = m_HebrewTable[index];
-
-
- int LunarYearType = m_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 (LunarYearType);
- }
-
-
-
-
- internal virtual int GetDatePart(long ticks, int part)
- {
-
- int gregorianYear;
- int gregorianMonth;
- int gregorianDay;
- int hebrewYearType;
-
- long AbsoluteDate;
-
-
-
-
-
- CheckTicksRange(ticks);
-
- DateTime time = new DateTime(ticks);
-
-
-
-
- gregorianYear = time.Year;
- gregorianMonth = time.Month;
- gregorianDay = time.Day;
-
- __DateBuffer lunarDate = new __DateBuffer();
-
-
-
- lunarDate.year = gregorianYear + HebrewYearOf1AD;
- hebrewYearType = GetLunarMonthDay(gregorianYear, lunarDate);
-
-
- __DateBuffer result = new __DateBuffer();
-
-
-
-
- result.year = lunarDate.year;
- result.month = lunarDate.month;
- result.day = lunarDate.day;
-
-
-
-
- AbsoluteDate = GregorianCalendar.GetAbsoluteDate(gregorianYear, gregorianMonth, gregorianDay);
-
-
-
-
- if ((gregorianMonth == 1) && (gregorianDay == 1)) {
- return (GetResult(result, part));
- }
-
-
-
-
- long NumDays;
-
- NumDays = AbsoluteDate - GregorianCalendar.GetAbsoluteDate(gregorianYear, 1, 1);
-
-
-
-
-
- if ((NumDays + (long)lunarDate.day) <= (long)(m_lunarMonthLen[hebrewYearType, lunarDate.month])) {
- result.day += (int)NumDays;
- return (GetResult(result, part));
- }
-
-
-
-
- result.month++;
- result.day = 1;
-
-
-
-
-
-
-
-
- NumDays -= (long)(m_lunarMonthLen[hebrewYearType, lunarDate.month] - lunarDate.day);
- BCLDebug.Assert(NumDays >= 1, "NumDays >= 1");
-
-
-
- if (NumDays > 1) {
-
-
-
- while (NumDays > (long)(m_lunarMonthLen[hebrewYearType, result.month])) {
-
-
-
- NumDays -= (long)(m_lunarMonthLen[hebrewYearType, result.month++]);
-
-
-
-
-
- if ((result.month > 13) || (m_lunarMonthLen[hebrewYearType, result.month] == 0)) {
-
-
-
- result.year++;
- hebrewYearType = m_HebrewTable[(gregorianYear + 1 - FirstGregorianTableYear) * 2 + 1];
-
-
-
-
- result.month = 1;
- }
- }
-
-
-
- result.day += (int)(NumDays - 1);
- }
- return (GetResult(result, part));
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public override DateTime AddMonths(DateTime time, int months)
- {
- try {
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
-
-
- int monthsInYear;
- int i;
- if (months >= 0) {
- i = m + months;
- while (i > (monthsInYear = GetMonthsInYear(y, CurrentEra))) {
- y++;
- i -= monthsInYear;
- }
- }
- else {
- if ((i = m + months) <= 0) {
- months = -months;
- months -= m;
- y--;
-
- while (months > (monthsInYear = GetMonthsInYear(y, CurrentEra))) {
- y--;
- months -= monthsInYear;
- }
- monthsInYear = GetMonthsInYear(y, CurrentEra);
- i = monthsInYear - months;
- }
- }
-
- int days = GetDaysInMonth(y, i);
- if (d > days) {
- d = days;
- }
- return (new DateTime(ToDateTime(y, i, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay)));
- }
-
-
- catch (ArgumentException) {
- throw new ArgumentOutOfRangeException("months", String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_AddValue")));
- }
- }
-
-
-
-
-
-
-
-
-
-
- public override DateTime AddYears(DateTime time, int years)
- {
- int y = GetDatePart(time.Ticks, DatePartYear);
- int m = GetDatePart(time.Ticks, DatePartMonth);
- int d = GetDatePart(time.Ticks, DatePartDay);
-
- y += years;
- CheckHebrewYearValue(y, Calendar.CurrentEra, "years");
-
- int months = GetMonthsInYear(y, CurrentEra);
- if (m > months) {
- m = months;
- }
-
- int days = GetDaysInMonth(y, m);
- if (d > days) {
- d = days;
- }
-
- long ticks = ToDateTime(y, m, d, 0, 0, 0, 0).Ticks + (time.Ticks % TicksPerDay);
- Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
- return (new DateTime(ticks));
- }
-
-
-
-
-
- public override int GetDayOfMonth(DateTime time)
- {
- return (GetDatePart(time.Ticks, DatePartDay));
- }
-
-
-
-
-
-
-
- public override DayOfWeek GetDayOfWeek(DateTime time)
- {
-
-
- return ((DayOfWeek)((int)(time.Ticks / TicksPerDay + 1) % 7));
- }
-
- internal int GetHebrewYearType(int year, int era)
- {
- CheckHebrewYearValue(year, era, "year");
-
-
- return (m_HebrewTable[(year - HebrewYearOf1AD - FirstGregorianTableYear) * 2 + 1]);
- }
-
-
-
-
-
- public override int GetDayOfYear(DateTime time)
- {
-
- int year = GetYear(time);
- DateTime beginOfYearDate = ToDateTime(year, 1, 1, 0, 0, 0, 0, CurrentEra);
- return ((int)((time.Ticks - beginOfYearDate.Ticks) / TicksPerDay) + 1);
- }
-
-
-
-
-
- public override int GetDaysInMonth(int year, int month, int era)
- {
- &nb