2004-10-14 Miguel de Icaza <miguel@ximian.com>
[mono.git] / mcs / class / corlib / System.Globalization / JapaneseCalendar.cs
1 // JapaneseCalendar.cs
2 //
3 // (C) Ulrich Kunitz 2002
4 //
5
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.
27 //
28
29 namespace System.Globalization {
30
31 using System;
32
33 /// <summary>
34 /// This is the Japanese calendar. It differs from the Gregorian calendar
35 /// only in the years.
36 /// </summary>
37 /// <remarks>
38 /// <para>The Japanese calendar support four eras.</para>
39 /// <list type="table">
40 /// <listheader>
41 /// <term>era number</term>
42 /// <term>Gregorian start date</term>
43 /// <term>Gregorian end date</term>
44 /// </listheader>
45 /// <item>
46 /// <term>1</term>
47 /// <term>September 8, 1868</term>
48 /// <term>July 29, 1912</term>
49 /// </item>
50 /// <item>
51 /// <term>2</term>
52 /// <term>July 30, 1912</term>
53 /// <term>December 24, 1926</term>
54 /// </item>
55 /// <item>
56 /// <term>3</term>
57 /// <term>December 25, 1926</term>
58 /// <term>January 7, 1989</term>
59 /// </item>
60 /// <item>
61 /// <term>4</term>
62 /// <term>January 8, 1989</term>
63 /// <term>present</term>
64 /// </item>
65 /// </list>
66 /// <para>The implementation uses the
67 /// <see cref="N:CalendricalCalculations"/> namespace.
68 /// </para>
69 /// </remarks>
70 [Serializable]
71 [MonoTODO ("Fix serialization compatibility with MS.NET")]
72 public class JapaneseCalendar : Calendar {
73         /// <summary>
74         /// Static protected field storing the
75         /// <see cref="T:CalendricalCalculations.GregorianEraHandler"/>.
76         /// </summary>
77         internal static readonly CCGregorianEraHandler M_EraHandler;
78
79         /// <summary>
80         /// Static constructor, who creates and initializes
81         /// <see cref="F:M_EraHandler"/>.
82         /// </summary>
83         static JapaneseCalendar() {
84                 M_EraHandler = new CCGregorianEraHandler();
85                 M_EraHandler.appendEra(1,
86                         CCGregorianCalendar.fixed_from_dmy(8, 9, 1868),
87                         CCGregorianCalendar.fixed_from_dmy(29, 7, 1912));
88                 M_EraHandler.appendEra(2,
89                         CCGregorianCalendar.fixed_from_dmy(30, 7, 1912),
90                         CCGregorianCalendar.fixed_from_dmy(24, 12, 1926));
91                 M_EraHandler.appendEra(3,
92                         CCGregorianCalendar.fixed_from_dmy(25, 12, 1926),
93                         CCGregorianCalendar.fixed_from_dmy(7, 1, 1989));
94                 M_EraHandler.appendEra(4,
95                         CCGregorianCalendar.fixed_from_dmy(8, 1, 1989));
96         }
97
98         /// <summary>
99         /// Default constructor.
100         /// </summary>
101         public JapaneseCalendar() {
102                 M_AbbrEraNames = new string[] { "M", "T", "S", "H" };
103                 M_EraNames = new string[] { "Meiji", "Taisho", "Showa",
104                         "Heisei" };
105         }
106                 
107
108         /// <value>Overridden. Gives the eras supported by the
109         /// calendar as an array of integers.
110         /// </value>
111         public override int[] Eras {
112                 get {
113                         return (int[])M_EraHandler.Eras.Clone();
114                 }
115         }
116
117         int twoDigitYearMax = 99;
118         
119         public override int TwoDigitYearMax 
120         {
121                 get {
122                         return twoDigitYearMax;
123                 }
124                 set {
125                         M_ArgumentInRange ("value", value, 100, M_MaxYear);
126
127                         twoDigitYearMax = value;
128                 }
129         }
130         
131         /// <summary>
132         /// A protected member checking a
133         /// <see cref="T:System.DateTime"/> value.
134         /// </summary>
135         /// <param name="time">The
136         /// <see cref="T:System.DateTime"/>
137         /// to check.
138         /// </param>
139         /// <exception cref="T:System.ArgumentOutOfRangeException">
140         /// The exception is thrown if the
141         /// <see cref="T:System.DateTime"/> parameter is outside all
142         /// supported eras.
143         /// </exception>
144         internal void M_CheckDateTime(DateTime time) {
145                 M_EraHandler.CheckDateTime(time);
146         }
147
148         /// <summary>
149         /// A protected method checking the era number.
150         /// </summary>
151         /// <param name="era">The era number as reference. It is set
152         /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
153         /// <exception name="T:System.ArgumentException">
154         /// The exception is thrown if the era is not supported by the class.
155         /// </exception>
156         internal void M_CheckEra(ref int era) {
157                 if (era == CurrentEra)
158                         era = 4;
159                 if (!M_EraHandler.ValidEra(era))
160                         throw new ArgumentException("Era value was not valid.");
161         }
162
163         /// <summary>
164         /// A protected method checking calendar year and the era number.
165         /// </summary>
166         /// <param name="year">An integer representing the calendar year.
167         /// </param>
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.
171         /// </exception>
172         /// <exception cref="T:System.ArgumentOutOfRangeException">
173         /// The exception is thrown if the calendar year is outside of
174         /// the supported range.
175         /// </exception>
176         internal int M_CheckYEG(int year, ref int era) {
177                 M_CheckEra(ref era);
178                 return M_EraHandler.GregorianYear(year, era);
179         }
180
181         /// <summary>
182         /// Checks whether the year is the era is valid, if era = CurrentEra
183         /// the right value is set.
184         /// </summary>
185         /// <param name="year">The year to check.</param>
186         /// <param name="era">The era to check.</Param>
187         /// <exception cref="T:ArgumentOutOfRangeException">
188         /// The exception will be thrown, if the year is not valid.
189         /// </exception>
190         internal override void M_CheckYE(int year, ref int era) {
191                 M_CheckYEG(year, ref era);
192         }
193
194         /// <summary>
195         /// A protected method checking the calendar year, month, and
196         /// era number.
197         /// </summary>
198         /// <param name="year">An integer representing the calendar year.
199         /// </param>
200         /// <param name="month">An integer giving the calendar month.
201         /// </param>
202         /// <param name="era">The era number as reference.</param>
203         /// <exception name="T:System.ArgumentException">
204         /// The exception is thrown if the era is not supported by the class.
205         /// </exception>
206         /// <exception cref="T:System.ArgumentOutOfRangeException">
207         /// The exception is thrown if the calendar year or month is
208         /// outside of the supported range.
209         /// </exception>
210         internal int M_CheckYMEG(int year, int month, ref int era) {
211                 int gregorianYear = M_CheckYEG(year, ref era);
212                 if (month < 1 || month > 12)
213                         throw new ArgumentOutOfRangeException("month",
214                                 "Month must be between one and twelve.");
215                 return gregorianYear;
216         }
217
218         /// <summary>
219         /// A protected method checking the calendar day, month, and year
220         /// and the era number.
221         /// </summary>
222         /// <param name="year">An integer representing the calendar year.
223         /// </param>
224         /// <param name="month">An integer giving the calendar month.
225         /// </param>
226         /// <param name="day">An integer giving the calendar day.
227         /// </param>
228         /// <param name="era">The era number as reference.</param>
229         /// <exception name="T:System.ArgumentException">
230         /// The exception is thrown if the era is not supported by the class.
231         /// </exception>
232         /// <exception cref="T:System.ArgumentOutOfRangeException">
233         /// The exception is thrown if the calendar year, month, or day is
234         /// outside of the supported range.
235         /// </exception>
236         internal int M_CheckYMDEG(int year, int month, int day, ref int era)
237         {
238                 int gregorianYear = M_CheckYMEG(year, month, ref era);
239                 M_ArgumentInRange("day", day, 1, GetDaysInMonth(year, month, era));
240                 return gregorianYear;
241         }
242
243 #if false
244
245         // Ifdefed out because this is not on the .NET Framewokr.
246         
247         /// <summary>
248         /// Overridden. Adds days to a given date.
249         /// </summary>
250         /// <param name="time">The
251         /// <see cref="T:System.DateTime"/> to which to add
252         /// days.
253         /// </param>
254         /// <param name="days">The number of days to add.</param>
255         /// <returns>A new <see cref="T:System.DateTime"/> value, that
256         /// results from adding <paramref name="days"/> to the specified
257         /// DateTime.</returns>
258         /// <exception cref="T:System.ArgumentOutOfRangeException">
259         /// The exception is thrown if the
260         /// <see cref="T:System.DateTime"/> return value is outside all
261         /// supported eras.
262         /// </exception>
263         public override DateTime AddDays(DateTime time, int days) {
264                 DateTime t = base.AddDays(time, days);
265                 M_CheckDateTime(t);
266                 return t;
267         }
268
269         /// <summary>
270         /// Overridden. Adds hours to a given date.
271         /// </summary>
272         /// <param name="time">The
273         /// <see cref="T:System.DateTime"/> to which to add
274         /// hours.
275         /// </param>
276         /// <param name="hours">The number of hours to add.</param>
277         /// <returns>A new <see cref="T:System.DateTime"/> value, that
278         /// results from adding <paramref name="hours"/> to the specified
279         /// DateTime.</returns>
280         /// <exception cref="T:System.ArgumentOutOfRangeException">
281         /// The exception is thrown if the
282         /// <see cref="T:System.DateTime"/> return value is outside all
283         /// supported eras.
284         /// </exception>
285         public override DateTime AddHours(DateTime time, int hours) {
286                 DateTime t = base.AddHours(time, hours);
287                 M_CheckDateTime(t);
288                 return t;
289         }
290
291         /// <summary>
292         /// Overridden. Adds milliseconds to a given date.
293         /// </summary>
294         /// <param name="time">The
295         /// <see cref="T:System.DateTime"/> to which to add
296         /// milliseconds.
297         /// </param>
298         /// <param name="milliseconds">The number of milliseconds given as
299         /// double to add. Keep in mind the 100 nanosecond resolution of 
300         /// <see cref="T:System.DateTime"/>.
301         /// </param>
302         /// <returns>A new <see cref="T:System.DateTime"/> value, that
303         /// results from adding <paramref name="milliseconds"/> to the specified
304         /// DateTime.</returns>
305         /// <exception cref="T:System.ArgumentOutOfRangeException">
306         /// The exception is thrown if the
307         /// <see cref="T:System.DateTime"/> return value is outside all
308         /// supported eras.
309         /// </exception>
310         public override DateTime AddMilliseconds(DateTime time,
311                 double milliseconds)
312         {
313                 DateTime t = base.AddMilliseconds(time, milliseconds);
314                 M_CheckDateTime(t);
315                 return t;
316         }
317
318         /// <summary>
319         /// Overridden. Adds minutes to a given date.
320         /// </summary>
321         /// <param name="time">The
322         /// <see cref="T:System.DateTime"/> to which to add
323         /// minutes.
324         /// </param>
325         /// <param name="minutes">The number of minutes to add.</param>
326         /// <returns>A new <see cref="T:System.DateTime"/> value, that
327         /// results from adding <paramref name="minutes"/> to the specified
328         /// DateTime.</returns>
329         /// <exception cref="T:System.ArgumentOutOfRangeException">
330         /// The exception is thrown if the
331         /// <see cref="T:System.DateTime"/> return value is outside all
332         /// supported eras.
333         /// </exception>
334         public override DateTime AddMinutes(DateTime time, int minutes) {
335                 DateTime t = base.AddMinutes(time, minutes);
336                 M_CheckDateTime(t);
337                 return t;
338         }
339
340         /// <summary>
341         /// Overridden. Adds seconds to a given date.
342         /// </summary>
343         /// <param name="time">The
344         /// <see cref="T:System.DateTime"/> to which to add
345         /// seconds.
346         /// </param>
347         /// <param name="seconds">The number of seconds to add.</param>
348         /// <returns>A new <see cref="T:System.DateTime"/> value, that
349         /// results from adding <paramref name="seconds"/> to the specified
350         /// DateTime.</returns>
351         /// <exception cref="T:System.ArgumentOutOfRangeException">
352         /// The exception is thrown if the
353         /// <see cref="T:System.DateTime"/> return value is outside all
354         /// supported eras.
355         /// </exception>
356         public override DateTime AddSeconds(DateTime time, int seconds) {
357                 DateTime t = base.AddSeconds(time, seconds);
358                 M_CheckDateTime(t);
359                 return t;
360         }
361
362
363         /// <summary>
364         /// Overridden. Adds weeks to a given date.
365         /// </summary>
366         /// <param name="time">The
367         /// <see cref="T:System.DateTime"/> to which to add
368         /// weeks.
369         /// </param>
370         /// <param name="weeks">The number of weeks to add.</param>
371         /// <returns>A new <see cref="T:System.DateTime"/> value, that
372         /// results from adding <paramref name="weeks"/> to the specified
373         /// DateTime.</returns>
374         /// <exception cref="T:System.ArgumentOutOfRangeException">
375         /// The exception is thrown if the
376         /// <see cref="T:System.DateTime"/> return value is outside all
377         /// supported eras.
378         /// </exception>
379         public override DateTime AddWeeks(DateTime time, int weeks) {
380                 DateTime t = base.AddWeeks(time, weeks);
381                 M_CheckDateTime(t);
382                 return t;
383         }
384
385         /// <summary>
386         /// Overridden. Gives the hour of the specified time.
387         /// </summary>
388         /// <param name="time">The
389         /// <see cref="T:System.DateTime"/> that specifies the
390         /// time.
391         /// </param>
392         /// <returns>An integer that gives the hour of the specified time,
393         /// starting with 0.</returns>
394         /// <exception cref="T:System.ArgumentOutOfRangeException">
395         /// The exception is thrown if the
396         /// <see cref="T:System.DateTime"/> parameter is outside all
397         /// supported eras.
398         /// </exception>
399         public override int GetHour(DateTime time) {
400                 M_CheckDateTime(time);
401                 return base.GetHour(time);
402         }
403
404         /// <summary>
405         /// Overridden. Gives the milliseconds in the current second
406         /// of the specified time.
407         /// </summary>
408         /// <param name="time">The
409         /// <see cref="T:System.DateTime"/> that specifies the
410         /// time.
411         /// </param>
412         /// <returns>An integer that gives the milliseconds in the seconds
413         /// of the specified time, starting with 0.</returns>
414         /// <exception cref="T:System.ArgumentOutOfRangeException">
415         /// The exception is thrown if the
416         /// <see cref="T:System.DateTime"/> parameter is outside all
417         /// supported eras.
418         /// </exception>
419         public override double GetMilliseconds(DateTime time) {
420                 M_CheckDateTime(time);
421                 return base.GetMilliseconds(time);
422         }
423
424         /// <summary>
425         /// Overridden. Gives the minute of the specified time.
426         /// </summary>
427         /// <param name="time">The
428         /// <see cref="T:System.DateTime"/> that specifies the
429         /// time.
430         /// </param>
431         /// <returns>An integer that gives the minute of the specified time,
432         /// starting with 0.</returns>
433         /// <exception cref="T:System.ArgumentOutOfRangeException">
434         /// The exception is thrown if the
435         /// <see cref="T:System.DateTime"/> parameter is outside all
436         /// supported eras.
437         /// </exception>
438         public override int GetMinute(DateTime time) {
439                 M_CheckDateTime(time);
440                 return base.GetMinute(time);
441         }
442
443         /// <summary>
444         /// Overridden. Gives the second of the specified time.
445         /// </summary>
446         /// <param name="time">The
447         /// <see cref="T:System.DateTime"/> that specifies the
448         /// time.
449         /// </param>
450         /// <returns>An integer that gives the second of the specified time,
451         /// starting with 0.</returns>
452         /// <exception cref="T:System.ArgumentOutOfRangeException">
453         /// The exception is thrown if the
454         /// <see cref="T:System.DateTime"/> parameter is outside all
455         /// supported eras.
456         /// </exception>
457         public override int GetSecond(DateTime time) {
458                 M_CheckDateTime(time);
459                 return base.GetMinute(time);
460         }
461 #endif
462         
463         /// <summary>
464         /// Overrideden. Adds months to a given date.
465         /// </summary>
466         /// <param name="time">The
467         /// <see cref="T:System.DateTime"/> to which to add
468         /// months.
469         /// </param>
470         /// <param name="months">The number of months to add.</param>
471         /// <returns>A new <see cref="T:System.DateTime"/> value, that
472         /// results from adding <paramref name="months"/> to the specified
473         /// DateTime.</returns>
474         /// <exception cref="T:System.ArgumentOutOfRangeException">
475         /// The exception is thrown if
476         /// <see cref="T:System.DateTime"/> return value is outside all
477         /// supported eras.
478         /// </exception>
479         public override DateTime AddMonths(DateTime time, int months) {
480                 DateTime t = CCGregorianCalendar.AddMonths(time, months);
481                 M_CheckDateTime(t);
482                 return t;
483         }
484
485         /// <summary>
486         /// Overridden. Adds years to a given date.
487         /// </summary>
488         /// <param name="time">The
489         /// <see cref="T:System.DateTime"/> to which to add
490         /// years.
491         /// </param>
492         /// <param name="years">The number of years to add.</param>
493         /// <returns>A new <see cref="T:System.DateTime"/> value, that
494         /// results from adding <paramref name="years"/> to the specified
495         /// DateTime.</returns>
496         /// <exception cref="T:System.ArgumentOutOfRangeException">
497         /// The exception is thrown if
498         /// <see cref="T:System.DateTime"/> return value is outside all
499         /// supported eras.
500         /// </exception>
501         public override DateTime AddYears(DateTime time, int years) {
502                 DateTime t = CCGregorianCalendar.AddYears(time, years);
503                 M_CheckDateTime(t);
504                 return t;
505         }
506                 
507         /// <summary>
508         /// Overriden. Gets the day of the month from
509         /// <paramref name="time"/>.
510         /// </summary>
511         /// <param name="time">The
512         /// <see cref="T:System.DateTime"/> that specifies a
513         /// date.
514         /// </param>
515         /// <returns>An integer giving the day of months, starting with 1.
516         /// </returns>
517         /// <exception cref="T:System.ArgumentOutOfRangeException">
518         /// The exception is thrown if the
519         /// <see cref="T:System.DateTime"/> parameter is outside all
520         /// supported eras.
521         /// </exception>
522         public override int GetDayOfMonth(DateTime time) {
523                 M_CheckDateTime(time);
524                 return CCGregorianCalendar.GetDayOfMonth(time);
525         }
526
527         /// <summary>
528         /// Overriden. Gets the day of the week from the specified date.
529         /// </summary>
530         /// <param name="time">The
531         /// <see cref="T:System.DateTime"/> that specifies a
532         /// date.
533         /// </param>
534         /// <returns>An integer giving the day of months, starting with 1.
535         /// </returns>
536         /// <exception cref="T:System.ArgumentOutOfRangeException">
537         /// The exception is thrown if the
538         /// <see cref="T:System.DateTime"/> parameter is outside all
539         /// supported eras.
540         /// </exception>
541         public override DayOfWeek GetDayOfWeek(DateTime time) {
542                 M_CheckDateTime(time);
543                 int rd = CCFixed.FromDateTime(time);
544                 return (DayOfWeek)CCFixed.day_of_week(rd);
545         }
546
547         /// <summary>
548         /// Overridden. Gives the number of the day in the year.
549         /// </summary>
550         /// <param name="time">The
551         /// <see cref="T:System.DateTime"/> that specifies a
552         /// date.
553         /// </param>
554         /// <returns>An integer representing the day of the year,
555         /// starting with 1.</returns>
556         /// <exception cref="T:System.ArgumentOutOfRangeException">
557         /// The exception is thrown if the
558         /// <see cref="T:System.DateTime"/> parameter is outside all
559         /// supported eras.
560         /// </exception>
561         public override int GetDayOfYear(DateTime time) {
562                 M_CheckDateTime(time);
563                 return CCGregorianCalendar.GetDayOfYear(time);
564         }
565
566         /// <summary>
567         /// Overridden. Gives the number of days in the specified month
568         /// of the given year and era.
569         /// </summary>
570         /// <param name="year">An integer that gives the year.
571         /// </param>
572         /// <param name="month">An integer that gives the month, starting
573         /// with 1.</param>
574         /// <param name="era">An integer that gives the era of the specified
575         /// year.</param>
576         /// <returns>An integer that gives the number of days of the
577         /// specified month.</returns>
578         /// <exception cref="T:System.ArgumentOutOfRangeException">
579         /// The exception is thrown, if <paramref name="month"/>,
580         /// <paramref name="year"/> ,or <paramref name="era"/> is outside
581         /// the allowed range.
582         /// </exception>
583         public override int GetDaysInMonth(int year, int month, int era) {
584                 int gregorianYear = M_CheckYMEG(year, month, ref era);
585                 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
586         }
587
588         /// <summary>
589         /// Overridden. Gives the number of days of the specified
590         /// year of the given era. 
591         /// </summary>
592         /// <param name="year">An integer that specifies the year. 
593         /// </param>
594         /// <param name="era">An ineger that specifies the era.
595         /// </param>
596         /// <returns>An integer that gives the number of days of the
597         /// specified year.</returns>
598         /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
599         /// The exception is thrown, if
600         /// <paramref name="year"/> or <paramref name="era"/> are outside the
601         /// allowed range.
602         /// </exception>
603         public override int GetDaysInYear(int year, int era) {
604                 int gregorianYear = M_CheckYEG(year, ref era);
605                 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
606         }
607                 
608
609         /// <summary>
610         /// Overridden. Gives the era of the specified date.
611         /// </summary>
612         /// <param name="time">The
613         /// <see cref="T:System.DateTime"/> that specifies a
614         /// date.
615         /// </param>
616         /// <returns>An integer representing the era of the calendar.
617         /// </returns>
618         /// <exception cref="T:System.ArgumentOutOfRangeException">
619         /// The exception is thrown if the
620         /// <see cref="T:System.DateTime"/> parameter is outside all
621         /// supported eras.
622         /// </exception>
623         public override int GetEra(DateTime time) {
624                 // M_CheckDateTime not needed, because EraYear does the
625                 // right thing.
626                 int rd = CCFixed.FromDateTime(time);
627                 int era;
628                 M_EraHandler.EraYear(out era, rd);
629                 return era;
630         }
631
632         /// <summary>
633         /// Overridden. Gives the number of the month of the specified
634         /// date.
635         /// </summary>
636         /// <param name="time">The
637         /// <see cref="T:System.DateTime"/> that specifies a
638         /// date.
639         /// </param>
640         /// <returns>An integer representing the month, 
641         /// starting with 1.</returns>
642         /// <exception cref="T:System.ArgumentOutOfRangeException">
643         /// The exception is thrown if the
644         /// <see cref="T:System.DateTime"/> parameter is outside all
645         /// supported eras.
646         /// </exception>
647         public override int GetMonth(DateTime time) {
648                 M_CheckDateTime(time);
649                 return CCGregorianCalendar.GetMonth(time);
650         }
651
652         /// <summary>
653         /// Overridden. Gives the number of months in the specified year 
654         /// and era.
655         /// </summary>
656         /// <param name="year">An integer that specifies the year.
657         /// </param>
658         /// <param name="era">An integer that specifies the era.
659         /// </param>
660         /// <returns>An integer that gives the number of the months in the
661         /// specified year.</returns>
662         /// <exception cref="T:System.ArgumentOutOfRangeException">
663         /// The exception is thrown, if the year or the era are not valid.
664         /// </exception>
665         public override int GetMonthsInYear(int year, int era) {
666                 M_CheckYE(year, ref era);
667                 return 12;
668         }
669
670         /// <summary>
671         /// Overridden. Gives the number of the year of the specified
672         /// date.
673         /// </summary>
674         /// <param name="time">The
675         /// <see cref="T:System.DateTime"/> that specifies a
676         /// date.
677         /// </param>
678         /// <returns>An integer representing the year, 
679         /// starting with 1.</returns>
680         /// <exception cref="T:System.ArgumentOutOfRangeException">
681         /// The exception is thrown if the
682         /// <see cref="T:System.DateTime"/> parameter is outside all
683         /// supported eras.
684         /// </exception>
685         public override int GetYear(DateTime time) {
686                 // M_CheckDateTime not needed, because EraYeat does the
687                 // right thing.
688                 int rd = CCFixed.FromDateTime(time);
689                 int era;
690                 return M_EraHandler.EraYear(out era, rd);
691         }
692
693         /// <summary>
694         /// Overridden. Tells whether the given day 
695         /// is a leap day.
696         /// </summary>
697         /// <param name="year">An integer that specifies the year in the
698         /// given era.
699         /// </param>
700         /// <param name="month">An integer that specifies the month.
701         /// </param>
702         /// <param name="day">An integer that specifies the day.
703         /// </param>
704         /// <param name="era">An integer that specifies the era.
705         /// </param>
706         /// <returns>A boolean that tells whether the given day is a leap
707         /// day.
708         /// </returns>
709         /// <exception cref="T:System.ArgumentOutOfRangeException">
710         /// The exception is thrown, if the year, month, day, or era is not
711         /// valid.
712         /// </exception>
713         public override bool IsLeapDay(int year, int month, int day, int era)
714         {
715                 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
716                 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
717         }
718
719         /// <summary>
720         /// Overridden. Tells whether the given month 
721         /// is a leap month.
722         /// </summary>
723         /// <param name="year">An integer that specifies the year in the
724         /// given era.
725         /// </param>
726         /// <param name="month">An integer that specifies the month.
727         /// </param>
728         /// <param name="era">An integer that specifies the era.
729         /// </param>
730         /// <returns>A boolean that tells whether the given month is a leap
731         /// month.
732         /// </returns>
733         /// <exception cref="T:System.ArgumentOutOfRangeException">
734         /// The exception is thrown, if the year, month, or era is not
735         /// valid.
736         /// </exception>
737         public override bool IsLeapMonth(int year, int month, int era) {
738                 M_CheckYMEG(year, month, ref era);
739                 return false;
740         }
741
742         /// <summary>
743         /// Overridden. Tells whether the given year
744         /// is a leap year.
745         /// </summary>
746         /// <param name="year">An integer that specifies the year in the
747         /// given era.
748         /// </param>
749         /// <param name="era">An integer that specifies the era.
750         /// </param>
751         /// <returns>A boolean that tells whether the given year is a leap
752         /// year.
753         /// </returns>
754         /// <exception cref="T:System.ArgumentOutOfRangeException">
755         /// The exception is thrown, if the year or era is not
756         /// valid.
757         /// </exception>
758         public override bool IsLeapYear(int year, int era) {
759                 int gregorianYear = M_CheckYEG(year, ref era);
760                 return CCGregorianCalendar.is_leap_year(gregorianYear);
761         }
762
763         /// <summary>
764         /// Overridden. Creates the
765         /// <see cref="T:System.DateTime"/> from the parameters.
766         /// </summary>
767         /// <param name="year">An integer that gives the year in the
768         /// <paramref name="era"/>.
769         /// </param>
770         /// <param name="month">An integer that specifies the month.
771         /// </param>
772         /// <param name="day">An integer that specifies the day.
773         /// </param>
774         /// <param name="hour">An integer that specifies the hour.
775         /// </param>
776         /// <param name="minute">An integer that specifies the minute.
777         /// </param>
778         /// <param name="second">An integer that gives the second.
779         /// </param>
780         /// <param name="milliseconds">An integer that gives the
781         /// milliseconds.
782         /// </param>
783         /// <param name="era">An integer that specifies the era.
784         /// </param>
785         /// <returns>A
786         /// <see cref="T:system.DateTime"/> representig the date and time.
787         /// </returns>
788         /// <exception cref="T:System.ArgumentOutOfRangeException">
789         /// The exception is thrown, if at least one of the parameters
790         /// is out of range.
791         /// </exception>
792         public override DateTime ToDateTime(int year, int month, int day,
793                 int hour, int minute, int second, int milliseconds,
794                 int era)
795         {
796                 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
797                 M_CheckHMSM(hour, minute, second, milliseconds);
798                 return CCGregorianCalendar.ToDateTime(
799                         gregorianYear, month, day,
800                         hour, minute, second, milliseconds);
801         }
802
803
804         /// <summary>
805         /// This functions returns simply the year for the Japanese calendar.
806         /// </summary>
807         /// <param name="year">An integer that gives the year.
808         /// </param>
809         /// <returns>The same argument as the year.
810         /// </returns>
811         /// <exception cref="T:System.ArgumentOutOfRangeException">
812         /// The exception is thrown if the year is negative or the resulting 
813         /// year is invalid.
814         /// </exception>
815         public override int ToFourDigitYear(int year) {
816                 if (year < 0)
817                         throw new ArgumentOutOfRangeException(
818                                 "year", "Non-negative number required.");
819                 int era = CurrentEra;
820                 M_CheckYE(year, ref era);
821                 return year;
822         }
823 } // class JapaneseCalendar
824         
825 } // namespace System.Globalization