mscorlib(4.0.0.0) API with additions
JulianCalendar.cs
2 
3 namespace System.Globalization
4 {
7  [ComVisible(true)]
8  public class JulianCalendar : Calendar
9  {
11  public static readonly int JulianEra = 1;
12 
13  private const int DatePartYear = 0;
14 
15  private const int DatePartDayOfYear = 1;
16 
17  private const int DatePartMonth = 2;
18 
19  private const int DatePartDay = 3;
20 
21  private const int JulianDaysPerYear = 365;
22 
23  private const int JulianDaysPer4Years = 1461;
24 
25  private static readonly int[] DaysToMonth365 = new int[13]
26  {
27  0,
28  31,
29  59,
30  90,
31  120,
32  151,
33  181,
34  212,
35  243,
36  273,
37  304,
38  334,
39  365
40  };
41 
42  private static readonly int[] DaysToMonth366 = new int[13]
43  {
44  0,
45  31,
46  60,
47  91,
48  121,
49  152,
50  182,
51  213,
52  244,
53  274,
54  305,
55  335,
56  366
57  };
58 
59  internal int MaxYear = 9999;
60 
63  [ComVisible(false)]
64  public override DateTime MinSupportedDateTime
65  {
66  get
67  {
68  return DateTime.MinValue;
69  }
70  }
71 
74  [ComVisible(false)]
75  public override DateTime MaxSupportedDateTime
76  {
77  get
78  {
79  return DateTime.MaxValue;
80  }
81  }
82 
85  [ComVisible(false)]
86  public override CalendarAlgorithmType AlgorithmType
87  {
88  get
89  {
90  return CalendarAlgorithmType.SolarCalendar;
91  }
92  }
93 
94  internal override int ID => 13;
95 
98  public override int[] Eras => new int[1]
99  {
100  JulianEra
101  };
102 
107  public override int TwoDigitYearMax
108  {
109  get
110  {
111  return twoDigitYearMax;
112  }
113  set
114  {
115  VerifyWritable();
116  if (value < 99 || value > MaxYear)
117  {
118  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 99, MaxYear));
119  }
120  twoDigitYearMax = value;
121  }
122  }
123 
125  public JulianCalendar()
126  {
127  twoDigitYearMax = 2029;
128  }
129 
130  internal static void CheckEraRange(int era)
131  {
132  if (era != 0 && era != JulianEra)
133  {
134  throw new ArgumentOutOfRangeException("era", Environment.GetResourceString("ArgumentOutOfRange_InvalidEraValue"));
135  }
136  }
137 
138  internal void CheckYearEraRange(int year, int era)
139  {
140  CheckEraRange(era);
141  if (year <= 0 || year > MaxYear)
142  {
143  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, MaxYear));
144  }
145  }
146 
147  internal static void CheckMonthRange(int month)
148  {
149  if (month < 1 || month > 12)
150  {
151  throw new ArgumentOutOfRangeException("month", Environment.GetResourceString("ArgumentOutOfRange_Month"));
152  }
153  }
154 
155  internal static void CheckDayRange(int year, int month, int day)
156  {
157  if (year == 1 && month == 1 && day < 3)
158  {
159  throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_BadYearMonthDay"));
160  }
161  int[] array = (year % 4 == 0) ? DaysToMonth366 : DaysToMonth365;
162  int num = array[month] - array[month - 1];
163  if (day < 1 || day > num)
164  {
165  throw new ArgumentOutOfRangeException("day", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, num));
166  }
167  }
168 
169  internal static int GetDatePart(long ticks, int part)
170  {
171  long num = ticks + 1728000000000L;
172  int num2 = (int)(num / 864000000000L);
173  int num3 = num2 / 1461;
174  num2 -= num3 * 1461;
175  int num4 = num2 / 365;
176  if (num4 == 4)
177  {
178  num4 = 3;
179  }
180  if (part == 0)
181  {
182  return num3 * 4 + num4 + 1;
183  }
184  num2 -= num4 * 365;
185  if (part == 1)
186  {
187  return num2 + 1;
188  }
189  int[] array = (num4 == 3) ? DaysToMonth366 : DaysToMonth365;
190  int i;
191  for (i = num2 >> 6; num2 >= array[i]; i++)
192  {
193  }
194  if (part == 2)
195  {
196  return i;
197  }
198  return num2 - array[i - 1] + 1;
199  }
200 
201  internal static long DateToTicks(int year, int month, int day)
202  {
203  int[] array = (year % 4 == 0) ? DaysToMonth366 : DaysToMonth365;
204  int num = year - 1;
205  int num2 = num * 365 + num / 4 + array[month - 1] + day - 1;
206  return (num2 - 2) * 864000000000L;
207  }
208 
217  public override DateTime AddMonths(DateTime time, int months)
218  {
219  if (months < -120000 || months > 120000)
220  {
221  throw new ArgumentOutOfRangeException("months", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), -120000, 120000));
222  }
223  int datePart = GetDatePart(time.Ticks, 0);
224  int datePart2 = GetDatePart(time.Ticks, 2);
225  int num = GetDatePart(time.Ticks, 3);
226  int num2 = datePart2 - 1 + months;
227  if (num2 >= 0)
228  {
229  datePart2 = num2 % 12 + 1;
230  datePart += num2 / 12;
231  }
232  else
233  {
234  datePart2 = 12 + (num2 + 1) % 12;
235  datePart += (num2 - 11) / 12;
236  }
237  int[] array = (datePart % 4 == 0 && (datePart % 100 != 0 || datePart % 400 == 0)) ? DaysToMonth366 : DaysToMonth365;
238  int num3 = array[datePart2] - array[datePart2 - 1];
239  if (num > num3)
240  {
241  num = num3;
242  }
243  long ticks = DateToTicks(datePart, datePart2, num) + time.Ticks % 864000000000L;
244  Calendar.CheckAddResult(ticks, MinSupportedDateTime, MaxSupportedDateTime);
245  return new DateTime(ticks);
246  }
247 
253  public override DateTime AddYears(DateTime time, int years)
254  {
255  return AddMonths(time, years * 12);
256  }
257 
261  public override int GetDayOfMonth(DateTime time)
262  {
263  return GetDatePart(time.Ticks, 3);
264  }
265 
269  public override DayOfWeek GetDayOfWeek(DateTime time)
270  {
271  return (DayOfWeek)((int)(time.Ticks / 864000000000L + 1) % 7);
272  }
273 
277  public override int GetDayOfYear(DateTime time)
278  {
279  return GetDatePart(time.Ticks, 1);
280  }
281 
291  public override int GetDaysInMonth(int year, int month, int era)
292  {
293  CheckYearEraRange(year, era);
294  CheckMonthRange(month);
295  int[] array = (year % 4 == 0) ? DaysToMonth366 : DaysToMonth365;
296  return array[month] - array[month - 1];
297  }
298 
306  public override int GetDaysInYear(int year, int era)
307  {
308  if (!IsLeapYear(year, era))
309  {
310  return 365;
311  }
312  return 366;
313  }
314 
318  public override int GetEra(DateTime time)
319  {
320  return JulianEra;
321  }
322 
326  public override int GetMonth(DateTime time)
327  {
328  return GetDatePart(time.Ticks, 2);
329  }
330 
338  public override int GetMonthsInYear(int year, int era)
339  {
340  CheckYearEraRange(year, era);
341  return 12;
342  }
343 
347  public override int GetYear(DateTime time)
348  {
349  return GetDatePart(time.Ticks, 0);
350  }
351 
364  public override bool IsLeapDay(int year, int month, int day, int era)
365  {
366  CheckMonthRange(month);
367  if (IsLeapYear(year, era))
368  {
369  CheckDayRange(year, month, day);
370  if (month == 2)
371  {
372  return day == 29;
373  }
374  return false;
375  }
376  CheckDayRange(year, month, day);
377  return false;
378  }
379 
384  [ComVisible(false)]
385  public override int GetLeapMonth(int year, int era)
386  {
387  CheckYearEraRange(year, era);
388  return 0;
389  }
390 
400  public override bool IsLeapMonth(int year, int month, int era)
401  {
402  CheckYearEraRange(year, era);
403  CheckMonthRange(month);
404  return false;
405  }
406 
415  public override bool IsLeapYear(int year, int era)
416  {
417  CheckYearEraRange(year, era);
418  return year % 4 == 0;
419  }
420 
440  public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
441  {
442  CheckYearEraRange(year, era);
443  CheckMonthRange(month);
444  CheckDayRange(year, month, day);
445  if (millisecond < 0 || millisecond >= 1000)
446  {
447  throw new ArgumentOutOfRangeException("millisecond", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 0, 999));
448  }
449  if (hour >= 0 && hour < 24 && minute >= 0 && minute < 60 && second >= 0 && second < 60)
450  {
451  return new DateTime(DateToTicks(year, month, day) + new TimeSpan(0, hour, minute, second, millisecond).Ticks);
452  }
453  throw new ArgumentOutOfRangeException(null, Environment.GetResourceString("ArgumentOutOfRange_BadHourMinuteSecond"));
454  }
455 
461  public override int ToFourDigitYear(int year)
462  {
463  if (year < 0)
464  {
465  throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
466  }
467  if (year > MaxYear)
468  {
469  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Bounds_Lower_Upper"), 1, MaxYear));
470  }
471  return base.ToFourDigitYear(year);
472  }
473  }
474 }
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
Represents time in divisions, such as weeks, months, and years.
Definition: Calendar.cs:11
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.
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 DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.JulianCalendar class.
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:109
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override int [] Eras
Gets the list of eras in the T:System.Globalization.JulianCalendar.
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 an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap 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....
override int ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime.
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:113
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year in the specified era.
Format character that affects the layout of text or the operation of text processes,...
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
static readonly int JulianEra
Represents the current era. This field is constant.
Represents the Julian calendar.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
Represents a time interval.To browse the .NET Framework source code for this type,...
Definition: TimeSpan.cs:12
Specifies that the class can be serialized.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
JulianCalendar()
Initializes a new instance of the T:System.Globalization.JulianCalendar class.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.JulianCalendar class.
DayOfWeek
Specifies the day of the week.
Definition: DayOfWeek.cs:9
long Ticks
Gets the number of ticks that represent the date and time of this instance.
Definition: DateTime.cs:315
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 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.