10 [__DynamicallyInvokable]
13 internal const long TicksPerMillisecond = 10000
L;
15 internal const long TicksPerSecond = 10000000
L;
17 internal const long TicksPerMinute = 600000000
L;
19 internal const long TicksPerHour = 36000000000
L;
21 internal const long TicksPerDay = 864000000000
L;
23 internal const int MillisPerSecond = 1000;
25 internal const int MillisPerMinute = 60000;
27 internal const int MillisPerHour = 3600000;
29 internal const int MillisPerDay = 86400000;
31 internal const int DaysPerYear = 365;
33 internal const int DaysPer4Years = 1461;
35 internal const int DaysPer100Years = 36524;
37 internal const int DaysPer400Years = 146097;
39 internal const int DaysTo10000 = 3652059;
41 internal const long MaxMillis = 315537897600000
L;
43 internal const int CAL_GREGORIAN = 1;
45 internal const int CAL_GREGORIAN_US = 2;
47 internal const int CAL_JAPAN = 3;
49 internal const int CAL_TAIWAN = 4;
51 internal const int CAL_KOREA = 5;
53 internal const int CAL_HIJRI = 6;
55 internal const int CAL_THAI = 7;
57 internal const int CAL_HEBREW = 8;
59 internal const int CAL_GREGORIAN_ME_FRENCH = 9;
61 internal const int CAL_GREGORIAN_ARABIC = 10;
63 internal const int CAL_GREGORIAN_XLIT_ENGLISH = 11;
65 internal const int CAL_GREGORIAN_XLIT_FRENCH = 12;
67 internal const int CAL_JULIAN = 13;
69 internal const int CAL_JAPANESELUNISOLAR = 14;
71 internal const int CAL_CHINESELUNISOLAR = 15;
73 internal const int CAL_SAKA = 16;
75 internal const int CAL_LUNAR_ETO_CHN = 17;
77 internal const int CAL_LUNAR_ETO_KOR = 18;
79 internal const int CAL_LUNAR_ETO_ROKUYOU = 19;
81 internal const int CAL_KOREANLUNISOLAR = 20;
83 internal const int CAL_TAIWANLUNISOLAR = 21;
85 internal const int CAL_PERSIAN = 22;
87 internal const int CAL_UMALQURA = 23;
89 internal int m_currentEraValue = -1;
91 [OptionalField(VersionAdded = 2)]
92 private bool m_isReadOnly;
95 [__DynamicallyInvokable]
98 internal int twoDigitYearMax = -1;
103 [__DynamicallyInvokable]
106 [__DynamicallyInvokable]
116 [__DynamicallyInvokable]
119 [__DynamicallyInvokable]
126 internal virtual int ID => -1;
128 internal virtual int BaseCalendarID => ID;
145 [__DynamicallyInvokable]
148 [__DynamicallyInvokable]
155 internal virtual int CurrentEraValue
159 if (m_currentEraValue == -1)
161 m_currentEraValue = CalendarData.GetCalendarData(BaseCalendarID).iCurrentEra;
163 return m_currentEraValue;
169 [__DynamicallyInvokable]
170 public abstract int[]
Eras 172 [__DynamicallyInvokable]
183 [__DynamicallyInvokable]
186 [__DynamicallyInvokable]
189 return twoDigitYearMax;
191 [__DynamicallyInvokable]
195 twoDigitYearMax = value;
200 [__DynamicallyInvokable]
210 object obj = MemberwiseClone();
211 ((
Calendar)obj).SetReadOnlyState(readOnly:
false);
223 if (calendar ==
null)
232 calendar2.SetReadOnlyState(readOnly:
true);
236 internal void VerifyWritable()
244 internal void SetReadOnlyState(
bool readOnly)
246 m_isReadOnly = readOnly;
249 internal static void CheckAddResult(
long ticks, DateTime minValue, DateTime maxValue)
251 if (ticks < minValue.Ticks || ticks > maxValue.Ticks)
253 throw new ArgumentException(
string.
Format(CultureInfo.InvariantCulture, Environment.GetResourceString(
"Argument_ResultCalendarRange"), minValue, maxValue));
257 internal DateTime Add(DateTime time,
double value,
int scale)
259 double num = value * (double)scale + ((value >= 0.0) ? 0.5 : (-0.5));
260 if (!(num > -315537897600000.0) || !(num < 315537897600000.0))
262 throw new ArgumentOutOfRangeException(
"value", Environment.GetResourceString(
"ArgumentOutOfRange_AddValue"));
264 long num2 = (long)num;
265 long ticks = time.Ticks + num2 * 10000;
277 [__DynamicallyInvokable]
280 return Add(time, milliseconds, 1);
290 [__DynamicallyInvokable]
293 return Add(time, days, 86400000);
303 [__DynamicallyInvokable]
306 return Add(time, hours, 3600000);
316 [__DynamicallyInvokable]
319 return Add(time, minutes, 60000);
329 [__DynamicallyInvokable]
339 [__DynamicallyInvokable]
342 return Add(time, seconds, 1000);
352 [__DynamicallyInvokable]
355 return AddDays(time, weeks * 7);
365 [__DynamicallyInvokable]
371 [__DynamicallyInvokable]
377 [__DynamicallyInvokable]
383 [__DynamicallyInvokable]
393 [__DynamicallyInvokable]
408 [__DynamicallyInvokable]
416 [__DynamicallyInvokable]
429 [__DynamicallyInvokable]
435 [__DynamicallyInvokable]
441 [__DynamicallyInvokable]
444 return (
int)(time.
Ticks / 36000000000
L % 24);
450 [__DynamicallyInvokable]
453 return time.
Ticks / 10000 % 1000;
459 [__DynamicallyInvokable]
462 return (
int)(time.
Ticks / 600000000 % 60);
468 [__DynamicallyInvokable]
476 [__DynamicallyInvokable]
489 [__DynamicallyInvokable]
495 [__DynamicallyInvokable]
498 return (
int)(time.
Ticks / 10000000 % 60);
501 internal int GetFirstDayWeekOfYear(
DateTime time,
int firstDayOfWeek)
505 int num3 = (num2 - firstDayOfWeek + 14) % 7;
506 return (num + num3) / 7 + 1;
509 private int GetWeekOfYearFullDays(
DateTime time,
int firstDayOfWeek,
int fullDays)
513 int num3 = (firstDayOfWeek - num2 + 14) % 7;
514 if (num3 != 0 && num3 >= fullDays)
518 int num4 = num - num3;
525 return GetWeekOfYearOfMinSupportedDateTime(firstDayOfWeek, fullDays);
527 return GetWeekOfYearFullDays(time.
AddDays(-(num + 1)), firstDayOfWeek, fullDays);
530 private int GetWeekOfYearOfMinSupportedDateTime(
int firstDayOfWeek,
int minimumDaysInFirstWeek)
534 int num3 = (firstDayOfWeek + 7 - num2) % 7;
535 if (num3 == 0 || num3 >= minimumDaysInFirstWeek)
540 int num5 = num2 - 1 - num4 % 7;
541 int num6 = (firstDayOfWeek - num5 + 14) % 7;
542 int num7 = num4 - num6;
543 if (num6 >= minimumDaysInFirstWeek)
559 [__DynamicallyInvokable]
562 if (firstDayOfWeek < DayOfWeek.Sunday || firstDayOfWeek >
DayOfWeek.Saturday)
569 return GetFirstDayWeekOfYear(time, (
int)firstDayOfWeek);
571 return GetWeekOfYearFullDays(time, (
int)firstDayOfWeek, 7);
573 return GetWeekOfYearFullDays(time, (
int)firstDayOfWeek, 4);
582 [__DynamicallyInvokable]
595 [__DynamicallyInvokable]
596 public virtual bool IsLeapDay(
int year,
int month,
int day)
613 [__DynamicallyInvokable]
614 public abstract bool IsLeapDay(
int year,
int month,
int day,
int era);
624 [__DynamicallyInvokable]
640 [__DynamicallyInvokable]
641 public abstract bool IsLeapMonth(
int year,
int month,
int era);
657 [__DynamicallyInvokable]
665 for (
int i = 1; i <= monthsInYear; i++)
681 [__DynamicallyInvokable]
695 [__DynamicallyInvokable]
696 public abstract bool IsLeapYear(
int year,
int era);
715 [__DynamicallyInvokable]
716 public virtual DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond)
718 return ToDateTime(year, month, day, hour, minute, second, millisecond, 0);
740 [__DynamicallyInvokable]
741 public abstract DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era);
743 internal virtual bool TryToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era, out
DateTime result)
748 result =
ToDateTime(year, month, day, hour, minute, second, millisecond, era);
757 internal virtual bool IsValidYear(
int year,
int era)
766 internal virtual bool IsValidMonth(
int year,
int month,
int era)
768 if (IsValidYear(year, era) && month >= 1)
775 internal virtual bool IsValidDay(
int year,
int month,
int day,
int era)
777 if (IsValidMonth(year, month, era) && day >= 1)
789 [__DynamicallyInvokable]
803 internal static long TimeToTicks(
int hour,
int minute,
int second,
int millisecond)
805 if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
807 if (millisecond < 0 || millisecond >= 1000)
811 return TimeSpan.TimeToTicks(hour, minute, second) + (long)millisecond * 10000L;
813 throw new ArgumentOutOfRangeException(
null, Environment.GetResourceString(
"ArgumentOutOfRange_BadHourMinuteSecond"));
816 [SecuritySafeCritical]
817 internal static int GetSystemTwoDigitYearSetting(
int CalID,
int defaultYearValue)
819 int num = CalendarData.nativeGetTwoDigitYearMax(CalID);
822 num = defaultYearValue;
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
abstract int GetYear(DateTime time)
When overridden in a derived class, returns the year in the specified T:System.DateTime.
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Represents time in divisions, such as weeks, months, and years.
virtual DateTime MinSupportedDateTime
Gets the earliest date and time supported by this T:System.Globalization.Calendar object.
virtual int GetLeapMonth(int year)
Calculates the leap month for a specified year.
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
virtual DateTime MaxSupportedDateTime
Gets the latest date and time supported by this T:System.Globalization.Calendar object.
virtual DateTime AddWeeks(DateTime time, int weeks)
Returns a T:System.DateTime that is the specified number of weeks away from the specified T:System....
The exception that is thrown when the value of an argument is outside the allowable range of values a...
abstract DateTime AddMonths(DateTime time, int months)
When overridden in a derived class, returns a T:System.DateTime that is the specified number of month...
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.
A type representing a date and time value.
virtual bool IsLeapMonth(int year, int month)
Determines whether the specified month in the specified year in the current era is a leap month.
virtual DateTime AddDays(DateTime time, int days)
Returns a T:System.DateTime that is the specified number of days away from the specified T:System....
virtual DateTime AddMilliseconds(DateTime time, double milliseconds)
Returns a T:System.DateTime that is the specified number of milliseconds away from the specified T:Sy...
Provides information about, and means to manipulate, the current environment and platform....
const int CurrentEra
Represents the current era of the current calendar.
static Calendar ReadOnly(Calendar calendar)
Returns a read-only version of the specified T:System.Globalization.Calendar object.
virtual int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
virtual int DaysInYearBeforeMinSupportedYear
Gets the number of days in the year that precedes the year that is specified by the P:System....
abstract int GetEra(DateTime time)
When overridden in a derived class, returns the era in the specified T:System.DateTime.
virtual int GetMonthsInYear(int year)
Returns the number of months in the specified year in the current era.
DateTime AddDays(double value)
Returns a new T:System.DateTime that adds the specified number of days to the value of this instance.
virtual DateTime AddSeconds(DateTime time, int seconds)
Returns a T:System.DateTime that is the specified number of seconds away from the specified T:System....
abstract DayOfWeek GetDayOfWeek(DateTime time)
When overridden in a derived class, returns the day of the week in the specified T:System....
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Format character that affects the layout of text or the operation of text processes,...
virtual int GetDaysInMonth(int year, int month)
Returns the number of days in the specified month and year of the current era.
virtual int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
virtual int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
Returns the week of the year that includes the date in the specified T:System.DateTime value.
abstract DateTime AddYears(DateTime time, int years)
When overridden in a derived class, returns a T:System.DateTime that is the specified number of years...
virtual DateTime AddHours(DateTime time, int hours)
Returns a T:System.DateTime that is the specified number of hours away from the specified T:System....
abstract int GetDayOfMonth(DateTime time)
When overridden in a derived class, returns the day of the month in the specified T:System....
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual double GetMilliseconds(DateTime time)
Returns the milliseconds value in the specified T:System.DateTime.
virtual int GetMinute(DateTime time)
Returns the minutes value in the specified T:System.DateTime.
CalendarWeekRule
Defines different rules for determining the first week of the year.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
abstract int [] Eras
When overridden in a derived class, gets the list of eras in the current calendar.
abstract int GetDayOfYear(DateTime time)
When overridden in a derived class, returns the day of the year in the specified T:System....
Represents a time interval.To browse the .NET Framework source code for this type,...
Specifies that the class can be serialized.
virtual bool IsLeapDay(int year, int month, int day)
Determines whether the specified date in the current era is a leap day.
The exception that is thrown when a method call is invalid for the object's current state.
virtual bool IsLeapYear(int year)
Determines whether the specified year in the current era is a leap year.
Provides information about a specific culture (called a locale for unmanaged code development)....
virtual int GetHour(DateTime time)
Returns the hours value in the specified T:System.DateTime.
virtual CalendarAlgorithmType AlgorithmType
Gets a value indicating whether the current calendar is solar-based, lunar-based, or a combination of...
virtual DateTime AddMinutes(DateTime time, int minutes)
Returns a T:System.DateTime that is the specified number of minutes away from the specified T:System....
virtual int GetSecond(DateTime time)
Returns the seconds value in the specified T:System.DateTime.
abstract int GetMonth(DateTime time)
When overridden in a derived class, returns the month in the specified T:System.DateTime.
DayOfWeek
Specifies the day of the week.
virtual DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond)
Returns a T:System.DateTime that is set to the specified date and time in the current era.
virtual int ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
virtual int GetDaysInYear(int year)
Returns the number of days in the specified year of the current era.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
virtual object Clone()
Creates a new object that is a copy of the current T:System.Globalization.Calendar object.
bool IsReadOnly
Gets a value indicating whether this T:System.Globalization.Calendar object is read-only.