3 // (C) Ulrich Kunitz 2002
7 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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 {
34 /// This is the Japanese calendar. It differs from the Gregorian calendar
35 /// only in the years.
38 /// <para>The Japanese calendar support a single era starting at January 1,
40 /// <para>The implementation uses the
41 /// <see cref="N:CalendricalCalculations"/> namespace.
45 [System.Runtime.InteropServices.ComVisible(true)]
48 [MonoTODO ("Fix serialization compatibility with MS.NET")]
49 public class TaiwanCalendar : Calendar {
51 /// Static protected field storing the
52 /// <see cref="T:CalendricalCalculations.GregorianEraHandler"/>.
54 internal static readonly CCGregorianEraHandler M_EraHandler;
57 /// Static constructor, who creates and initializes
58 /// <see cref="F:M_EraHandler"/>.
60 static TaiwanCalendar() {
61 M_EraHandler = new CCGregorianEraHandler();
62 M_EraHandler.appendEra(1,
63 CCGregorianCalendar.fixed_from_dmy(1, 1, 1912));
67 /// Default constructor.
69 public TaiwanCalendar() {
70 M_AbbrEraNames = new string[] {"T.C.E."};
71 M_EraNames = new string[] {"Taiwan current era"};
74 /// <value>Overridden. Gives the eras supported by the
75 /// calendar as an array of integers.
77 public override int[] Eras {
79 return (int[])M_EraHandler.Eras.Clone();
83 int twoDigitYearMax = 99;
85 public override int TwoDigitYearMax
88 return twoDigitYearMax;
91 M_ArgumentInRange ("value", value, 100, M_MaxYear);
93 twoDigitYearMax = value;
98 /// A protected member checking a
99 /// <see cref="T:System.DateTime"/> value.
101 /// <param name="time">The
102 /// <see cref="T:System.DateTime"/>
105 /// <exception cref="T:System.ArgumentOutOfRangeException">
106 /// The exception is thrown if the
107 /// <see cref="T:System.DateTime"/> parameter is outside all
110 internal void M_CheckDateTime(DateTime time) {
111 M_EraHandler.CheckDateTime(time);
115 /// A protected method checking the era number.
117 /// <param name="era">The era number as reference. It is set
118 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
119 /// <exception name="T:System.ArgumentException">
120 /// The exception is thrown if the era is not supported by the class.
122 internal void M_CheckEra(ref int era) {
123 if (era == CurrentEra)
125 if (!M_EraHandler.ValidEra(era))
126 throw new ArgumentException("Era value was not valid.");
130 /// A protected method checking calendar year and the era number.
132 /// <param name="year">An integer representing the calendar year.
134 /// <param name="era">The era number as reference.</param>
135 /// <exception name="T:System.ArgumentException">
136 /// The exception is thrown if the era is not supported by the class.
138 /// <exception cref="T:System.ArgumentOutOfRangeException">
139 /// The exception is thrown if the calendar year is outside of
140 /// the supported range.
142 internal int M_CheckYEG(int year, ref int era) {
144 return M_EraHandler.GregorianYear(year, era);
148 /// Checks whether the year is the era is valid, if era = CurrentEra
149 /// the right value is set.
151 /// <param name="year">The year to check.</param>
152 /// <param name="era">The era to check.</Param>
153 /// <exception cref="T:ArgumentOutOfRangeException">
154 /// The exception will be thrown, if the year is not valid.
156 internal override void M_CheckYE(int year, ref int era) {
157 M_CheckYEG(year, ref era);
161 /// A protected method checking the calendar year, month, and
164 /// <param name="year">An integer representing the calendar year.
166 /// <param name="month">An integer giving the calendar month.
168 /// <param name="era">The era number as reference.</param>
169 /// <exception name="T:System.ArgumentException">
170 /// The exception is thrown if the era is not supported by the class.
172 /// <exception cref="T:System.ArgumentOutOfRangeException">
173 /// The exception is thrown if the calendar year or month is
174 /// outside of the supported range.
176 internal int M_CheckYMEG(int year, int month, ref int era) {
177 int gregorianYear = M_CheckYEG(year, ref era);
178 if (month < 1 || month > 12)
179 throw new ArgumentOutOfRangeException("month",
180 "Month must be between one and twelve.");
181 return gregorianYear;
185 /// A protected method checking the calendar day, month, and year
186 /// and the era number.
188 /// <param name="year">An integer representing the calendar year.
190 /// <param name="month">An integer giving the calendar month.
192 /// <param name="day">An integer giving the calendar day.
194 /// <param name="era">The era number as reference.</param>
195 /// <exception name="T:System.ArgumentException">
196 /// The exception is thrown if the era is not supported by the class.
198 /// <exception cref="T:System.ArgumentOutOfRangeException">
199 /// The exception is thrown if the calendar year, month, or day is
200 /// outside of the supported range.
202 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
204 int gregorianYear = M_CheckYMEG(year, month, ref era);
205 M_ArgumentInRange("day", day, 1,
206 GetDaysInMonth(year, month, era));
207 return gregorianYear;
212 // Ifdefed out because this is not on the .NET Framework
215 /// Overridden. Adds days to a given date.
217 /// <param name="time">The
218 /// <see cref="T:System.DateTime"/> to which to add
221 /// <param name="days">The number of days to add.</param>
222 /// <returns>A new <see cref="T:System.DateTime"/> value, that
223 /// results from adding <paramref name="days"/> to the specified
224 /// DateTime.</returns>
225 /// <exception cref="T:System.ArgumentOutOfRangeException">
226 /// The exception is thrown if the
227 /// <see cref="T:System.DateTime"/> return value is outside all
230 public override DateTime AddDays(DateTime time, int days) {
231 DateTime t = base.AddDays(time, days);
237 /// Overridden. Adds hours to a given date.
239 /// <param name="time">The
240 /// <see cref="T:System.DateTime"/> to which to add
243 /// <param name="hours">The number of hours to add.</param>
244 /// <returns>A new <see cref="T:System.DateTime"/> value, that
245 /// results from adding <paramref name="hours"/> to the specified
246 /// DateTime.</returns>
247 /// <exception cref="T:System.ArgumentOutOfRangeException">
248 /// The exception is thrown if the
249 /// <see cref="T:System.DateTime"/> return value is outside all
252 public override DateTime AddHours(DateTime time, int hours) {
253 DateTime t = base.AddHours(time, hours);
259 /// Overridden. Adds milliseconds to a given date.
261 /// <param name="time">The
262 /// <see cref="T:System.DateTime"/> to which to add
265 /// <param name="milliseconds">The number of milliseconds given as
266 /// double to add. Keep in mind the 100 nanosecond resolution of
267 /// <see cref="T:System.DateTime"/>.
269 /// <returns>A new <see cref="T:System.DateTime"/> value, that
270 /// results from adding <paramref name="milliseconds"/> to the specified
271 /// DateTime.</returns>
272 /// <exception cref="T:System.ArgumentOutOfRangeException">
273 /// The exception is thrown if the
274 /// <see cref="T:System.DateTime"/> return value is outside all
277 public override DateTime AddMilliseconds(DateTime time,
280 DateTime t = base.AddMilliseconds(time, milliseconds);
286 /// Overridden. Adds minutes to a given date.
288 /// <param name="time">The
289 /// <see cref="T:System.DateTime"/> to which to add
292 /// <param name="minutes">The number of minutes to add.</param>
293 /// <returns>A new <see cref="T:System.DateTime"/> value, that
294 /// results from adding <paramref name="minutes"/> 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 AddMinutes(DateTime time, int minutes) {
302 DateTime t = base.AddMinutes(time, minutes);
308 /// Overridden. Adds seconds to a given date.
310 /// <param name="time">The
311 /// <see cref="T:System.DateTime"/> to which to add
314 /// <param name="seconds">The number of seconds to add.</param>
315 /// <returns>A new <see cref="T:System.DateTime"/> value, that
316 /// results from adding <paramref name="seconds"/> to the specified
317 /// DateTime.</returns>
318 /// <exception cref="T:System.ArgumentOutOfRangeException">
319 /// The exception is thrown if the
320 /// <see cref="T:System.DateTime"/> return value is outside all
323 public override DateTime AddSeconds(DateTime time, int seconds) {
324 DateTime t = base.AddSeconds(time, seconds);
331 /// Overridden. Adds weeks to a given date.
333 /// <param name="time">The
334 /// <see cref="T:System.DateTime"/> to which to add
337 /// <param name="weeks">The number of weeks to add.</param>
338 /// <returns>A new <see cref="T:System.DateTime"/> value, that
339 /// results from adding <paramref name="weeks"/> to the specified
340 /// DateTime.</returns>
341 /// <exception cref="T:System.ArgumentOutOfRangeException">
342 /// The exception is thrown if the
343 /// <see cref="T:System.DateTime"/> return value is outside all
346 public override DateTime AddWeeks(DateTime time, int weeks) {
347 DateTime t = base.AddWeeks(time, weeks);
353 /// Overridden. Gives the hour of the specified time.
355 /// <param name="time">The
356 /// <see cref="T:System.DateTime"/> that specifies the
359 /// <returns>An integer that gives the hour of the specified time,
360 /// starting with 0.</returns>
361 /// <exception cref="T:System.ArgumentOutOfRangeException">
362 /// The exception is thrown if the
363 /// <see cref="T:System.DateTime"/> parameter is outside all
366 public override int GetHour(DateTime time) {
367 M_CheckDateTime(time);
368 return base.GetHour(time);
372 /// Overridden. Gives the milliseconds in the current second
373 /// of the specified time.
375 /// <param name="time">The
376 /// <see cref="T:System.DateTime"/> that specifies the
379 /// <returns>An integer that gives the milliseconds in the seconds
380 /// of the specified time, starting with 0.</returns>
381 /// <exception cref="T:System.ArgumentOutOfRangeException">
382 /// The exception is thrown if the
383 /// <see cref="T:System.DateTime"/> parameter is outside all
386 public override double GetMilliseconds(DateTime time) {
387 M_CheckDateTime(time);
388 return base.GetMilliseconds(time);
392 /// Overridden. Gives the minute of the specified time.
394 /// <param name="time">The
395 /// <see cref="T:System.DateTime"/> that specifies the
398 /// <returns>An integer that gives the minute of the specified time,
399 /// starting with 0.</returns>
400 /// <exception cref="T:System.ArgumentOutOfRangeException">
401 /// The exception is thrown if the
402 /// <see cref="T:System.DateTime"/> parameter is outside all
405 public override int GetMinute(DateTime time) {
406 M_CheckDateTime(time);
407 return base.GetMinute(time);
411 /// Overridden. Gives the second of the specified time.
413 /// <param name="time">The
414 /// <see cref="T:System.DateTime"/> that specifies the
417 /// <returns>An integer that gives the second of the specified time,
418 /// starting with 0.</returns>
419 /// <exception cref="T:System.ArgumentOutOfRangeException">
420 /// The exception is thrown if the
421 /// <see cref="T:System.DateTime"/> parameter is outside all
424 public override int GetSecond(DateTime time) {
425 M_CheckDateTime(time);
426 return base.GetMinute(time);
431 /// Overrideden. Adds months to a given date.
433 /// <param name="time">The
434 /// <see cref="T:System.DateTime"/> to which to add
437 /// <param name="months">The number of months to add.</param>
438 /// <returns>A new <see cref="T:System.DateTime"/> value, that
439 /// results from adding <paramref name="months"/> to the specified
440 /// DateTime.</returns>
441 /// <exception cref="T:System.ArgumentOutOfRangeException">
442 /// The exception is thrown if
443 /// <see cref="T:System.DateTime"/> return value is outside all
446 public override DateTime AddMonths(DateTime time, int months) {
447 DateTime t = CCGregorianCalendar.AddMonths(time, months);
453 /// Overridden. Adds years to a given date.
455 /// <param name="time">The
456 /// <see cref="T:System.DateTime"/> to which to add
459 /// <param name="years">The number of years to add.</param>
460 /// <returns>A new <see cref="T:System.DateTime"/> value, that
461 /// results from adding <paramref name="years"/> to the specified
462 /// DateTime.</returns>
463 /// <exception cref="T:System.ArgumentOutOfRangeException">
464 /// The exception is thrown if
465 /// <see cref="T:System.DateTime"/> return value is outside all
468 public override DateTime AddYears(DateTime time, int years) {
469 DateTime t = CCGregorianCalendar.AddYears(time, years);
475 /// Overriden. Gets the day of the month from
476 /// <paramref name="time"/>.
478 /// <param name="time">The
479 /// <see cref="T:System.DateTime"/> that specifies a
482 /// <returns>An integer giving the day of months, starting with 1.
484 /// <exception cref="T:System.ArgumentOutOfRangeException">
485 /// The exception is thrown if the
486 /// <see cref="T:System.DateTime"/> parameter is outside all
489 public override int GetDayOfMonth(DateTime time) {
490 M_CheckDateTime(time);
491 return CCGregorianCalendar.GetDayOfMonth(time);
495 /// Overriden. Gets the day of the week from the specified date.
497 /// <param name="time">The
498 /// <see cref="T:System.DateTime"/> that specifies a
501 /// <returns>An integer giving the day of months, starting with 1.
503 /// <exception cref="T:System.ArgumentOutOfRangeException">
504 /// The exception is thrown if the
505 /// <see cref="T:System.DateTime"/> parameter is outside all
508 public override DayOfWeek GetDayOfWeek(DateTime time) {
509 M_CheckDateTime(time);
510 int rd = CCFixed.FromDateTime(time);
511 return (DayOfWeek)CCFixed.day_of_week(rd);
515 /// Overridden. Gives the number of the day in the year.
517 /// <param name="time">The
518 /// <see cref="T:System.DateTime"/> that specifies a
521 /// <returns>An integer representing the day of the year,
522 /// starting with 1.</returns>
523 /// <exception cref="T:System.ArgumentOutOfRangeException">
524 /// The exception is thrown if the
525 /// <see cref="T:System.DateTime"/> parameter is outside all
528 public override int GetDayOfYear(DateTime time) {
529 M_CheckDateTime(time);
530 return CCGregorianCalendar.GetDayOfYear(time);
534 /// Overridden. Gives the number of days in the specified month
535 /// of the given year and era.
537 /// <param name="year">An integer that gives the year.
539 /// <param name="month">An integer that gives the month, starting
541 /// <param name="era">An integer that gives the era of the specified
543 /// <returns>An integer that gives the number of days of the
544 /// specified month.</returns>
545 /// <exception cref="T:System.ArgumentOutOfRangeException">
546 /// The exception is thrown, if <paramref name="month"/>,
547 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
548 /// the allowed range.
550 public override int GetDaysInMonth(int year, int month, int era) {
551 int gregorianYear = M_CheckYMEG(year, month, ref era);
552 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
556 /// Overridden. Gives the number of days of the specified
557 /// year of the given era.
559 /// <param name="year">An integer that specifies the year.
561 /// <param name="era">An ineger that specifies the era.
563 /// <returns>An integer that gives the number of days of the
564 /// specified year.</returns>
565 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
566 /// The exception is thrown, if
567 /// <paramref name="year"/> or <paramref name="era"/> are outside the
570 public override int GetDaysInYear(int year, int era) {
571 int gregorianYear = M_CheckYEG(year, ref era);
572 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
577 /// Overridden. Gives the era of the specified date.
579 /// <param name="time">The
580 /// <see cref="T:System.DateTime"/> that specifies a
583 /// <returns>An integer representing the era of the calendar.
585 /// <exception cref="T:System.ArgumentOutOfRangeException">
586 /// The exception is thrown if the
587 /// <see cref="T:System.DateTime"/> parameter is outside all
590 public override int GetEra(DateTime time) {
591 // M_CheckDateTime not needed, because EraYear does the
593 int rd = CCFixed.FromDateTime(time);
595 M_EraHandler.EraYear(out era, rd);
600 /// Overridden. Gives the number of the month of the specified
603 /// <param name="time">The
604 /// <see cref="T:System.DateTime"/> that specifies a
607 /// <returns>An integer representing the month,
608 /// starting with 1.</returns>
609 /// <exception cref="T:System.ArgumentOutOfRangeException">
610 /// The exception is thrown if the
611 /// <see cref="T:System.DateTime"/> parameter is outside all
614 public override int GetMonth(DateTime time) {
615 M_CheckDateTime(time);
616 return CCGregorianCalendar.GetMonth(time);
620 /// Overridden. Gives the number of months in the specified year
623 /// <param name="year">An integer that specifies the year.
625 /// <param name="era">An integer that specifies the era.
627 /// <returns>An integer that gives the number of the months in the
628 /// specified year.</returns>
629 /// <exception cref="T:System.ArgumentOutOfRangeException">
630 /// The exception is thrown, if the year or the era are not valid.
632 public override int GetMonthsInYear(int year, int era) {
633 M_CheckYEG(year, ref era);
638 /// Overridden. Gives the number of the year of the specified
641 /// <param name="time">The
642 /// <see cref="T:System.DateTime"/> that specifies a
645 /// <returns>An integer representing the year,
646 /// starting with 1.</returns>
647 /// <exception cref="T:System.ArgumentOutOfRangeException">
648 /// The exception is thrown if the
649 /// <see cref="T:System.DateTime"/> parameter is outside all
652 public override int GetYear(DateTime time) {
653 // M_CheckDateTime not needed, because EraYeat does the
655 int rd = CCFixed.FromDateTime(time);
657 return M_EraHandler.EraYear(out era, rd);
661 /// Overridden. Tells whether the given day
664 /// <param name="year">An integer that specifies the year in the
667 /// <param name="month">An integer that specifies the month.
669 /// <param name="day">An integer that specifies the day.
671 /// <param name="era">An integer that specifies the era.
673 /// <returns>A boolean that tells whether the given day is a leap
676 /// <exception cref="T:System.ArgumentOutOfRangeException">
677 /// The exception is thrown, if the year, month, day, or era is not
680 public override bool IsLeapDay(int year, int month, int day, int era)
682 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
683 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
687 /// Overridden. Tells whether the given month
690 /// <param name="year">An integer that specifies the year in the
693 /// <param name="month">An integer that specifies the month.
695 /// <param name="era">An integer that specifies the era.
697 /// <returns>A boolean that tells whether the given month is a leap
700 /// <exception cref="T:System.ArgumentOutOfRangeException">
701 /// The exception is thrown, if the year, month, or era is not
704 public override bool IsLeapMonth(int year, int month, int era) {
705 M_CheckYMEG(year, month, ref era);
710 /// Overridden. Tells whether the given year
713 /// <param name="year">An integer that specifies the year in the
716 /// <param name="era">An integer that specifies the era.
718 /// <returns>A boolean that tells whether the given year is a leap
721 /// <exception cref="T:System.ArgumentOutOfRangeException">
722 /// The exception is thrown, if the year or era is not
725 public override bool IsLeapYear(int year, int era) {
726 int gregorianYear = M_CheckYEG(year, ref era);
727 return CCGregorianCalendar.is_leap_year(gregorianYear);
731 /// Overridden. Creates the
732 /// <see cref="T:System.DateTime"/> from the parameters.
734 /// <param name="year">An integer that gives the year in the
735 /// <paramref name="era"/>.
737 /// <param name="month">An integer that specifies the month.
739 /// <param name="day">An integer that specifies the day.
741 /// <param name="hour">An integer that specifies the hour.
743 /// <param name="minute">An integer that specifies the minute.
745 /// <param name="second">An integer that gives the second.
747 /// <param name="milliseconds">An integer that gives the
750 /// <param name="era">An integer that specifies the era.
753 /// <see cref="T:system.DateTime"/> representig the date and time.
755 /// <exception cref="T:System.ArgumentOutOfRangeException">
756 /// The exception is thrown, if at least one of the parameters
759 public override DateTime ToDateTime(int year, int month, int day,
760 int hour, int minute, int second, int milliseconds,
763 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
764 M_CheckHMSM(hour, minute, second, milliseconds);
765 return CCGregorianCalendar.ToDateTime(
766 gregorianYear, month, day,
767 hour, minute, second, milliseconds);
771 /// This functions returns simply the year for the Taiwan calendar.
773 /// <param name="year">An integer that gives the year.
775 /// <returns>The same argument as the year.
777 /// <exception cref="T:System.ArgumentOutOfRangeException">
778 /// The exception is thrown if the year is negative or the resulting
781 public override int ToFourDigitYear(int year) {
783 throw new ArgumentOutOfRangeException(
784 "year", "Non-negative number required.");
785 int era = CurrentEra;
786 M_CheckYE(year, ref era);
790 public override CalendarAlgorithmType AlgorithmType {
792 return CalendarAlgorithmType.SolarCalendar;
796 static DateTime TaiwanMin = new DateTime (1912, 1, 1, 0, 0, 0);
797 static DateTime TaiwanMax = new DateTime (9999, 12, 31, 11, 59, 59);
799 public override DateTime MinSupportedDateTime {
805 public override DateTime MaxSupportedDateTime {
812 } // class TaiwanCalendar
814 } // namespace System.Globalization