mscorlib(4.0.0.0) API with additions
TaiwanCalendar.cs
2 
3 namespace System.Globalization
4 {
7  [ComVisible(true)]
8  public class TaiwanCalendar : Calendar
9  {
10  internal static EraInfo[] taiwanEraInfo = new EraInfo[1]
11  {
12  new EraInfo(1, 1912, 1, 1, 1911, 1, 8088)
13  };
14 
15  internal static volatile Calendar s_defaultInstance;
16 
17  internal GregorianCalendarHelper helper;
18 
19  internal static readonly DateTime calendarMinValue = new DateTime(1912, 1, 1);
20 
21  private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 99;
22 
25  [ComVisible(false)]
26  public override DateTime MinSupportedDateTime
27  {
28  get
29  {
30  return calendarMinValue;
31  }
32  }
33 
36  [ComVisible(false)]
37  public override DateTime MaxSupportedDateTime
38  {
39  get
40  {
41  return DateTime.MaxValue;
42  }
43  }
44 
47  [ComVisible(false)]
48  public override CalendarAlgorithmType AlgorithmType
49  {
50  get
51  {
52  return CalendarAlgorithmType.SolarCalendar;
53  }
54  }
55 
56  internal override int ID => 4;
57 
60  public override int[] Eras => helper.Eras;
61 
66  public override int TwoDigitYearMax
67  {
68  get
69  {
70  if (twoDigitYearMax == -1)
71  {
72  twoDigitYearMax = Calendar.GetSystemTwoDigitYearSetting(ID, 99);
73  }
74  return twoDigitYearMax;
75  }
76  set
77  {
78  VerifyWritable();
79  if (value < 99 || value > helper.MaxYear)
80  {
81  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 99, helper.MaxYear));
82  }
83  twoDigitYearMax = value;
84  }
85  }
86 
87  internal static Calendar GetDefaultInstance()
88  {
89  if (s_defaultInstance == null)
90  {
91  s_defaultInstance = new TaiwanCalendar();
92  }
93  return s_defaultInstance;
94  }
95 
98  public TaiwanCalendar()
99  {
100  try
101  {
102  new CultureInfo("zh-TW");
103  }
104  catch (ArgumentException innerException)
105  {
106  throw new TypeInitializationException(GetType().FullName, innerException);
107  }
108  helper = new GregorianCalendarHelper(this, taiwanEraInfo);
109  }
110 
119  public override DateTime AddMonths(DateTime time, int months)
120  {
121  return helper.AddMonths(time, months);
122  }
123 
129  public override DateTime AddYears(DateTime time, int years)
130  {
131  return helper.AddYears(time, years);
132  }
133 
143  public override int GetDaysInMonth(int year, int month, int era)
144  {
145  return helper.GetDaysInMonth(year, month, era);
146  }
147 
155  public override int GetDaysInYear(int year, int era)
156  {
157  return helper.GetDaysInYear(year, era);
158  }
159 
163  public override int GetDayOfMonth(DateTime time)
164  {
165  return helper.GetDayOfMonth(time);
166  }
167 
171  public override DayOfWeek GetDayOfWeek(DateTime time)
172  {
173  return helper.GetDayOfWeek(time);
174  }
175 
179  public override int GetDayOfYear(DateTime time)
180  {
181  return helper.GetDayOfYear(time);
182  }
183 
191  public override int GetMonthsInYear(int year, int era)
192  {
193  return helper.GetMonthsInYear(year, era);
194  }
195 
204  [ComVisible(false)]
205  public override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
206  {
207  return helper.GetWeekOfYear(time, rule, firstDayOfWeek);
208  }
209 
213  public override int GetEra(DateTime time)
214  {
215  return helper.GetEra(time);
216  }
217 
221  public override int GetMonth(DateTime time)
222  {
223  return helper.GetMonth(time);
224  }
225 
229  public override int GetYear(DateTime time)
230  {
231  return helper.GetYear(time);
232  }
233 
246  public override bool IsLeapDay(int year, int month, int day, int era)
247  {
248  return helper.IsLeapDay(year, month, day, era);
249  }
250 
259  public override bool IsLeapYear(int year, int era)
260  {
261  return helper.IsLeapYear(year, era);
262  }
263 
268  [ComVisible(false)]
269  public override int GetLeapMonth(int year, int era)
270  {
271  return helper.GetLeapMonth(year, era);
272  }
273 
283  public override bool IsLeapMonth(int year, int month, int era)
284  {
285  return helper.IsLeapMonth(year, month, era);
286  }
287 
307  public override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
308  {
309  return helper.ToDateTime(year, month, day, hour, minute, second, millisecond, era);
310  }
311 
317  public override int ToFourDigitYear(int year)
318  {
319  if (year <= 0)
320  {
321  throw new ArgumentOutOfRangeException("year", Environment.GetResourceString("ArgumentOutOfRange_NeedPosNum"));
322  }
323  if (year > helper.MaxYear)
324  {
325  throw new ArgumentOutOfRangeException("year", string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("ArgumentOutOfRange_Range"), 1, helper.MaxYear));
326  }
327  return year;
328  }
329  }
330 }
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
DateTime AddYears(int value)
Returns a new T:System.DateTime that adds the specified number of years to the value of this instance...
Definition: DateTime.cs:842
The exception that is thrown as a wrapper around the exception thrown by the class initializer....
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 int ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
Returns the week of the year that includes the date in the specified T:System.DateTime.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date in the specified era is a leap day.
TaiwanCalendar()
Initializes a new instance of the T:System.Globalization.TaiwanCalendar class.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
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.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
DateTime AddMonths(int months)
Returns a new T:System.DateTime that adds the specified number of months to the value of this instanc...
Definition: DateTime.cs:779
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:113
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,...
DateTime IConvertible. ToDateTime(IFormatProvider provider)
Returns the current T:System.DateTime object.
Definition: DateTime.cs:1931
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.TaiwanCalendar class.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when one of the arguments provided to a method is not valid.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.TaiwanCalendar class.
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....
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
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.
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime.
Specifies that the class can be serialized.
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....
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime.
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.
DayOfWeek
Specifies the day of the week.
Definition: DayOfWeek.cs:9
override int [] Eras
Gets the list of eras in the T:System.Globalization.TaiwanCalendar.
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.