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();
57 /// A protected member checking a
58 /// <see cref="T:System.DateTime"/> value.
60 /// <param name="time">The
61 /// <see cref="T:System.DateTime"/>
64 /// <exception cref="T:System.ArgumentOutOfRangeException">
65 /// The exception is thrown if the
66 /// <see cref="T:System.DateTime"/> parameter is outside all
69 internal void M_CheckDateTime(DateTime time) {
70 M_EraHandler.CheckDateTime(time);
74 /// A protected method checking the era number.
76 /// <param name="era">The era number as reference. It is set
77 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
78 /// <exception name="T:System.ArgumentException">
79 /// The exception is thrown if the era is not supported by the class.
81 internal void M_CheckEra(ref int era) {
82 if (era == CurrentEra)
84 if (!M_EraHandler.ValidEra(era))
85 throw new ArgumentException("Era value was not valid.");
89 /// A protected method checking calendar year and the era number.
91 /// <param name="year">An integer representing the calendar year.
93 /// <param name="era">The era number as reference.</param>
94 /// <exception name="T:System.ArgumentException">
95 /// The exception is thrown if the era is not supported by the class.
97 /// <exception cref="T:System.ArgumentOutOfRangeException">
98 /// The exception is thrown if the calendar year is outside of
99 /// the supported range.
101 internal int M_CheckYEG(int year, ref int era) {
103 return M_EraHandler.GregorianYear(year, era);
107 /// Checks whether the year is the era is valid, if era = CurrentEra
108 /// the right value is set.
110 /// <param name="year">The year to check.</param>
111 /// <param name="era">The era to check.</Param>
112 /// <exception cref="T:ArgumentOutOfRangeException">
113 /// The exception will be thrown, if the year is not valid.
115 internal override void M_CheckYE(int year, ref int era) {
116 M_CheckYEG(year, ref era);
120 /// A protected method checking the calendar year, month, and
123 /// <param name="year">An integer representing the calendar year.
125 /// <param name="month">An integer giving the calendar month.
127 /// <param name="era">The era number as reference.</param>
128 /// <exception name="T:System.ArgumentException">
129 /// The exception is thrown if the era is not supported by the class.
131 /// <exception cref="T:System.ArgumentOutOfRangeException">
132 /// The exception is thrown if the calendar year or month is
133 /// outside of the supported range.
135 internal int M_CheckYMEG(int year, int month, ref int era) {
136 int gregorianYear = M_CheckYEG(year, ref era);
137 if (month < 1 || month > 12)
138 throw new ArgumentOutOfRangeException("month",
139 "Month must be between one and twelve.");
140 return gregorianYear;
144 /// A protected method checking the calendar day, month, and year
145 /// and the era number.
147 /// <param name="year">An integer representing the calendar year.
149 /// <param name="month">An integer giving the calendar month.
151 /// <param name="day">An integer giving the calendar day.
153 /// <param name="era">The era number as reference.</param>
154 /// <exception name="T:System.ArgumentException">
155 /// The exception is thrown if the era is not supported by the class.
157 /// <exception cref="T:System.ArgumentOutOfRangeException">
158 /// The exception is thrown if the calendar year, month, or day is
159 /// outside of the supported range.
161 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
163 int gregorianYear = M_CheckYMEG(year, month, ref era);
164 M_ArgumentInRange("day", day, 1,
165 GetDaysInMonth(year, month, era));
166 return gregorianYear;
170 /// Overridden. Adds days to a given date.
172 /// <param name="time">The
173 /// <see cref="T:System.DateTime"/> to which to add
176 /// <param name="days">The number of days to add.</param>
177 /// <returns>A new <see cref="T:System.DateTime"/> value, that
178 /// results from adding <paramref name="days"/> to the specified
179 /// DateTime.</returns>
180 /// <exception cref="T:System.ArgumentOutOfRangeException">
181 /// The exception is thrown if the
182 /// <see cref="T:System.DateTime"/> return value is outside all
185 public override DateTime AddDays(DateTime time, int days) {
186 DateTime t = base.AddDays(time, days);
192 /// Overridden. Adds hours to a given date.
194 /// <param name="time">The
195 /// <see cref="T:System.DateTime"/> to which to add
198 /// <param name="hours">The number of hours to add.</param>
199 /// <returns>A new <see cref="T:System.DateTime"/> value, that
200 /// results from adding <paramref name="hours"/> to the specified
201 /// DateTime.</returns>
202 /// <exception cref="T:System.ArgumentOutOfRangeException">
203 /// The exception is thrown if the
204 /// <see cref="T:System.DateTime"/> return value is outside all
207 public override DateTime AddHours(DateTime time, int hours) {
208 DateTime t = base.AddHours(time, hours);
214 /// Overridden. Adds milliseconds to a given date.
216 /// <param name="time">The
217 /// <see cref="T:System.DateTime"/> to which to add
220 /// <param name="milliseconds">The number of milliseconds given as
221 /// double to add. Keep in mind the 100 nanosecond resolution of
222 /// <see cref="T:System.DateTime"/>.
224 /// <returns>A new <see cref="T:System.DateTime"/> value, that
225 /// results from adding <paramref name="milliseconds"/> to the specified
226 /// DateTime.</returns>
227 /// <exception cref="T:System.ArgumentOutOfRangeException">
228 /// The exception is thrown if the
229 /// <see cref="T:System.DateTime"/> return value is outside all
232 public override DateTime AddMilliseconds(DateTime time,
235 DateTime t = base.AddMilliseconds(time, milliseconds);
241 /// Overridden. Adds minutes to a given date.
243 /// <param name="time">The
244 /// <see cref="T:System.DateTime"/> to which to add
247 /// <param name="minutes">The number of minutes to add.</param>
248 /// <returns>A new <see cref="T:System.DateTime"/> value, that
249 /// results from adding <paramref name="minutes"/> to the specified
250 /// DateTime.</returns>
251 /// <exception cref="T:System.ArgumentOutOfRangeException">
252 /// The exception is thrown if the
253 /// <see cref="T:System.DateTime"/> return value is outside all
256 public override DateTime AddMinutes(DateTime time, int minutes) {
257 DateTime t = base.AddMinutes(time, minutes);
263 /// Overridden. Adds seconds to a given date.
265 /// <param name="time">The
266 /// <see cref="T:System.DateTime"/> to which to add
269 /// <param name="seconds">The number of seconds to add.</param>
270 /// <returns>A new <see cref="T:System.DateTime"/> value, that
271 /// results from adding <paramref name="seconds"/> to the specified
272 /// DateTime.</returns>
273 /// <exception cref="T:System.ArgumentOutOfRangeException">
274 /// The exception is thrown if the
275 /// <see cref="T:System.DateTime"/> return value is outside all
278 public override DateTime AddSeconds(DateTime time, int seconds) {
279 DateTime t = base.AddSeconds(time, seconds);
286 /// Overridden. Adds weeks to a given date.
288 /// <param name="time">The
289 /// <see cref="T:System.DateTime"/> to which to add
292 /// <param name="weeks">The number of weeks to add.</param>
293 /// <returns>A new <see cref="T:System.DateTime"/> value, that
294 /// results from adding <paramref name="weeks"/> to the specified
295 /// DateTime.</returns>
296 /// <exception cref="T:System.ArgumentOutOfRangeException">
297 /// The exception is thrown if the
298 /// <see cref="T:System.DateTime"/> return value is outside all
301 public override DateTime AddWeeks(DateTime time, int weeks) {
302 DateTime t = base.AddWeeks(time, weeks);
308 /// Overridden. Gives the hour of the specified time.
310 /// <param name="time">The
311 /// <see cref="T:System.DateTime"/> that specifies the
314 /// <returns>An integer that gives the hour of the specified time,
315 /// starting with 0.</returns>
316 /// <exception cref="T:System.ArgumentOutOfRangeException">
317 /// The exception is thrown if the
318 /// <see cref="T:System.DateTime"/> parameter is outside all
321 public override int GetHour(DateTime time) {
322 M_CheckDateTime(time);
323 return base.GetHour(time);
327 /// Overridden. Gives the milliseconds in the current second
328 /// of the specified time.
330 /// <param name="time">The
331 /// <see cref="T:System.DateTime"/> that specifies the
334 /// <returns>An integer that gives the milliseconds in the seconds
335 /// of the specified time, starting with 0.</returns>
336 /// <exception cref="T:System.ArgumentOutOfRangeException">
337 /// The exception is thrown if the
338 /// <see cref="T:System.DateTime"/> parameter is outside all
341 public override double GetMilliseconds(DateTime time) {
342 M_CheckDateTime(time);
343 return base.GetMilliseconds(time);
347 /// Overridden. Gives the minute of the specified time.
349 /// <param name="time">The
350 /// <see cref="T:System.DateTime"/> that specifies the
353 /// <returns>An integer that gives the minute of the specified time,
354 /// starting with 0.</returns>
355 /// <exception cref="T:System.ArgumentOutOfRangeException">
356 /// The exception is thrown if the
357 /// <see cref="T:System.DateTime"/> parameter is outside all
360 public override int GetMinute(DateTime time) {
361 M_CheckDateTime(time);
362 return base.GetMinute(time);
366 /// Overridden. Gives the second of the specified time.
368 /// <param name="time">The
369 /// <see cref="T:System.DateTime"/> that specifies the
372 /// <returns>An integer that gives the second of the specified time,
373 /// starting with 0.</returns>
374 /// <exception cref="T:System.ArgumentOutOfRangeException">
375 /// The exception is thrown if the
376 /// <see cref="T:System.DateTime"/> parameter is outside all
379 public override int GetSecond(DateTime time) {
380 M_CheckDateTime(time);
381 return base.GetMinute(time);
385 /// Overrideden. Adds months to a given date.
387 /// <param name="time">The
388 /// <see cref="T:System.DateTime"/> to which to add
391 /// <param name="months">The number of months to add.</param>
392 /// <returns>A new <see cref="T:System.DateTime"/> value, that
393 /// results from adding <paramref name="months"/> to the specified
394 /// DateTime.</returns>
395 /// <exception cref="T:System.ArgumentOutOfRangeException">
396 /// The exception is thrown if
397 /// <see cref="T:System.DateTime"/> return value is outside all
400 public override DateTime AddMonths(DateTime time, int months) {
401 DateTime t = CCGregorianCalendar.AddMonths(time, months);
407 /// Overridden. Adds years to a given date.
409 /// <param name="time">The
410 /// <see cref="T:System.DateTime"/> to which to add
413 /// <param name="years">The number of years to add.</param>
414 /// <returns>A new <see cref="T:System.DateTime"/> value, that
415 /// results from adding <paramref name="years"/> to the specified
416 /// DateTime.</returns>
417 /// <exception cref="T:System.ArgumentOutOfRangeException">
418 /// The exception is thrown if
419 /// <see cref="T:System.DateTime"/> return value is outside all
422 public override DateTime AddYears(DateTime time, int years) {
423 DateTime t = CCGregorianCalendar.AddYears(time, years);
429 /// Overriden. Gets the day of the month from
430 /// <paramref name="time"/>.
432 /// <param name="time">The
433 /// <see cref="T:System.DateTime"/> that specifies a
436 /// <returns>An integer giving the day of months, starting with 1.
438 /// <exception cref="T:System.ArgumentOutOfRangeException">
439 /// The exception is thrown if the
440 /// <see cref="T:System.DateTime"/> parameter is outside all
443 public override int GetDayOfMonth(DateTime time) {
444 M_CheckDateTime(time);
445 return CCGregorianCalendar.GetDayOfMonth(time);
449 /// Overriden. Gets the day of the week from the specified date.
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 DayOfWeek GetDayOfWeek(DateTime time) {
463 M_CheckDateTime(time);
464 int rd = CCFixed.FromDateTime(time);
465 return (DayOfWeek)CCFixed.day_of_week(rd);
469 /// Overridden. Gives the number of the day in the year.
471 /// <param name="time">The
472 /// <see cref="T:System.DateTime"/> that specifies a
475 /// <returns>An integer representing the day of the year,
476 /// starting with 1.</returns>
477 /// <exception cref="T:System.ArgumentOutOfRangeException">
478 /// The exception is thrown if the
479 /// <see cref="T:System.DateTime"/> parameter is outside all
482 public override int GetDayOfYear(DateTime time) {
483 M_CheckDateTime(time);
484 return CCGregorianCalendar.GetDayOfYear(time);
488 /// Overridden. Gives the number of days in the specified month
489 /// of the given year and era.
491 /// <param name="year">An integer that gives the year.
493 /// <param name="month">An integer that gives the month, starting
495 /// <param name="era">An integer that gives the era of the specified
497 /// <returns>An integer that gives the number of days of the
498 /// specified month.</returns>
499 /// <exception cref="T:System.ArgumentOutOfRangeException">
500 /// The exception is thrown, if <paramref name="month"/>,
501 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
502 /// the allowed range.
504 public override int GetDaysInMonth(int year, int month, int era) {
505 int gregorianYear = M_CheckYMEG(year, month, ref era);
506 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
510 /// Overridden. Gives the number of days of the specified
511 /// year of the given era.
513 /// <param name="year">An integer that specifies the year.
515 /// <param name="era">An ineger that specifies the era.
517 /// <returns>An integer that gives the number of days of the
518 /// specified year.</returns>
519 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
520 /// The exception is thrown, if
521 /// <paramref name="year"/> or <paramref name="era"/> are outside the
524 public override int GetDaysInYear(int year, int era) {
525 int gregorianYear = M_CheckYEG(year, ref era);
526 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
531 /// Overridden. Gives the era of the specified date.
533 /// <param name="time">The
534 /// <see cref="T:System.DateTime"/> that specifies a
537 /// <returns>An integer representing the era of the calendar.
539 /// <exception cref="T:System.ArgumentOutOfRangeException">
540 /// The exception is thrown if the
541 /// <see cref="T:System.DateTime"/> parameter is outside all
544 public override int GetEra(DateTime time) {
545 // M_CheckDateTime not needed, because EraYear does the
547 int rd = CCFixed.FromDateTime(time);
549 M_EraHandler.EraYear(out era, rd);
554 /// Overridden. Gives the number of the month of the specified
557 /// <param name="time">The
558 /// <see cref="T:System.DateTime"/> that specifies a
561 /// <returns>An integer representing the month,
562 /// starting with 1.</returns>
563 /// <exception cref="T:System.ArgumentOutOfRangeException">
564 /// The exception is thrown if the
565 /// <see cref="T:System.DateTime"/> parameter is outside all
568 public override int GetMonth(DateTime time) {
569 M_CheckDateTime(time);
570 return CCGregorianCalendar.GetMonth(time);
574 /// Overridden. Gives the number of months in the specified year
577 /// <param name="year">An integer that specifies the year.
579 /// <param name="era">An integer that specifies the era.
581 /// <returns>An integer that gives the number of the months in the
582 /// specified year.</returns>
583 /// <exception cref="T:System.ArgumentOutOfRangeException">
584 /// The exception is thrown, if the year or the era are not valid.
586 public override int GetMonthsInYear(int year, int era) {
587 M_CheckYEG(year, ref era);
592 /// Overridden. Gives the number of the year of the specified
595 /// <param name="time">The
596 /// <see cref="T:System.DateTime"/> that specifies a
599 /// <returns>An integer representing the year,
600 /// starting with 1.</returns>
601 /// <exception cref="T:System.ArgumentOutOfRangeException">
602 /// The exception is thrown if the
603 /// <see cref="T:System.DateTime"/> parameter is outside all
606 public override int GetYear(DateTime time) {
607 // M_CheckDateTime not needed, because EraYeat does the
609 int rd = CCFixed.FromDateTime(time);
611 return M_EraHandler.EraYear(out era, rd);
615 /// Overridden. Tells whether the given day
618 /// <param name="year">An integer that specifies the year in the
621 /// <param name="month">An integer that specifies the month.
623 /// <param name="day">An integer that specifies the day.
625 /// <param name="era">An integer that specifies the era.
627 /// <returns>A boolean that tells whether the given day is a leap
630 /// <exception cref="T:System.ArgumentOutOfRangeException">
631 /// The exception is thrown, if the year, month, day, or era is not
634 public override bool IsLeapDay(int year, int month, int day, int era)
636 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
637 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
641 /// Overridden. Tells whether the given month
644 /// <param name="year">An integer that specifies the year in the
647 /// <param name="month">An integer that specifies the month.
649 /// <param name="era">An integer that specifies the era.
651 /// <returns>A boolean that tells whether the given month is a leap
654 /// <exception cref="T:System.ArgumentOutOfRangeException">
655 /// The exception is thrown, if the year, month, or era is not
658 public override bool IsLeapMonth(int year, int month, int era) {
659 M_CheckYMEG(year, month, ref era);
664 /// Overridden. Tells whether the given year
667 /// <param name="year">An integer that specifies the year in the
670 /// <param name="era">An integer that specifies the era.
672 /// <returns>A boolean that tells whether the given year is a leap
675 /// <exception cref="T:System.ArgumentOutOfRangeException">
676 /// The exception is thrown, if the year or era is not
679 public override bool IsLeapYear(int year, int era) {
680 int gregorianYear = M_CheckYEG(year, ref era);
681 return CCGregorianCalendar.is_leap_year(gregorianYear);
685 /// Overridden. Creates the
686 /// <see cref="T:System.DateTime"/> from the parameters.
688 /// <param name="year">An integer that gives the year in the
689 /// <paramref name="era"/>.
691 /// <param name="month">An integer that specifies the month.
693 /// <param name="day">An integer that specifies the day.
695 /// <param name="hour">An integer that specifies the hour.
697 /// <param name="minute">An integer that specifies the minute.
699 /// <param name="second">An integer that gives the second.
701 /// <param name="milliseconds">An integer that gives the
704 /// <param name="era">An integer that specifies the era.
707 /// <see cref="T:system.DateTime"/> representig the date and time.
709 /// <exception cref="T:System.ArgumentOutOfRangeException">
710 /// The exception is thrown, if at least one of the parameters
713 public override DateTime ToDateTime(int year, int month, int day,
714 int hour, int minute, int second, int milliseconds,
717 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
718 M_CheckHMSM(hour, minute, second, milliseconds);
719 return CCGregorianCalendar.ToDateTime(
720 gregorianYear, month, day,
721 hour, minute, second, milliseconds);
725 /// This functions returns simply the year for the Taiwan calendar.
727 /// <param name="year">An integer that gives the year.
729 /// <returns>The same argument as the year.
731 /// <exception cref="T:System.ArgumentOutOfRangeException">
732 /// The exception is thrown if the year is negative or the resulting
735 public override int ToFourDigitYear(int year) {
737 throw new ArgumentOutOfRangeException(
738 "year", "Non-negative number required.");
739 int era = CurrentEra;
740 M_CheckYE(year, ref era);
743 } // class TaiwanCalendar
745 } // namespace System.Globalization