14 internal const int DatePartYear = 0;
16 internal const int DatePartDayOfYear = 1;
18 internal const int DatePartMonth = 2;
20 internal const int DatePartDay = 3;
22 internal const int MaxYear = 9999;
26 internal static readonly
int[] DaysToMonth365 =
new int[13]
43 internal static readonly
int[] DaysToMonth366 =
new int[13]
60 private static volatile Calendar s_defaultInstance;
62 private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 2029;
126 internal override int ID => (int)m_type;
130 public override int[]
Eras =>
new int[1]
143 if (twoDigitYearMax == -1)
145 twoDigitYearMax =
Calendar.GetSystemTwoDigitYearSetting(ID, 2029);
147 return twoDigitYearMax;
152 if (value < 99 || value > 9999)
156 twoDigitYearMax = value;
169 internal static Calendar GetDefaultInstance()
171 if (s_defaultInstance ==
null)
175 return s_defaultInstance;
197 internal virtual int GetDatePart(
long ticks,
int part)
199 int num = (int)(ticks / 864000000000L);
200 int num2 = num / 146097;
201 num -= num2 * 146097;
202 int num3 = num / 36524;
208 int num4 = num / 1461;
210 int num5 = num / 365;
217 return num2 * 400 + num3 * 100 + num4 * 4 + num5 + 1;
224 int[] array = (num5 == 3 && (num4 != 24 || num3 == 3)) ? DaysToMonth366 : DaysToMonth365;
226 for (i = num >> 6; num >= array[i]; i++)
233 return num - array[i - 1] + 1;
236 internal static long GetAbsoluteDate(
int year,
int month,
int day)
238 if (year >= 1 && year <= 9999 && month >= 1 && month <= 12)
240 int[] array = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
241 if (day >= 1 && day <= array[month] - array[month - 1])
244 int num2 = num * 365 + num / 4 - num / 100 + num / 400 + array[month - 1] + day - 1;
248 throw new ArgumentOutOfRangeException(
null, Environment.GetResourceString(
"ArgumentOutOfRange_BadYearMonthDay"));
251 internal virtual long DateToTicks(
int year,
int month,
int day)
253 return GetAbsoluteDate(year, month, day) * 864000000000
L;
266 if (months < -120000 || months > 120000)
270 int datePart = GetDatePart(time.
Ticks, 0);
271 int datePart2 = GetDatePart(time.
Ticks, 2);
272 int num = GetDatePart(time.
Ticks, 3);
273 int num2 = datePart2 - 1 + months;
276 datePart2 = num2 % 12 + 1;
277 datePart += num2 / 12;
281 datePart2 = 12 + (num2 + 1) % 12;
282 datePart += (num2 - 11) / 12;
284 int[] array = (datePart % 4 == 0 && (datePart % 100 != 0 || datePart % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
285 int num3 = array[datePart2] - array[datePart2 - 1];
290 long ticks = DateToTicks(datePart, datePart2, num) + time.
Ticks % 864000000000
L;
310 return GetDatePart(time.
Ticks, 3);
326 return GetDatePart(time.
Ticks, 1);
340 if (era == 0 || era == 1)
342 if (year < 1 || year > 9999)
346 if (month < 1 || month > 12)
350 int[] array = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
351 return array[month] - array[month - 1];
365 if (era == 0 || era == 1)
367 if (year >= 1 && year <= 9999)
369 if (year % 4 != 0 || (year % 100 == 0 && year % 400 != 0))
393 return GetDatePart(time.
Ticks, 2);
405 if (era == 0 || era == 1)
407 if (year >= 1 && year <= 9999)
421 return GetDatePart(time.
Ticks, 0);
436 public override bool IsLeapDay(
int year,
int month,
int day,
int era)
438 if (month < 1 || month > 12)
442 if (era != 0 && era != 1)
446 if (year < 1 || year > 9999)
458 if (month == 2 && day == 29)
475 if (era != 0 && era != 1)
479 if (year < 1 || year > 9999)
497 if (era != 0 && era != 1)
501 if (year < 1 || year > 9999)
505 if (month < 1 || month > 12)
522 if (era == 0 || era == 1)
524 if (year >= 1 && year <= 9999)
530 return year % 400 == 0;
560 public override DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era)
562 if (era == 0 || era == 1)
564 return new DateTime(year, month, day, hour, minute, second, millisecond);
569 internal override bool TryToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era, out
DateTime result)
571 if (era == 0 || era == 1)
573 return DateTime.TryCreate(year, month, day, hour, minute, second, millisecond, out result);
594 return base.ToFourDigitYear(year);
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
Represents time in divisions, such as weeks, months, and years.
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.
Refers to the localized version of the Gregorian calendar, based on the language of the T:System....
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year in the specified era.
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Represents the Gregorian calendar.
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.GregorianCalendar type.
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.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.GregorianCalendar type.
GregorianCalendarTypes
Defines the different language versions of the Gregorian calendar.
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 int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
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.
GregorianCalendar(GregorianCalendarTypes type)
Initializes a new instance of the T:System.Globalization.GregorianCalendar class using the specified ...
override int [] Eras
Gets the list of eras in the T:System.Globalization.GregorianCalendar.
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date in the specified era is a leap day.
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
const int ADEra
Represents the current era. This field is constant.
Provides information about, and means to manipulate, the current environment and platform....
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
Format character that affects the layout of text or the operation of text processes,...
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.
The exception thrown when an error occurs during serialization or deserialization.
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 ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week 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.
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....
virtual GregorianCalendarTypes CalendarType
Gets or sets the T:System.Globalization.GregorianCalendarTypes value that denotes the language versio...
Provides information about a specific culture (called a locale for unmanaged code development)....
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.
DayOfWeek
Specifies the day of the week.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
GregorianCalendar()
Initializes a new instance of the T:System.Globalization.GregorianCalendar class using the default T:...