15 internal const int DatePartYear = 0;
17 internal const int DatePartDayOfYear = 1;
19 internal const int DatePartMonth = 2;
21 internal const int DatePartDay = 3;
23 internal const int MinAdvancedHijri = -2;
25 internal const int MaxAdvancedHijri = 2;
27 internal static readonly
int[] HijriMonthDays =
new int[13]
44 private const string InternationalRegKey =
"Control Panel\\International";
46 private const string HijriAdvanceRegKeyEntry =
"AddHijriDate";
48 private int m_HijriAdvance =
int.MinValue;
50 internal const int MaxCalendarYear = 9666;
52 internal const int MaxCalendarMonth = 4;
54 internal const int MaxCalendarDay = 3;
56 internal static readonly
DateTime calendarMinValue =
new DateTime(622, 7, 18);
60 private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 1451;
69 return calendarMinValue;
80 return calendarMaxValue;
95 internal override int ID => 6;
106 [SecuritySafeCritical]
109 if (m_HijriAdvance ==
int.MinValue)
111 m_HijriAdvance = GetAdvanceHijriDate();
113 return m_HijriAdvance;
117 if (value < -2 || value > 2)
122 m_HijriAdvance = value;
128 public override int[]
Eras =>
new int[1]
141 if (twoDigitYearMax == -1)
143 twoDigitYearMax =
Calendar.GetSystemTwoDigitYearSetting(ID, 1451);
145 return twoDigitYearMax;
150 if (value < 99 || value > 9666)
154 twoDigitYearMax = value;
158 private long GetAbsoluteDateHijri(
int y,
int m,
int d)
160 return DaysUpToHijriYear(y) + HijriMonthDays[m - 1] + d - 1 -
HijriAdjustment;
163 private long DaysUpToHijriYear(
int HijriYear)
165 int num = (HijriYear - 1) / 30 * 30;
166 int num2 = HijriYear - num - 1;
167 long num3 = (long)num * 10631L / 30 + 227013;
177 private static int GetAdvanceHijriDate()
183 registryKey = Registry.CurrentUser.InternalOpenSubKey(
"Control Panel\\International", writable:
false);
185 catch (ObjectDisposedException)
189 catch (ArgumentException)
193 if (registryKey !=
null)
197 object obj = registryKey.InternalGetValue(
"AddHijriDate",
null, doNotExpand:
false, checkSecurity:
false);
202 string text = obj.ToString();
203 if (
string.Compare(text, 0,
"AddHijriDate", 0,
"AddHijriDate".Length,
StringComparison.OrdinalIgnoreCase) == 0)
205 if (text.Length !=
"AddHijriDate".Length)
207 text = text.Substring(
"AddHijriDate".Length);
210 int num =
int.Parse(text.ToString(), CultureInfo.InvariantCulture);
222 catch (ArgumentException)
226 catch (FormatException)
230 catch (OverflowException)
247 internal static void CheckTicksRange(
long ticks)
249 if (ticks < calendarMinValue.Ticks || ticks > calendarMaxValue.Ticks)
251 throw new ArgumentOutOfRangeException(
"time",
string.
Format(CultureInfo.InvariantCulture, Environment.GetResourceString(
"ArgumentOutOfRange_CalendarRange"), calendarMinValue, calendarMaxValue));
255 internal static void CheckEraRange(
int era)
259 throw new ArgumentOutOfRangeException(
"era", Environment.GetResourceString(
"ArgumentOutOfRange_InvalidEraValue"));
263 internal static void CheckYearRange(
int year,
int era)
266 if (year < 1 || year > 9666)
268 throw new ArgumentOutOfRangeException(
"year",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, 9666));
272 internal static void CheckYearMonthRange(
int year,
int month,
int era)
274 CheckYearRange(year, era);
275 if (year == 9666 && month > 4)
277 throw new ArgumentOutOfRangeException(
"month",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, 4));
279 if (month < 1 || month > 12)
281 throw new ArgumentOutOfRangeException(
"month", Environment.GetResourceString(
"ArgumentOutOfRange_Month"));
285 internal virtual int GetDatePart(
long ticks,
int part)
287 CheckTicksRange(ticks);
288 long num = ticks / 864000000000
L + 1;
290 int num2 = (int)((num - 227013) * 30 / 10631) + 1;
291 long num3 = DaysUpToHijriYear(num2);
298 else if (num == num3)
303 else if (num > num3 + num4)
318 for (; i <= 12 && num > HijriMonthDays[i - 1]; i++)
326 int result = (int)(num - HijriMonthDays[i - 1]);
331 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_DateTimeParsing"));
344 if (months < -120000 || months > 120000)
348 int datePart = GetDatePart(time.
Ticks, 0);
349 int datePart2 = GetDatePart(time.
Ticks, 2);
350 int num = GetDatePart(time.
Ticks, 3);
351 int num2 = datePart2 - 1 + months;
354 datePart2 = num2 % 12 + 1;
355 datePart += num2 / 12;
359 datePart2 = 12 + (num2 + 1) % 12;
360 datePart += (num2 - 11) / 12;
363 if (num > daysInMonth)
367 long ticks = GetAbsoluteDateHijri(datePart, datePart2, num) * 864000000000
L + time.
Ticks % 864000000000
L;
387 return GetDatePart(time.
Ticks, 3);
403 return GetDatePart(time.
Ticks, 1);
417 CheckYearMonthRange(year, month, era);
441 CheckYearRange(year, era);
454 CheckTicksRange(time.
Ticks);
463 return GetDatePart(time.
Ticks, 2);
475 CheckYearRange(year, era);
484 return GetDatePart(time.
Ticks, 0);
499 public override bool IsLeapDay(
int year,
int month,
int day,
int era)
502 if (day < 1 || day > daysInMonth)
523 CheckYearRange(year, era);
538 CheckYearMonthRange(year, month, era);
552 CheckYearRange(year, era);
553 return (year * 11 + 14) % 30 < 11;
575 public override DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era)
578 if (day < 1 || day > daysInMonth)
582 long absoluteDateHijri = GetAbsoluteDateHijri(year, month, day);
583 if (absoluteDateHijri >= 0)
585 return new DateTime(absoluteDateHijri * 864000000000
L +
Calendar.TimeToTicks(hour, minute, second, millisecond));
603 return base.ToFourDigitYear(year);
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....
Represents time in divisions, such as weeks, months, and years.
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week 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 GetMonthsInYear(int year, int era)
Returns the number of months in the specified year and era.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
override bool IsLeapMonth(int year, int month, int era)
Determines whether the specified month in the specified year and era is a leap month.
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
static readonly int HijriEra
Represents the current era. This field is constant.
override int DaysInYearBeforeMinSupportedYear
Gets the number of days in the year that precedes the year that is specified by the P:System....
override int [] Eras
Gets the list of eras in the T:System.Globalization.HijriCalendar.
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....
Provides information about, and means to manipulate, the current environment and platform....
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
int HijriAdjustment
Gets or sets the number of days to add or subtract from the calendar to accommodate the variances in ...
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date is a leap day.
Format character that affects the layout of text or the operation of text processes,...
override int ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
override int GetDaysInMonth(int year, int month, int era)
Returns the number of days in the specified month of the specified year and era.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
Specifies that the class can be serialized.
Represents the Hijri calendar.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime.
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year and era.
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, time, and era.
Provides information about a specific culture (called a locale for unmanaged code development)....
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by this calendar.
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by this calendar.
DayOfWeek
Specifies the day of the week.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.