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;
92 M_ArgumentInRange ("value", value, 100, M_MaxYear);
94 twoDigitYearMax = value;
99 /// A protected member checking a
100 /// <see cref="T:System.DateTime"/> value.
102 /// <param name="time">The
103 /// <see cref="T:System.DateTime"/>
106 /// <exception cref="T:System.ArgumentOutOfRangeException">
107 /// The exception is thrown if the
108 /// <see cref="T:System.DateTime"/> parameter is outside all
111 internal void M_CheckDateTime(DateTime time) {
112 M_EraHandler.CheckDateTime(time);
116 /// A protected method checking the era number.
118 /// <param name="era">The era number as reference. It is set
119 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
120 /// <exception name="T:System.ArgumentException">
121 /// The exception is thrown if the era is not supported by the class.
123 internal void M_CheckEra(ref int era) {
124 if (era == CurrentEra)
126 if (!M_EraHandler.ValidEra(era))
127 throw new ArgumentException("Era value was not valid.");
131 /// A protected method checking calendar year and the era number.
133 /// <param name="year">An integer representing the calendar year.
135 /// <param name="era">The era number as reference.</param>
136 /// <exception name="T:System.ArgumentException">
137 /// The exception is thrown if the era is not supported by the class.
139 /// <exception cref="T:System.ArgumentOutOfRangeException">
140 /// The exception is thrown if the calendar year is outside of
141 /// the supported range.
143 internal int M_CheckYEG(int year, ref int era) {
145 return M_EraHandler.GregorianYear(year, era);
149 /// Checks whether the year is the era is valid, if era = CurrentEra
150 /// the right value is set.
152 /// <param name="year">The year to check.</param>
153 /// <param name="era">The era to check.</Param>
154 /// <exception cref="T:ArgumentOutOfRangeException">
155 /// The exception will be thrown, if the year is not valid.
157 internal override void M_CheckYE(int year, ref int era) {
158 M_CheckYEG(year, ref era);
162 /// A protected method checking the calendar year, month, and
165 /// <param name="year">An integer representing the calendar year.
167 /// <param name="month">An integer giving the calendar month.
169 /// <param name="era">The era number as reference.</param>
170 /// <exception name="T:System.ArgumentException">
171 /// The exception is thrown if the era is not supported by the class.
173 /// <exception cref="T:System.ArgumentOutOfRangeException">
174 /// The exception is thrown if the calendar year or month is
175 /// outside of the supported range.
177 internal int M_CheckYMEG(int year, int month, ref int era) {
178 int gregorianYear = M_CheckYEG(year, ref era);
179 if (month < 1 || month > 12)
180 throw new ArgumentOutOfRangeException("month",
181 "Month must be between one and twelve.");
182 return gregorianYear;
186 /// A protected method checking the calendar day, month, and year
187 /// and the era number.
189 /// <param name="year">An integer representing the calendar year.
191 /// <param name="month">An integer giving the calendar month.
193 /// <param name="day">An integer giving the calendar day.
195 /// <param name="era">The era number as reference.</param>
196 /// <exception name="T:System.ArgumentException">
197 /// The exception is thrown if the era is not supported by the class.
199 /// <exception cref="T:System.ArgumentOutOfRangeException">
200 /// The exception is thrown if the calendar year, month, or day is
201 /// outside of the supported range.
203 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
205 int gregorianYear = M_CheckYMEG(year, month, ref era);
206 M_ArgumentInRange("day", day, 1,
207 GetDaysInMonth(year, month, era));
208 return gregorianYear;
213 // Ifdefed out because this is not on the .NET Framework
216 /// Overridden. Adds days to a given date.
218 /// <param name="time">The
219 /// <see cref="T:System.DateTime"/> to which to add
222 /// <param name="days">The number of days to add.</param>
223 /// <returns>A new <see cref="T:System.DateTime"/> value, that
224 /// results from adding <paramref name="days"/> to the specified
225 /// DateTime.</returns>
226 /// <exception cref="T:System.ArgumentOutOfRangeException">
227 /// The exception is thrown if the
228 /// <see cref="T:System.DateTime"/> return value is outside all
231 public override DateTime AddDays(DateTime time, int days) {
232 DateTime t = base.AddDays(time, days);
238 /// Overridden. Adds hours to a given date.
240 /// <param name="time">The
241 /// <see cref="T:System.DateTime"/> to which to add
244 /// <param name="hours">The number of hours to add.</param>
245 /// <returns>A new <see cref="T:System.DateTime"/> value, that
246 /// results from adding <paramref name="hours"/> to the specified
247 /// DateTime.</returns>
248 /// <exception cref="T:System.ArgumentOutOfRangeException">
249 /// The exception is thrown if the
250 /// <see cref="T:System.DateTime"/> return value is outside all
253 public override DateTime AddHours(DateTime time, int hours) {
254 DateTime t = base.AddHours(time, hours);
260 /// Overridden. Adds milliseconds to a given date.
262 /// <param name="time">The
263 /// <see cref="T:System.DateTime"/> to which to add
266 /// <param name="milliseconds">The number of milliseconds given as
267 /// double to add. Keep in mind the 100 nanosecond resolution of
268 /// <see cref="T:System.DateTime"/>.
270 /// <returns>A new <see cref="T:System.DateTime"/> value, that
271 /// results from adding <paramref name="milliseconds"/> 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 AddMilliseconds(DateTime time,
281 DateTime t = base.AddMilliseconds(time, milliseconds);
287 /// Overridden. Adds minutes to a given date.
289 /// <param name="time">The
290 /// <see cref="T:System.DateTime"/> to which to add
293 /// <param name="minutes">The number of minutes to add.</param>
294 /// <returns>A new <see cref="T:System.DateTime"/> value, that
295 /// results from adding <paramref name="minutes"/> to the specified
296 /// DateTime.</returns>
297 /// <exception cref="T:System.ArgumentOutOfRangeException">
298 /// The exception is thrown if the
299 /// <see cref="T:System.DateTime"/> return value is outside all
302 public override DateTime AddMinutes(DateTime time, int minutes) {
303 DateTime t = base.AddMinutes(time, minutes);
309 /// Overridden. Adds seconds to a given date.
311 /// <param name="time">The
312 /// <see cref="T:System.DateTime"/> to which to add
315 /// <param name="seconds">The number of seconds to add.</param>
316 /// <returns>A new <see cref="T:System.DateTime"/> value, that
317 /// results from adding <paramref name="seconds"/> to the specified
318 /// DateTime.</returns>
319 /// <exception cref="T:System.ArgumentOutOfRangeException">
320 /// The exception is thrown if the
321 /// <see cref="T:System.DateTime"/> return value is outside all
324 public override DateTime AddSeconds(DateTime time, int seconds) {
325 DateTime t = base.AddSeconds(time, seconds);
332 /// Overridden. Adds weeks to a given date.
334 /// <param name="time">The
335 /// <see cref="T:System.DateTime"/> to which to add
338 /// <param name="weeks">The number of weeks to add.</param>
339 /// <returns>A new <see cref="T:System.DateTime"/> value, that
340 /// results from adding <paramref name="weeks"/> to the specified
341 /// DateTime.</returns>
342 /// <exception cref="T:System.ArgumentOutOfRangeException">
343 /// The exception is thrown if the
344 /// <see cref="T:System.DateTime"/> return value is outside all
347 public override DateTime AddWeeks(DateTime time, int weeks) {
348 DateTime t = base.AddWeeks(time, weeks);
354 /// Overridden. Gives the hour of the specified time.
356 /// <param name="time">The
357 /// <see cref="T:System.DateTime"/> that specifies the
360 /// <returns>An integer that gives the hour of the specified time,
361 /// starting with 0.</returns>
362 /// <exception cref="T:System.ArgumentOutOfRangeException">
363 /// The exception is thrown if the
364 /// <see cref="T:System.DateTime"/> parameter is outside all
367 public override int GetHour(DateTime time) {
368 M_CheckDateTime(time);
369 return base.GetHour(time);
373 /// Overridden. Gives the milliseconds in the current second
374 /// of the specified time.
376 /// <param name="time">The
377 /// <see cref="T:System.DateTime"/> that specifies the
380 /// <returns>An integer that gives the milliseconds in the seconds
381 /// of the specified time, starting with 0.</returns>
382 /// <exception cref="T:System.ArgumentOutOfRangeException">
383 /// The exception is thrown if the
384 /// <see cref="T:System.DateTime"/> parameter is outside all
387 public override double GetMilliseconds(DateTime time) {
388 M_CheckDateTime(time);
389 return base.GetMilliseconds(time);
393 /// Overridden. Gives the minute of the specified time.
395 /// <param name="time">The
396 /// <see cref="T:System.DateTime"/> that specifies the
399 /// <returns>An integer that gives the minute of the specified time,
400 /// starting with 0.</returns>
401 /// <exception cref="T:System.ArgumentOutOfRangeException">
402 /// The exception is thrown if the
403 /// <see cref="T:System.DateTime"/> parameter is outside all
406 public override int GetMinute(DateTime time) {
407 M_CheckDateTime(time);
408 return base.GetMinute(time);
412 /// Overridden. Gives the second of the specified time.
414 /// <param name="time">The
415 /// <see cref="T:System.DateTime"/> that specifies the
418 /// <returns>An integer that gives the second of the specified time,
419 /// starting with 0.</returns>
420 /// <exception cref="T:System.ArgumentOutOfRangeException">
421 /// The exception is thrown if the
422 /// <see cref="T:System.DateTime"/> parameter is outside all
425 public override int GetSecond(DateTime time) {
426 M_CheckDateTime(time);
427 return base.GetMinute(time);
432 /// Overrideden. Adds months to a given date.
434 /// <param name="time">The
435 /// <see cref="T:System.DateTime"/> to which to add
438 /// <param name="months">The number of months to add.</param>
439 /// <returns>A new <see cref="T:System.DateTime"/> value, that
440 /// results from adding <paramref name="months"/> to the specified
441 /// DateTime.</returns>
442 /// <exception cref="T:System.ArgumentOutOfRangeException">
443 /// The exception is thrown if
444 /// <see cref="T:System.DateTime"/> return value is outside all
447 public override DateTime AddMonths(DateTime time, int months) {
448 DateTime t = CCGregorianCalendar.AddMonths(time, months);
454 /// Overridden. Adds years to a given date.
456 /// <param name="time">The
457 /// <see cref="T:System.DateTime"/> to which to add
460 /// <param name="years">The number of years to add.</param>
461 /// <returns>A new <see cref="T:System.DateTime"/> value, that
462 /// results from adding <paramref name="years"/> to the specified
463 /// DateTime.</returns>
464 /// <exception cref="T:System.ArgumentOutOfRangeException">
465 /// The exception is thrown if
466 /// <see cref="T:System.DateTime"/> return value is outside all
469 public override DateTime AddYears(DateTime time, int years) {
470 DateTime t = CCGregorianCalendar.AddYears(time, years);
476 /// Overriden. Gets the day of the month from
477 /// <paramref name="time"/>.
479 /// <param name="time">The
480 /// <see cref="T:System.DateTime"/> that specifies a
483 /// <returns>An integer giving the day of months, starting with 1.
485 /// <exception cref="T:System.ArgumentOutOfRangeException">
486 /// The exception is thrown if the
487 /// <see cref="T:System.DateTime"/> parameter is outside all
490 public override int GetDayOfMonth(DateTime time) {
491 M_CheckDateTime(time);
492 return CCGregorianCalendar.GetDayOfMonth(time);
496 /// Overriden. Gets the day of the week from the specified date.
498 /// <param name="time">The
499 /// <see cref="T:System.DateTime"/> that specifies a
502 /// <returns>An integer giving the day of months, starting with 1.
504 /// <exception cref="T:System.ArgumentOutOfRangeException">
505 /// The exception is thrown if the
506 /// <see cref="T:System.DateTime"/> parameter is outside all
509 public override DayOfWeek GetDayOfWeek(DateTime time) {
510 M_CheckDateTime(time);
511 int rd = CCFixed.FromDateTime(time);
512 return (DayOfWeek)CCFixed.day_of_week(rd);
516 /// Overridden. Gives the number of the day in the year.
518 /// <param name="time">The
519 /// <see cref="T:System.DateTime"/> that specifies a
522 /// <returns>An integer representing the day of the year,
523 /// starting with 1.</returns>
524 /// <exception cref="T:System.ArgumentOutOfRangeException">
525 /// The exception is thrown if the
526 /// <see cref="T:System.DateTime"/> parameter is outside all
529 public override int GetDayOfYear(DateTime time) {
530 M_CheckDateTime(time);
531 return CCGregorianCalendar.GetDayOfYear(time);
535 /// Overridden. Gives the number of days in the specified month
536 /// of the given year and era.
538 /// <param name="year">An integer that gives the year.
540 /// <param name="month">An integer that gives the month, starting
542 /// <param name="era">An integer that gives the era of the specified
544 /// <returns>An integer that gives the number of days of the
545 /// specified month.</returns>
546 /// <exception cref="T:System.ArgumentOutOfRangeException">
547 /// The exception is thrown, if <paramref name="month"/>,
548 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
549 /// the allowed range.
551 public override int GetDaysInMonth(int year, int month, int era) {
552 int gregorianYear = M_CheckYMEG(year, month, ref era);
553 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
557 /// Overridden. Gives the number of days of the specified
558 /// year of the given era.
560 /// <param name="year">An integer that specifies the year.
562 /// <param name="era">An ineger that specifies the era.
564 /// <returns>An integer that gives the number of days of the
565 /// specified year.</returns>
566 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
567 /// The exception is thrown, if
568 /// <paramref name="year"/> or <paramref name="era"/> are outside the
571 public override int GetDaysInYear(int year, int era) {
572 int gregorianYear = M_CheckYEG(year, ref era);
573 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
578 /// Overridden. Gives the era of the specified date.
580 /// <param name="time">The
581 /// <see cref="T:System.DateTime"/> that specifies a
584 /// <returns>An integer representing the era of the calendar.
586 /// <exception cref="T:System.ArgumentOutOfRangeException">
587 /// The exception is thrown if the
588 /// <see cref="T:System.DateTime"/> parameter is outside all
591 public override int GetEra(DateTime time) {
592 // M_CheckDateTime not needed, because EraYear does the
594 int rd = CCFixed.FromDateTime(time);
596 M_EraHandler.EraYear(out era, rd);
601 /// Overridden. Gives the number of the month of the specified
604 /// <param name="time">The
605 /// <see cref="T:System.DateTime"/> that specifies a
608 /// <returns>An integer representing the month,
609 /// starting with 1.</returns>
610 /// <exception cref="T:System.ArgumentOutOfRangeException">
611 /// The exception is thrown if the
612 /// <see cref="T:System.DateTime"/> parameter is outside all
615 public override int GetMonth(DateTime time) {
616 M_CheckDateTime(time);
617 return CCGregorianCalendar.GetMonth(time);
621 /// Overridden. Gives the number of months in the specified year
624 /// <param name="year">An integer that specifies the year.
626 /// <param name="era">An integer that specifies the era.
628 /// <returns>An integer that gives the number of the months in the
629 /// specified year.</returns>
630 /// <exception cref="T:System.ArgumentOutOfRangeException">
631 /// The exception is thrown, if the year or the era are not valid.
633 public override int GetMonthsInYear(int year, int era) {
634 M_CheckYEG(year, ref era);
639 /// Overridden. Gives the number of the year of the specified
642 /// <param name="time">The
643 /// <see cref="T:System.DateTime"/> that specifies a
646 /// <returns>An integer representing the year,
647 /// starting with 1.</returns>
648 /// <exception cref="T:System.ArgumentOutOfRangeException">
649 /// The exception is thrown if the
650 /// <see cref="T:System.DateTime"/> parameter is outside all
653 public override int GetYear(DateTime time) {
654 // M_CheckDateTime not needed, because EraYeat does the
656 int rd = CCFixed.FromDateTime(time);
658 return M_EraHandler.EraYear(out era, rd);
662 /// Overridden. Tells whether the given day
665 /// <param name="year">An integer that specifies the year in the
668 /// <param name="month">An integer that specifies the month.
670 /// <param name="day">An integer that specifies the day.
672 /// <param name="era">An integer that specifies the era.
674 /// <returns>A boolean that tells whether the given day is a leap
677 /// <exception cref="T:System.ArgumentOutOfRangeException">
678 /// The exception is thrown, if the year, month, day, or era is not
681 public override bool IsLeapDay(int year, int month, int day, int era)
683 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
684 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
688 /// Overridden. Tells whether the given month
691 /// <param name="year">An integer that specifies the year in the
694 /// <param name="month">An integer that specifies the month.
696 /// <param name="era">An integer that specifies the era.
698 /// <returns>A boolean that tells whether the given month is a leap
701 /// <exception cref="T:System.ArgumentOutOfRangeException">
702 /// The exception is thrown, if the year, month, or era is not
705 public override bool IsLeapMonth(int year, int month, int era) {
706 M_CheckYMEG(year, month, ref era);
711 /// Overridden. Tells whether the given year
714 /// <param name="year">An integer that specifies the year in the
717 /// <param name="era">An integer that specifies the era.
719 /// <returns>A boolean that tells whether the given year is a leap
722 /// <exception cref="T:System.ArgumentOutOfRangeException">
723 /// The exception is thrown, if the year or era is not
726 public override bool IsLeapYear(int year, int era) {
727 int gregorianYear = M_CheckYEG(year, ref era);
728 return CCGregorianCalendar.is_leap_year(gregorianYear);
732 /// Overridden. Creates the
733 /// <see cref="T:System.DateTime"/> from the parameters.
735 /// <param name="year">An integer that gives the year in the
736 /// <paramref name="era"/>.
738 /// <param name="month">An integer that specifies the month.
740 /// <param name="day">An integer that specifies the day.
742 /// <param name="hour">An integer that specifies the hour.
744 /// <param name="minute">An integer that specifies the minute.
746 /// <param name="second">An integer that gives the second.
748 /// <param name="milliseconds">An integer that gives the
751 /// <param name="era">An integer that specifies the era.
754 /// <see cref="T:system.DateTime"/> representig the date and time.
756 /// <exception cref="T:System.ArgumentOutOfRangeException">
757 /// The exception is thrown, if at least one of the parameters
760 public override DateTime ToDateTime(int year, int month, int day,
761 int hour, int minute, int second, int milliseconds,
764 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
765 M_CheckHMSM(hour, minute, second, milliseconds);
766 return CCGregorianCalendar.ToDateTime(
767 gregorianYear, month, day,
768 hour, minute, second, milliseconds);
772 /// This functions returns simply the year for the Taiwan calendar.
774 /// <param name="year">An integer that gives the year.
776 /// <returns>The same argument as the year.
778 /// <exception cref="T:System.ArgumentOutOfRangeException">
779 /// The exception is thrown if the year is negative or the resulting
782 public override int ToFourDigitYear(int year) {
784 throw new ArgumentOutOfRangeException(
785 "year", "Non-negative number required.");
786 int era = CurrentEra;
787 M_CheckYE(year, ref era);
791 public override CalendarAlgorithmType AlgorithmType {
793 return CalendarAlgorithmType.SolarCalendar;
797 static DateTime TaiwanMin = new DateTime (1912, 1, 1, 0, 0, 0);
798 static DateTime TaiwanMax = new DateTime (9999, 12, 31, 11, 59, 59);
800 public override DateTime MinSupportedDateTime {
806 public override DateTime MaxSupportedDateTime {
813 } // class TaiwanCalendar
815 } // namespace System.Globalization