3 // (C) Ulrich Kunitz 2002
6 namespace System.Globalization {
11 /// This is the Japanese calendar. It differs from the Gregorian calendar
12 /// only in the years.
15 /// <para>The Japanese calendar support a single era starting at January 1,
17 /// <para>The implementation uses the
18 /// <see cref="N:CalendricalCalculations"/> namespace.
22 public class TaiwanCalendar : Calendar {
24 /// Static protected field storing the
25 /// <see cref="T:CalendricalCalculations.GregorianEraHandler"/>.
27 internal static readonly CCGregorianEraHandler M_EraHandler;
30 /// Static constructor, who creates and initializes
31 /// <see cref="F:M_EraHandler"/>.
33 static TaiwanCalendar() {
34 M_EraHandler = new CCGregorianEraHandler();
35 M_EraHandler.appendEra(1,
36 CCGregorianCalendar.fixed_from_dmy(1, 1, 1912));
40 /// Default constructor.
42 public TaiwanCalendar() {
43 M_AbbrEraNames = new string[] {"T.C.E."};
44 M_EraNames = new string[] {"Taiwan current era"};
47 /// <value>Overridden. Gives the eras supported by the
48 /// calendar as an array of integers.
50 public override int[] Eras {
52 return (int[])M_EraHandler.Eras.Clone();
56 int twoDigitYearMax = 99;
58 public override int TwoDigitYearMax
61 return twoDigitYearMax;
64 M_ArgumentInRange ("value", value, 100, M_MaxYear);
66 twoDigitYearMax = value;
71 /// A protected member checking a
72 /// <see cref="T:System.DateTime"/> value.
74 /// <param name="time">The
75 /// <see cref="T:System.DateTime"/>
78 /// <exception cref="T:System.ArgumentOutOfRangeException">
79 /// The exception is thrown if the
80 /// <see cref="T:System.DateTime"/> parameter is outside all
83 internal void M_CheckDateTime(DateTime time) {
84 M_EraHandler.CheckDateTime(time);
88 /// A protected method checking the era number.
90 /// <param name="era">The era number as reference. It is set
91 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
92 /// <exception name="T:System.ArgumentException">
93 /// The exception is thrown if the era is not supported by the class.
95 internal void M_CheckEra(ref int era) {
96 if (era == CurrentEra)
98 if (!M_EraHandler.ValidEra(era))
99 throw new ArgumentException("Era value was not valid.");
103 /// A protected method checking calendar year and the era number.
105 /// <param name="year">An integer representing the calendar year.
107 /// <param name="era">The era number as reference.</param>
108 /// <exception name="T:System.ArgumentException">
109 /// The exception is thrown if the era is not supported by the class.
111 /// <exception cref="T:System.ArgumentOutOfRangeException">
112 /// The exception is thrown if the calendar year is outside of
113 /// the supported range.
115 internal int M_CheckYEG(int year, ref int era) {
117 return M_EraHandler.GregorianYear(year, era);
121 /// Checks whether the year is the era is valid, if era = CurrentEra
122 /// the right value is set.
124 /// <param name="year">The year to check.</param>
125 /// <param name="era">The era to check.</Param>
126 /// <exception cref="T:ArgumentOutOfRangeException">
127 /// The exception will be thrown, if the year is not valid.
129 internal override void M_CheckYE(int year, ref int era) {
130 M_CheckYEG(year, ref era);
134 /// A protected method checking the calendar year, month, and
137 /// <param name="year">An integer representing the calendar year.
139 /// <param name="month">An integer giving the calendar month.
141 /// <param name="era">The era number as reference.</param>
142 /// <exception name="T:System.ArgumentException">
143 /// The exception is thrown if the era is not supported by the class.
145 /// <exception cref="T:System.ArgumentOutOfRangeException">
146 /// The exception is thrown if the calendar year or month is
147 /// outside of the supported range.
149 internal int M_CheckYMEG(int year, int month, ref int era) {
150 int gregorianYear = M_CheckYEG(year, ref era);
151 if (month < 1 || month > 12)
152 throw new ArgumentOutOfRangeException("month",
153 "Month must be between one and twelve.");
154 return gregorianYear;
158 /// A protected method checking the calendar day, month, and year
159 /// and the era number.
161 /// <param name="year">An integer representing the calendar year.
163 /// <param name="month">An integer giving the calendar month.
165 /// <param name="day">An integer giving the calendar day.
167 /// <param name="era">The era number as reference.</param>
168 /// <exception name="T:System.ArgumentException">
169 /// The exception is thrown if the era is not supported by the class.
171 /// <exception cref="T:System.ArgumentOutOfRangeException">
172 /// The exception is thrown if the calendar year, month, or day is
173 /// outside of the supported range.
175 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
177 int gregorianYear = M_CheckYMEG(year, month, ref era);
178 M_ArgumentInRange("day", day, 1,
179 GetDaysInMonth(year, month, era));
180 return gregorianYear;
185 // Ifdefed out because this is not on the .NET Framework
188 /// Overridden. Adds days to a given date.
190 /// <param name="time">The
191 /// <see cref="T:System.DateTime"/> to which to add
194 /// <param name="days">The number of days to add.</param>
195 /// <returns>A new <see cref="T:System.DateTime"/> value, that
196 /// results from adding <paramref name="days"/> to the specified
197 /// DateTime.</returns>
198 /// <exception cref="T:System.ArgumentOutOfRangeException">
199 /// The exception is thrown if the
200 /// <see cref="T:System.DateTime"/> return value is outside all
203 public override DateTime AddDays(DateTime time, int days) {
204 DateTime t = base.AddDays(time, days);
210 /// Overridden. Adds hours to a given date.
212 /// <param name="time">The
213 /// <see cref="T:System.DateTime"/> to which to add
216 /// <param name="hours">The number of hours to add.</param>
217 /// <returns>A new <see cref="T:System.DateTime"/> value, that
218 /// results from adding <paramref name="hours"/> to the specified
219 /// DateTime.</returns>
220 /// <exception cref="T:System.ArgumentOutOfRangeException">
221 /// The exception is thrown if the
222 /// <see cref="T:System.DateTime"/> return value is outside all
225 public override DateTime AddHours(DateTime time, int hours) {
226 DateTime t = base.AddHours(time, hours);
232 /// Overridden. Adds milliseconds to a given date.
234 /// <param name="time">The
235 /// <see cref="T:System.DateTime"/> to which to add
238 /// <param name="milliseconds">The number of milliseconds given as
239 /// double to add. Keep in mind the 100 nanosecond resolution of
240 /// <see cref="T:System.DateTime"/>.
242 /// <returns>A new <see cref="T:System.DateTime"/> value, that
243 /// results from adding <paramref name="milliseconds"/> to the specified
244 /// DateTime.</returns>
245 /// <exception cref="T:System.ArgumentOutOfRangeException">
246 /// The exception is thrown if the
247 /// <see cref="T:System.DateTime"/> return value is outside all
250 public override DateTime AddMilliseconds(DateTime time,
253 DateTime t = base.AddMilliseconds(time, milliseconds);
259 /// Overridden. Adds minutes to a given date.
261 /// <param name="time">The
262 /// <see cref="T:System.DateTime"/> to which to add
265 /// <param name="minutes">The number of minutes to add.</param>
266 /// <returns>A new <see cref="T:System.DateTime"/> value, that
267 /// results from adding <paramref name="minutes"/> to the specified
268 /// DateTime.</returns>
269 /// <exception cref="T:System.ArgumentOutOfRangeException">
270 /// The exception is thrown if the
271 /// <see cref="T:System.DateTime"/> return value is outside all
274 public override DateTime AddMinutes(DateTime time, int minutes) {
275 DateTime t = base.AddMinutes(time, minutes);
281 /// Overridden. Adds seconds to a given date.
283 /// <param name="time">The
284 /// <see cref="T:System.DateTime"/> to which to add
287 /// <param name="seconds">The number of seconds to add.</param>
288 /// <returns>A new <see cref="T:System.DateTime"/> value, that
289 /// results from adding <paramref name="seconds"/> to the specified
290 /// DateTime.</returns>
291 /// <exception cref="T:System.ArgumentOutOfRangeException">
292 /// The exception is thrown if the
293 /// <see cref="T:System.DateTime"/> return value is outside all
296 public override DateTime AddSeconds(DateTime time, int seconds) {
297 DateTime t = base.AddSeconds(time, seconds);
304 /// Overridden. Adds weeks to a given date.
306 /// <param name="time">The
307 /// <see cref="T:System.DateTime"/> to which to add
310 /// <param name="weeks">The number of weeks to add.</param>
311 /// <returns>A new <see cref="T:System.DateTime"/> value, that
312 /// results from adding <paramref name="weeks"/> to the specified
313 /// DateTime.</returns>
314 /// <exception cref="T:System.ArgumentOutOfRangeException">
315 /// The exception is thrown if the
316 /// <see cref="T:System.DateTime"/> return value is outside all
319 public override DateTime AddWeeks(DateTime time, int weeks) {
320 DateTime t = base.AddWeeks(time, weeks);
326 /// Overridden. Gives the hour of the specified time.
328 /// <param name="time">The
329 /// <see cref="T:System.DateTime"/> that specifies the
332 /// <returns>An integer that gives the hour of the specified time,
333 /// starting with 0.</returns>
334 /// <exception cref="T:System.ArgumentOutOfRangeException">
335 /// The exception is thrown if the
336 /// <see cref="T:System.DateTime"/> parameter is outside all
339 public override int GetHour(DateTime time) {
340 M_CheckDateTime(time);
341 return base.GetHour(time);
345 /// Overridden. Gives the milliseconds in the current second
346 /// of the specified time.
348 /// <param name="time">The
349 /// <see cref="T:System.DateTime"/> that specifies the
352 /// <returns>An integer that gives the milliseconds in the seconds
353 /// of the specified time, starting with 0.</returns>
354 /// <exception cref="T:System.ArgumentOutOfRangeException">
355 /// The exception is thrown if the
356 /// <see cref="T:System.DateTime"/> parameter is outside all
359 public override double GetMilliseconds(DateTime time) {
360 M_CheckDateTime(time);
361 return base.GetMilliseconds(time);
365 /// Overridden. Gives the minute of the specified time.
367 /// <param name="time">The
368 /// <see cref="T:System.DateTime"/> that specifies the
371 /// <returns>An integer that gives the minute of the specified time,
372 /// starting with 0.</returns>
373 /// <exception cref="T:System.ArgumentOutOfRangeException">
374 /// The exception is thrown if the
375 /// <see cref="T:System.DateTime"/> parameter is outside all
378 public override int GetMinute(DateTime time) {
379 M_CheckDateTime(time);
380 return base.GetMinute(time);
384 /// Overridden. Gives the second of the specified time.
386 /// <param name="time">The
387 /// <see cref="T:System.DateTime"/> that specifies the
390 /// <returns>An integer that gives the second of the specified time,
391 /// starting with 0.</returns>
392 /// <exception cref="T:System.ArgumentOutOfRangeException">
393 /// The exception is thrown if the
394 /// <see cref="T:System.DateTime"/> parameter is outside all
397 public override int GetSecond(DateTime time) {
398 M_CheckDateTime(time);
399 return base.GetMinute(time);
404 /// Overrideden. Adds months to a given date.
406 /// <param name="time">The
407 /// <see cref="T:System.DateTime"/> to which to add
410 /// <param name="months">The number of months to add.</param>
411 /// <returns>A new <see cref="T:System.DateTime"/> value, that
412 /// results from adding <paramref name="months"/> to the specified
413 /// DateTime.</returns>
414 /// <exception cref="T:System.ArgumentOutOfRangeException">
415 /// The exception is thrown if
416 /// <see cref="T:System.DateTime"/> return value is outside all
419 public override DateTime AddMonths(DateTime time, int months) {
420 DateTime t = CCGregorianCalendar.AddMonths(time, months);
426 /// Overridden. Adds years to a given date.
428 /// <param name="time">The
429 /// <see cref="T:System.DateTime"/> to which to add
432 /// <param name="years">The number of years to add.</param>
433 /// <returns>A new <see cref="T:System.DateTime"/> value, that
434 /// results from adding <paramref name="years"/> to the specified
435 /// DateTime.</returns>
436 /// <exception cref="T:System.ArgumentOutOfRangeException">
437 /// The exception is thrown if
438 /// <see cref="T:System.DateTime"/> return value is outside all
441 public override DateTime AddYears(DateTime time, int years) {
442 DateTime t = CCGregorianCalendar.AddYears(time, years);
448 /// Overriden. Gets the day of the month from
449 /// <paramref name="time"/>.
451 /// <param name="time">The
452 /// <see cref="T:System.DateTime"/> that specifies a
455 /// <returns>An integer giving the day of months, starting with 1.
457 /// <exception cref="T:System.ArgumentOutOfRangeException">
458 /// The exception is thrown if the
459 /// <see cref="T:System.DateTime"/> parameter is outside all
462 public override int GetDayOfMonth(DateTime time) {
463 M_CheckDateTime(time);
464 return CCGregorianCalendar.GetDayOfMonth(time);
468 /// Overriden. Gets the day of the week from the specified date.
470 /// <param name="time">The
471 /// <see cref="T:System.DateTime"/> that specifies a
474 /// <returns>An integer giving the day of months, starting with 1.
476 /// <exception cref="T:System.ArgumentOutOfRangeException">
477 /// The exception is thrown if the
478 /// <see cref="T:System.DateTime"/> parameter is outside all
481 public override DayOfWeek GetDayOfWeek(DateTime time) {
482 M_CheckDateTime(time);
483 int rd = CCFixed.FromDateTime(time);
484 return (DayOfWeek)CCFixed.day_of_week(rd);
488 /// Overridden. Gives the number of the day in the year.
490 /// <param name="time">The
491 /// <see cref="T:System.DateTime"/> that specifies a
494 /// <returns>An integer representing the day of the year,
495 /// starting with 1.</returns>
496 /// <exception cref="T:System.ArgumentOutOfRangeException">
497 /// The exception is thrown if the
498 /// <see cref="T:System.DateTime"/> parameter is outside all
501 public override int GetDayOfYear(DateTime time) {
502 M_CheckDateTime(time);
503 return CCGregorianCalendar.GetDayOfYear(time);
507 /// Overridden. Gives the number of days in the specified month
508 /// of the given year and era.
510 /// <param name="year">An integer that gives the year.
512 /// <param name="month">An integer that gives the month, starting
514 /// <param name="era">An integer that gives the era of the specified
516 /// <returns>An integer that gives the number of days of the
517 /// specified month.</returns>
518 /// <exception cref="T:System.ArgumentOutOfRangeException">
519 /// The exception is thrown, if <paramref name="month"/>,
520 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
521 /// the allowed range.
523 public override int GetDaysInMonth(int year, int month, int era) {
524 int gregorianYear = M_CheckYMEG(year, month, ref era);
525 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
529 /// Overridden. Gives the number of days of the specified
530 /// year of the given era.
532 /// <param name="year">An integer that specifies the year.
534 /// <param name="era">An ineger that specifies the era.
536 /// <returns>An integer that gives the number of days of the
537 /// specified year.</returns>
538 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
539 /// The exception is thrown, if
540 /// <paramref name="year"/> or <paramref name="era"/> are outside the
543 public override int GetDaysInYear(int year, int era) {
544 int gregorianYear = M_CheckYEG(year, ref era);
545 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
550 /// Overridden. Gives the era of the specified date.
552 /// <param name="time">The
553 /// <see cref="T:System.DateTime"/> that specifies a
556 /// <returns>An integer representing the era of the calendar.
558 /// <exception cref="T:System.ArgumentOutOfRangeException">
559 /// The exception is thrown if the
560 /// <see cref="T:System.DateTime"/> parameter is outside all
563 public override int GetEra(DateTime time) {
564 // M_CheckDateTime not needed, because EraYear does the
566 int rd = CCFixed.FromDateTime(time);
568 M_EraHandler.EraYear(out era, rd);
573 /// Overridden. Gives the number of the month of the specified
576 /// <param name="time">The
577 /// <see cref="T:System.DateTime"/> that specifies a
580 /// <returns>An integer representing the month,
581 /// starting with 1.</returns>
582 /// <exception cref="T:System.ArgumentOutOfRangeException">
583 /// The exception is thrown if the
584 /// <see cref="T:System.DateTime"/> parameter is outside all
587 public override int GetMonth(DateTime time) {
588 M_CheckDateTime(time);
589 return CCGregorianCalendar.GetMonth(time);
593 /// Overridden. Gives the number of months in the specified year
596 /// <param name="year">An integer that specifies the year.
598 /// <param name="era">An integer that specifies the era.
600 /// <returns>An integer that gives the number of the months in the
601 /// specified year.</returns>
602 /// <exception cref="T:System.ArgumentOutOfRangeException">
603 /// The exception is thrown, if the year or the era are not valid.
605 public override int GetMonthsInYear(int year, int era) {
606 M_CheckYEG(year, ref era);
611 /// Overridden. Gives the number of the year of the specified
614 /// <param name="time">The
615 /// <see cref="T:System.DateTime"/> that specifies a
618 /// <returns>An integer representing the year,
619 /// starting with 1.</returns>
620 /// <exception cref="T:System.ArgumentOutOfRangeException">
621 /// The exception is thrown if the
622 /// <see cref="T:System.DateTime"/> parameter is outside all
625 public override int GetYear(DateTime time) {
626 // M_CheckDateTime not needed, because EraYeat does the
628 int rd = CCFixed.FromDateTime(time);
630 return M_EraHandler.EraYear(out era, rd);
634 /// Overridden. Tells whether the given day
637 /// <param name="year">An integer that specifies the year in the
640 /// <param name="month">An integer that specifies the month.
642 /// <param name="day">An integer that specifies the day.
644 /// <param name="era">An integer that specifies the era.
646 /// <returns>A boolean that tells whether the given day is a leap
649 /// <exception cref="T:System.ArgumentOutOfRangeException">
650 /// The exception is thrown, if the year, month, day, or era is not
653 public override bool IsLeapDay(int year, int month, int day, int era)
655 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
656 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
660 /// Overridden. Tells whether the given month
663 /// <param name="year">An integer that specifies the year in the
666 /// <param name="month">An integer that specifies the month.
668 /// <param name="era">An integer that specifies the era.
670 /// <returns>A boolean that tells whether the given month is a leap
673 /// <exception cref="T:System.ArgumentOutOfRangeException">
674 /// The exception is thrown, if the year, month, or era is not
677 public override bool IsLeapMonth(int year, int month, int era) {
678 M_CheckYMEG(year, month, ref era);
683 /// Overridden. Tells whether the given year
686 /// <param name="year">An integer that specifies the year in the
689 /// <param name="era">An integer that specifies the era.
691 /// <returns>A boolean that tells whether the given year is a leap
694 /// <exception cref="T:System.ArgumentOutOfRangeException">
695 /// The exception is thrown, if the year or era is not
698 public override bool IsLeapYear(int year, int era) {
699 int gregorianYear = M_CheckYEG(year, ref era);
700 return CCGregorianCalendar.is_leap_year(gregorianYear);
704 /// Overridden. Creates the
705 /// <see cref="T:System.DateTime"/> from the parameters.
707 /// <param name="year">An integer that gives the year in the
708 /// <paramref name="era"/>.
710 /// <param name="month">An integer that specifies the month.
712 /// <param name="day">An integer that specifies the day.
714 /// <param name="hour">An integer that specifies the hour.
716 /// <param name="minute">An integer that specifies the minute.
718 /// <param name="second">An integer that gives the second.
720 /// <param name="milliseconds">An integer that gives the
723 /// <param name="era">An integer that specifies the era.
726 /// <see cref="T:system.DateTime"/> representig the date and time.
728 /// <exception cref="T:System.ArgumentOutOfRangeException">
729 /// The exception is thrown, if at least one of the parameters
732 public override DateTime ToDateTime(int year, int month, int day,
733 int hour, int minute, int second, int milliseconds,
736 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
737 M_CheckHMSM(hour, minute, second, milliseconds);
738 return CCGregorianCalendar.ToDateTime(
739 gregorianYear, month, day,
740 hour, minute, second, milliseconds);
744 /// This functions returns simply the year for the Taiwan calendar.
746 /// <param name="year">An integer that gives the year.
748 /// <returns>The same argument as the year.
750 /// <exception cref="T:System.ArgumentOutOfRangeException">
751 /// The exception is thrown if the year is negative or the resulting
754 public override int ToFourDigitYear(int year) {
756 throw new ArgumentOutOfRangeException(
757 "year", "Non-negative number required.");
758 int era = CurrentEra;
759 M_CheckYE(year, ref era);
762 } // class TaiwanCalendar
764 } // namespace System.Globalization