GenericParameter.cs: override Module properly
[mcs.git] / class / corlib / System.Globalization / TaiwanCalendar.cs
blob4b2de2db723d7ee7b7edbc731141108ac70f2093
1 // System.Globalization.TaiwanCalendar.cs
2 //
3 // (C) Ulrich Kunitz 2002
4 //
6 //
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 namespace System.Globalization {
31 using System;
32 using System.Runtime.InteropServices;
34 /// <summary>
35 /// This is the Japanese calendar. It differs from the Gregorian calendar
36 /// only in the years.
37 /// </summary>
38 /// <remarks>
39 /// <para>The Japanese calendar support a single era starting at January 1,
40 /// 1912</para>
41 /// <para>The implementation uses the
42 /// <see cref="N:CalendricalCalculations"/> namespace.
43 /// </para>
44 /// </remarks>
45 [System.Runtime.InteropServices.ComVisible(true)]
46 [Serializable]
47 [MonoLimitation ("Serialization format not compatible with.NET")]
48 public class TaiwanCalendar : Calendar {
49 /// <summary>
50 /// Static protected field storing the
51 /// <see cref="T:CalendricalCalculations.GregorianEraHandler"/>.
52 /// </summary>
53 internal static readonly CCGregorianEraHandler M_EraHandler;
55 /// <summary>
56 /// Static constructor, who creates and initializes
57 /// <see cref="F:M_EraHandler"/>.
58 /// </summary>
59 static TaiwanCalendar() {
60 M_EraHandler = new CCGregorianEraHandler();
61 M_EraHandler.appendEra(1,
62 CCGregorianCalendar.fixed_from_dmy(1, 1, 1912));
65 /// <summary>
66 /// Default constructor.
67 /// </summary>
68 public TaiwanCalendar() {
69 M_AbbrEraNames = new string[] {"T.C.E."};
70 M_EraNames = new string[] {"Taiwan current era"};
73 /// <value>Overridden. Gives the eras supported by the
74 /// calendar as an array of integers.
75 /// </value>
76 public override int[] Eras {
77 get {
78 return (int[])M_EraHandler.Eras.Clone();
82 public override int TwoDigitYearMax
84 get {
85 return twoDigitYearMax;
87 set {
88 CheckReadOnly ();
89 M_ArgumentInRange ("value", value, 100, M_MaxYear);
91 twoDigitYearMax = value;
95 /// <summary>
96 /// A protected member checking a
97 /// <see cref="T:System.DateTime"/> value.
98 /// </summary>
99 /// <param name="time">The
100 /// <see cref="T:System.DateTime"/>
101 /// to check.
102 /// </param>
103 /// <exception cref="T:System.ArgumentOutOfRangeException">
104 /// The exception is thrown if the
105 /// <see cref="T:System.DateTime"/> parameter is outside all
106 /// supported eras.
107 /// </exception>
108 internal void M_CheckDateTime(DateTime time) {
109 M_EraHandler.CheckDateTime(time);
112 /// <summary>
113 /// A protected method checking the era number.
114 /// </summary>
115 /// <param name="era">The era number as reference. It is set
116 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
117 /// <exception name="T:System.ArgumentException">
118 /// The exception is thrown if the era is not supported by the class.
119 /// </exception>
120 internal void M_CheckEra(ref int era) {
121 if (era == CurrentEra)
122 era = 1;
123 if (!M_EraHandler.ValidEra(era))
124 throw new ArgumentException("Era value was not valid.");
127 /// <summary>
128 /// A protected method checking calendar year and the era number.
129 /// </summary>
130 /// <param name="year">An integer representing the calendar year.
131 /// </param>
132 /// <param name="era">The era number as reference.</param>
133 /// <exception name="T:System.ArgumentException">
134 /// The exception is thrown if the era is not supported by the class.
135 /// </exception>
136 /// <exception cref="T:System.ArgumentOutOfRangeException">
137 /// The exception is thrown if the calendar year is outside of
138 /// the supported range.
139 /// </exception>
140 internal int M_CheckYEG(int year, ref int era) {
141 M_CheckEra(ref era);
142 return M_EraHandler.GregorianYear(year, era);
145 /// <summary>
146 /// Checks whether the year is the era is valid, if era = CurrentEra
147 /// the right value is set.
148 /// </summary>
149 /// <param name="year">The year to check.</param>
150 /// <param name="era">The era to check.</Param>
151 /// <exception cref="T:ArgumentOutOfRangeException">
152 /// The exception will be thrown, if the year is not valid.
153 /// </exception>
154 internal override void M_CheckYE(int year, ref int era) {
155 M_CheckYEG(year, ref era);
158 /// <summary>
159 /// A protected method checking the calendar year, month, and
160 /// era number.
161 /// </summary>
162 /// <param name="year">An integer representing the calendar year.
163 /// </param>
164 /// <param name="month">An integer giving the calendar month.
165 /// </param>
166 /// <param name="era">The era number as reference.</param>
167 /// <exception name="T:System.ArgumentException">
168 /// The exception is thrown if the era is not supported by the class.
169 /// </exception>
170 /// <exception cref="T:System.ArgumentOutOfRangeException">
171 /// The exception is thrown if the calendar year or month is
172 /// outside of the supported range.
173 /// </exception>
174 internal int M_CheckYMEG(int year, int month, ref int era) {
175 int gregorianYear = M_CheckYEG(year, ref era);
176 if (month < 1 || month > 12)
177 throw new ArgumentOutOfRangeException("month",
178 "Month must be between one and twelve.");
179 return gregorianYear;
182 /// <summary>
183 /// A protected method checking the calendar day, month, and year
184 /// and the era number.
185 /// </summary>
186 /// <param name="year">An integer representing the calendar year.
187 /// </param>
188 /// <param name="month">An integer giving the calendar month.
189 /// </param>
190 /// <param name="day">An integer giving the calendar day.
191 /// </param>
192 /// <param name="era">The era number as reference.</param>
193 /// <exception name="T:System.ArgumentException">
194 /// The exception is thrown if the era is not supported by the class.
195 /// </exception>
196 /// <exception cref="T:System.ArgumentOutOfRangeException">
197 /// The exception is thrown if the calendar year, month, or day is
198 /// outside of the supported range.
199 /// </exception>
200 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
202 int gregorianYear = M_CheckYMEG(year, month, ref era);
203 M_ArgumentInRange("day", day, 1,
204 GetDaysInMonth(year, month, era));
205 return gregorianYear;
208 /// <summary>
209 /// Overrideden. Adds months to a given date.
210 /// </summary>
211 /// <param name="time">The
212 /// <see cref="T:System.DateTime"/> to which to add
213 /// months.
214 /// </param>
215 /// <param name="months">The number of months to add.</param>
216 /// <returns>A new <see cref="T:System.DateTime"/> value, that
217 /// results from adding <paramref name="months"/> to the specified
218 /// DateTime.</returns>
219 /// <exception cref="T:System.ArgumentOutOfRangeException">
220 /// The exception is thrown if
221 /// <see cref="T:System.DateTime"/> return value is outside all
222 /// supported eras.
223 /// </exception>
224 public override DateTime AddMonths(DateTime time, int months) {
225 DateTime t = CCGregorianCalendar.AddMonths(time, months);
226 M_CheckDateTime(t);
227 return t;
230 /// <summary>
231 /// Overridden. Adds years to a given date.
232 /// </summary>
233 /// <param name="time">The
234 /// <see cref="T:System.DateTime"/> to which to add
235 /// years.
236 /// </param>
237 /// <param name="years">The number of years to add.</param>
238 /// <returns>A new <see cref="T:System.DateTime"/> value, that
239 /// results from adding <paramref name="years"/> to the specified
240 /// DateTime.</returns>
241 /// <exception cref="T:System.ArgumentOutOfRangeException">
242 /// The exception is thrown if
243 /// <see cref="T:System.DateTime"/> return value is outside all
244 /// supported eras.
245 /// </exception>
246 public override DateTime AddYears(DateTime time, int years) {
247 DateTime t = CCGregorianCalendar.AddYears(time, years);
248 M_CheckDateTime(t);
249 return t;
252 /// <summary>
253 /// Overriden. Gets the day of the month from
254 /// <paramref name="time"/>.
255 /// </summary>
256 /// <param name="time">The
257 /// <see cref="T:System.DateTime"/> that specifies a
258 /// date.
259 /// </param>
260 /// <returns>An integer giving the day of months, starting with 1.
261 /// </returns>
262 /// <exception cref="T:System.ArgumentOutOfRangeException">
263 /// The exception is thrown if the
264 /// <see cref="T:System.DateTime"/> parameter is outside all
265 /// supported eras.
266 /// </exception>
267 public override int GetDayOfMonth(DateTime time) {
268 M_CheckDateTime(time);
269 return CCGregorianCalendar.GetDayOfMonth(time);
272 /// <summary>
273 /// Overriden. Gets the day of the week from the specified date.
274 /// </summary>
275 /// <param name="time">The
276 /// <see cref="T:System.DateTime"/> that specifies a
277 /// date.
278 /// </param>
279 /// <returns>An integer giving the day of months, starting with 1.
280 /// </returns>
281 /// <exception cref="T:System.ArgumentOutOfRangeException">
282 /// The exception is thrown if the
283 /// <see cref="T:System.DateTime"/> parameter is outside all
284 /// supported eras.
285 /// </exception>
286 public override DayOfWeek GetDayOfWeek(DateTime time) {
287 M_CheckDateTime(time);
288 int rd = CCFixed.FromDateTime(time);
289 return (DayOfWeek)CCFixed.day_of_week(rd);
292 /// <summary>
293 /// Overridden. Gives the number of the day in the year.
294 /// </summary>
295 /// <param name="time">The
296 /// <see cref="T:System.DateTime"/> that specifies a
297 /// date.
298 /// </param>
299 /// <returns>An integer representing the day of the year,
300 /// starting with 1.</returns>
301 /// <exception cref="T:System.ArgumentOutOfRangeException">
302 /// The exception is thrown if the
303 /// <see cref="T:System.DateTime"/> parameter is outside all
304 /// supported eras.
305 /// </exception>
306 public override int GetDayOfYear(DateTime time) {
307 M_CheckDateTime(time);
308 return CCGregorianCalendar.GetDayOfYear(time);
311 /// <summary>
312 /// Overridden. Gives the number of days in the specified month
313 /// of the given year and era.
314 /// </summary>
315 /// <param name="year">An integer that gives the year.
316 /// </param>
317 /// <param name="month">An integer that gives the month, starting
318 /// with 1.</param>
319 /// <param name="era">An integer that gives the era of the specified
320 /// year.</param>
321 /// <returns>An integer that gives the number of days of the
322 /// specified month.</returns>
323 /// <exception cref="T:System.ArgumentOutOfRangeException">
324 /// The exception is thrown, if <paramref name="month"/>,
325 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
326 /// the allowed range.
327 /// </exception>
328 public override int GetDaysInMonth(int year, int month, int era) {
329 int gregorianYear = M_CheckYMEG(year, month, ref era);
330 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
333 /// <summary>
334 /// Overridden. Gives the number of days of the specified
335 /// year of the given era.
336 /// </summary>
337 /// <param name="year">An integer that specifies the year.
338 /// </param>
339 /// <param name="era">An ineger that specifies the era.
340 /// </param>
341 /// <returns>An integer that gives the number of days of the
342 /// specified year.</returns>
343 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
344 /// The exception is thrown, if
345 /// <paramref name="year"/> or <paramref name="era"/> are outside the
346 /// allowed range.
347 /// </exception>
348 public override int GetDaysInYear(int year, int era) {
349 int gregorianYear = M_CheckYEG(year, ref era);
350 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
354 /// <summary>
355 /// Overridden. Gives the era of the specified date.
356 /// </summary>
357 /// <param name="time">The
358 /// <see cref="T:System.DateTime"/> that specifies a
359 /// date.
360 /// </param>
361 /// <returns>An integer representing the era of the calendar.
362 /// </returns>
363 /// <exception cref="T:System.ArgumentOutOfRangeException">
364 /// The exception is thrown if the
365 /// <see cref="T:System.DateTime"/> parameter is outside all
366 /// supported eras.
367 /// </exception>
368 public override int GetEra(DateTime time) {
369 // M_CheckDateTime not needed, because EraYear does the
370 // right thing.
371 int rd = CCFixed.FromDateTime(time);
372 int era;
373 M_EraHandler.EraYear(out era, rd);
374 return era;
377 [ComVisible (false)]
378 public override int GetLeapMonth (int year, int era)
380 return 0;
383 /// <summary>
384 /// Overridden. Gives the number of the month of the specified
385 /// date.
386 /// </summary>
387 /// <param name="time">The
388 /// <see cref="T:System.DateTime"/> that specifies a
389 /// date.
390 /// </param>
391 /// <returns>An integer representing the month,
392 /// starting with 1.</returns>
393 /// <exception cref="T:System.ArgumentOutOfRangeException">
394 /// The exception is thrown if the
395 /// <see cref="T:System.DateTime"/> parameter is outside all
396 /// supported eras.
397 /// </exception>
398 public override int GetMonth(DateTime time) {
399 M_CheckDateTime(time);
400 return CCGregorianCalendar.GetMonth(time);
403 /// <summary>
404 /// Overridden. Gives the number of months in the specified year
405 /// and era.
406 /// </summary>
407 /// <param name="year">An integer that specifies the year.
408 /// </param>
409 /// <param name="era">An integer that specifies the era.
410 /// </param>
411 /// <returns>An integer that gives the number of the months in the
412 /// specified year.</returns>
413 /// <exception cref="T:System.ArgumentOutOfRangeException">
414 /// The exception is thrown, if the year or the era are not valid.
415 /// </exception>
416 public override int GetMonthsInYear(int year, int era) {
417 M_CheckYEG(year, ref era);
418 return 12;
421 [ComVisible (false)]
422 public override int GetWeekOfYear (DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
424 return base.GetWeekOfYear (time, rule, firstDayOfWeek);
427 /// <summary>
428 /// Overridden. Gives the number of the year of the specified
429 /// date.
430 /// </summary>
431 /// <param name="time">The
432 /// <see cref="T:System.DateTime"/> that specifies a
433 /// date.
434 /// </param>
435 /// <returns>An integer representing the year,
436 /// starting with 1.</returns>
437 /// <exception cref="T:System.ArgumentOutOfRangeException">
438 /// The exception is thrown if the
439 /// <see cref="T:System.DateTime"/> parameter is outside all
440 /// supported eras.
441 /// </exception>
442 public override int GetYear(DateTime time) {
443 // M_CheckDateTime not needed, because EraYeat does the
444 // right thing.
445 int rd = CCFixed.FromDateTime(time);
446 int era;
447 return M_EraHandler.EraYear(out era, rd);
450 /// <summary>
451 /// Overridden. Tells whether the given day
452 /// is a leap day.
453 /// </summary>
454 /// <param name="year">An integer that specifies the year in the
455 /// given era.
456 /// </param>
457 /// <param name="month">An integer that specifies the month.
458 /// </param>
459 /// <param name="day">An integer that specifies the day.
460 /// </param>
461 /// <param name="era">An integer that specifies the era.
462 /// </param>
463 /// <returns>A boolean that tells whether the given day is a leap
464 /// day.
465 /// </returns>
466 /// <exception cref="T:System.ArgumentOutOfRangeException">
467 /// The exception is thrown, if the year, month, day, or era is not
468 /// valid.
469 /// </exception>
470 public override bool IsLeapDay(int year, int month, int day, int era)
472 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
473 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
476 /// <summary>
477 /// Overridden. Tells whether the given month
478 /// is a leap month.
479 /// </summary>
480 /// <param name="year">An integer that specifies the year in the
481 /// given era.
482 /// </param>
483 /// <param name="month">An integer that specifies the month.
484 /// </param>
485 /// <param name="era">An integer that specifies the era.
486 /// </param>
487 /// <returns>A boolean that tells whether the given month is a leap
488 /// month.
489 /// </returns>
490 /// <exception cref="T:System.ArgumentOutOfRangeException">
491 /// The exception is thrown, if the year, month, or era is not
492 /// valid.
493 /// </exception>
494 public override bool IsLeapMonth(int year, int month, int era) {
495 M_CheckYMEG(year, month, ref era);
496 return false;
499 /// <summary>
500 /// Overridden. Tells whether the given year
501 /// is a leap year.
502 /// </summary>
503 /// <param name="year">An integer that specifies the year in the
504 /// given era.
505 /// </param>
506 /// <param name="era">An integer that specifies the era.
507 /// </param>
508 /// <returns>A boolean that tells whether the given year is a leap
509 /// year.
510 /// </returns>
511 /// <exception cref="T:System.ArgumentOutOfRangeException">
512 /// The exception is thrown, if the year or era is not
513 /// valid.
514 /// </exception>
515 public override bool IsLeapYear(int year, int era) {
516 int gregorianYear = M_CheckYEG(year, ref era);
517 return CCGregorianCalendar.is_leap_year(gregorianYear);
520 /// <summary>
521 /// Overridden. Creates the
522 /// <see cref="T:System.DateTime"/> from the parameters.
523 /// </summary>
524 /// <param name="year">An integer that gives the year in the
525 /// <paramref name="era"/>.
526 /// </param>
527 /// <param name="month">An integer that specifies the month.
528 /// </param>
529 /// <param name="day">An integer that specifies the day.
530 /// </param>
531 /// <param name="hour">An integer that specifies the hour.
532 /// </param>
533 /// <param name="minute">An integer that specifies the minute.
534 /// </param>
535 /// <param name="second">An integer that gives the second.
536 /// </param>
537 /// <param name="milliseconds">An integer that gives the
538 /// milliseconds.
539 /// </param>
540 /// <param name="era">An integer that specifies the era.
541 /// </param>
542 /// <returns>A
543 /// <see cref="T:system.DateTime"/> representig the date and time.
544 /// </returns>
545 /// <exception cref="T:System.ArgumentOutOfRangeException">
546 /// The exception is thrown, if at least one of the parameters
547 /// is out of range.
548 /// </exception>
549 public override DateTime ToDateTime(int year, int month, int day,
550 int hour, int minute, int second, int millisecond,
551 int era)
553 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
554 M_CheckHMSM(hour, minute, second, millisecond);
555 return CCGregorianCalendar.ToDateTime(
556 gregorianYear, month, day,
557 hour, minute, second, millisecond);
560 /// <summary>
561 /// This functions returns simply the year for the Taiwan calendar.
562 /// </summary>
563 /// <param name="year">An integer that gives the year.
564 /// </param>
565 /// <returns>The same argument as the year.
566 /// </returns>
567 /// <exception cref="T:System.ArgumentOutOfRangeException">
568 /// The exception is thrown if the year is negative or the resulting
569 /// year is invalid.
570 /// </exception>
571 public override int ToFourDigitYear(int year) {
572 if (year < 0)
573 throw new ArgumentOutOfRangeException(
574 "year", "Non-negative number required.");
575 int era = CurrentEra;
576 M_CheckYE(year, ref era);
577 return year;
580 #if !NET_2_1
581 [ComVisible (false)]
582 public override CalendarAlgorithmType AlgorithmType {
583 get {
584 return CalendarAlgorithmType.SolarCalendar;
587 #endif
589 static DateTime TaiwanMin = new DateTime (1912, 1, 1, 0, 0, 0);
590 static DateTime TaiwanMax = new DateTime (9999, 12, 31, 11, 59, 59);
592 [ComVisible (false)]
593 public override DateTime MinSupportedDateTime {
594 get {
595 return TaiwanMin;
599 [ComVisible (false)]
600 public override DateTime MaxSupportedDateTime {
601 get {
602 return TaiwanMax;
605 } // class TaiwanCalendar
607 } // namespace System.Globalization