2006-11-16 Miguel de Icaza <miguel@novell.com>
[mono-project.git] / mcs / class / corlib / System.Globalization / JapaneseCalendar.cs
blob1fdcaeb2960a9ccae0926fa11d065f99109e8241
1 // JapaneseCalendar.cs
2 //
3 // (C) Ulrich Kunitz 2002
4 //
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.
29 namespace System.Globalization {
31 using System;
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 ("Serialization format not compatible with .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;
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));
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" };
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();
117 int twoDigitYearMax = 99;
119 public override int TwoDigitYearMax
121 get {
122 return twoDigitYearMax;
124 set {
125 CheckReadOnly ();
126 M_ArgumentInRange ("value", value, 100, M_MaxYear);
128 twoDigitYearMax = value;
132 /// <summary>
133 /// A protected member checking a
134 /// <see cref="T:System.DateTime"/> value.
135 /// </summary>
136 /// <param name="time">The
137 /// <see cref="T:System.DateTime"/>
138 /// to check.
139 /// </param>
140 /// <exception cref="T:System.ArgumentOutOfRangeException">
141 /// The exception is thrown if the
142 /// <see cref="T:System.DateTime"/> parameter is outside all
143 /// supported eras.
144 /// </exception>
145 internal void M_CheckDateTime(DateTime time) {
146 M_EraHandler.CheckDateTime(time);
149 /// <summary>
150 /// A protected method checking the era number.
151 /// </summary>
152 /// <param name="era">The era number as reference. It is set
153 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
154 /// <exception name="T:System.ArgumentException">
155 /// The exception is thrown if the era is not supported by the class.
156 /// </exception>
157 internal void M_CheckEra(ref int era) {
158 if (era == CurrentEra)
159 era = 4;
160 if (!M_EraHandler.ValidEra(era))
161 throw new ArgumentException("Era value was not valid.");
164 /// <summary>
165 /// A protected method checking calendar year and the era number.
166 /// </summary>
167 /// <param name="year">An integer representing the calendar year.
168 /// </param>
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.
172 /// </exception>
173 /// <exception cref="T:System.ArgumentOutOfRangeException">
174 /// The exception is thrown if the calendar year is outside of
175 /// the supported range.
176 /// </exception>
177 internal int M_CheckYEG(int year, ref int era) {
178 M_CheckEra(ref era);
179 return M_EraHandler.GregorianYear(year, era);
182 /// <summary>
183 /// Checks whether the year is the era is valid, if era = CurrentEra
184 /// the right value is set.
185 /// </summary>
186 /// <param name="year">The year to check.</param>
187 /// <param name="era">The era to check.</Param>
188 /// <exception cref="T:ArgumentOutOfRangeException">
189 /// The exception will be thrown, if the year is not valid.
190 /// </exception>
191 internal override void M_CheckYE(int year, ref int era) {
192 M_CheckYEG(year, ref era);
195 /// <summary>
196 /// A protected method checking the calendar year, month, and
197 /// era number.
198 /// </summary>
199 /// <param name="year">An integer representing the calendar year.
200 /// </param>
201 /// <param name="month">An integer giving the calendar month.
202 /// </param>
203 /// <param name="era">The era number as reference.</param>
204 /// <exception name="T:System.ArgumentException">
205 /// The exception is thrown if the era is not supported by the class.
206 /// </exception>
207 /// <exception cref="T:System.ArgumentOutOfRangeException">
208 /// The exception is thrown if the calendar year or month is
209 /// outside of the supported range.
210 /// </exception>
211 internal int M_CheckYMEG(int year, int month, ref int era) {
212 int gregorianYear = M_CheckYEG(year, ref era);
213 if (month < 1 || month > 12)
214 throw new ArgumentOutOfRangeException("month",
215 "Month must be between one and twelve.");
216 return gregorianYear;
219 /// <summary>
220 /// A protected method checking the calendar day, month, and year
221 /// and the era number.
222 /// </summary>
223 /// <param name="year">An integer representing the calendar year.
224 /// </param>
225 /// <param name="month">An integer giving the calendar month.
226 /// </param>
227 /// <param name="day">An integer giving the calendar day.
228 /// </param>
229 /// <param name="era">The era number as reference.</param>
230 /// <exception name="T:System.ArgumentException">
231 /// The exception is thrown if the era is not supported by the class.
232 /// </exception>
233 /// <exception cref="T:System.ArgumentOutOfRangeException">
234 /// The exception is thrown if the calendar year, month, or day is
235 /// outside of the supported range.
236 /// </exception>
237 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
239 int gregorianYear = M_CheckYMEG(year, month, ref era);
240 M_ArgumentInRange("day", day, 1, GetDaysInMonth(year, month, era));
241 return gregorianYear;
244 #if false
246 // Ifdefed out because this is not on the .NET Framewokr.
248 /// <summary>
249 /// Overridden. Adds days to a given date.
250 /// </summary>
251 /// <param name="time">The
252 /// <see cref="T:System.DateTime"/> to which to add
253 /// days.
254 /// </param>
255 /// <param name="days">The number of days to add.</param>
256 /// <returns>A new <see cref="T:System.DateTime"/> value, that
257 /// results from adding <paramref name="days"/> to the specified
258 /// DateTime.</returns>
259 /// <exception cref="T:System.ArgumentOutOfRangeException">
260 /// The exception is thrown if the
261 /// <see cref="T:System.DateTime"/> return value is outside all
262 /// supported eras.
263 /// </exception>
264 public override DateTime AddDays(DateTime time, int days) {
265 DateTime t = base.AddDays(time, days);
266 M_CheckDateTime(t);
267 return t;
270 /// <summary>
271 /// Overridden. Adds hours to a given date.
272 /// </summary>
273 /// <param name="time">The
274 /// <see cref="T:System.DateTime"/> to which to add
275 /// hours.
276 /// </param>
277 /// <param name="hours">The number of hours to add.</param>
278 /// <returns>A new <see cref="T:System.DateTime"/> value, that
279 /// results from adding <paramref name="hours"/> to the specified
280 /// DateTime.</returns>
281 /// <exception cref="T:System.ArgumentOutOfRangeException">
282 /// The exception is thrown if the
283 /// <see cref="T:System.DateTime"/> return value is outside all
284 /// supported eras.
285 /// </exception>
286 public override DateTime AddHours(DateTime time, int hours) {
287 DateTime t = base.AddHours(time, hours);
288 M_CheckDateTime(t);
289 return t;
292 /// <summary>
293 /// Overridden. Adds milliseconds to a given date.
294 /// </summary>
295 /// <param name="time">The
296 /// <see cref="T:System.DateTime"/> to which to add
297 /// milliseconds.
298 /// </param>
299 /// <param name="milliseconds">The number of milliseconds given as
300 /// double to add. Keep in mind the 100 nanosecond resolution of
301 /// <see cref="T:System.DateTime"/>.
302 /// </param>
303 /// <returns>A new <see cref="T:System.DateTime"/> value, that
304 /// results from adding <paramref name="milliseconds"/> to the specified
305 /// DateTime.</returns>
306 /// <exception cref="T:System.ArgumentOutOfRangeException">
307 /// The exception is thrown if the
308 /// <see cref="T:System.DateTime"/> return value is outside all
309 /// supported eras.
310 /// </exception>
311 public override DateTime AddMilliseconds(DateTime time,
312 double milliseconds)
314 DateTime t = base.AddMilliseconds(time, milliseconds);
315 M_CheckDateTime(t);
316 return t;
319 /// <summary>
320 /// Overridden. Adds minutes to a given date.
321 /// </summary>
322 /// <param name="time">The
323 /// <see cref="T:System.DateTime"/> to which to add
324 /// minutes.
325 /// </param>
326 /// <param name="minutes">The number of minutes to add.</param>
327 /// <returns>A new <see cref="T:System.DateTime"/> value, that
328 /// results from adding <paramref name="minutes"/> to the specified
329 /// DateTime.</returns>
330 /// <exception cref="T:System.ArgumentOutOfRangeException">
331 /// The exception is thrown if the
332 /// <see cref="T:System.DateTime"/> return value is outside all
333 /// supported eras.
334 /// </exception>
335 public override DateTime AddMinutes(DateTime time, int minutes) {
336 DateTime t = base.AddMinutes(time, minutes);
337 M_CheckDateTime(t);
338 return t;
341 /// <summary>
342 /// Overridden. Adds seconds to a given date.
343 /// </summary>
344 /// <param name="time">The
345 /// <see cref="T:System.DateTime"/> to which to add
346 /// seconds.
347 /// </param>
348 /// <param name="seconds">The number of seconds to add.</param>
349 /// <returns>A new <see cref="T:System.DateTime"/> value, that
350 /// results from adding <paramref name="seconds"/> to the specified
351 /// DateTime.</returns>
352 /// <exception cref="T:System.ArgumentOutOfRangeException">
353 /// The exception is thrown if the
354 /// <see cref="T:System.DateTime"/> return value is outside all
355 /// supported eras.
356 /// </exception>
357 public override DateTime AddSeconds(DateTime time, int seconds) {
358 DateTime t = base.AddSeconds(time, seconds);
359 M_CheckDateTime(t);
360 return t;
364 /// <summary>
365 /// Overridden. Adds weeks to a given date.
366 /// </summary>
367 /// <param name="time">The
368 /// <see cref="T:System.DateTime"/> to which to add
369 /// weeks.
370 /// </param>
371 /// <param name="weeks">The number of weeks to add.</param>
372 /// <returns>A new <see cref="T:System.DateTime"/> value, that
373 /// results from adding <paramref name="weeks"/> to the specified
374 /// DateTime.</returns>
375 /// <exception cref="T:System.ArgumentOutOfRangeException">
376 /// The exception is thrown if the
377 /// <see cref="T:System.DateTime"/> return value is outside all
378 /// supported eras.
379 /// </exception>
380 public override DateTime AddWeeks(DateTime time, int weeks) {
381 DateTime t = base.AddWeeks(time, weeks);
382 M_CheckDateTime(t);
383 return t;
386 /// <summary>
387 /// Overridden. Gives the hour of the specified time.
388 /// </summary>
389 /// <param name="time">The
390 /// <see cref="T:System.DateTime"/> that specifies the
391 /// time.
392 /// </param>
393 /// <returns>An integer that gives the hour of the specified time,
394 /// starting with 0.</returns>
395 /// <exception cref="T:System.ArgumentOutOfRangeException">
396 /// The exception is thrown if the
397 /// <see cref="T:System.DateTime"/> parameter is outside all
398 /// supported eras.
399 /// </exception>
400 public override int GetHour(DateTime time) {
401 M_CheckDateTime(time);
402 return base.GetHour(time);
405 /// <summary>
406 /// Overridden. Gives the milliseconds in the current second
407 /// of the specified time.
408 /// </summary>
409 /// <param name="time">The
410 /// <see cref="T:System.DateTime"/> that specifies the
411 /// time.
412 /// </param>
413 /// <returns>An integer that gives the milliseconds in the seconds
414 /// of the specified time, starting with 0.</returns>
415 /// <exception cref="T:System.ArgumentOutOfRangeException">
416 /// The exception is thrown if the
417 /// <see cref="T:System.DateTime"/> parameter is outside all
418 /// supported eras.
419 /// </exception>
420 public override double GetMilliseconds(DateTime time) {
421 M_CheckDateTime(time);
422 return base.GetMilliseconds(time);
425 /// <summary>
426 /// Overridden. Gives the minute of the specified time.
427 /// </summary>
428 /// <param name="time">The
429 /// <see cref="T:System.DateTime"/> that specifies the
430 /// time.
431 /// </param>
432 /// <returns>An integer that gives the minute of the specified time,
433 /// starting with 0.</returns>
434 /// <exception cref="T:System.ArgumentOutOfRangeException">
435 /// The exception is thrown if the
436 /// <see cref="T:System.DateTime"/> parameter is outside all
437 /// supported eras.
438 /// </exception>
439 public override int GetMinute(DateTime time) {
440 M_CheckDateTime(time);
441 return base.GetMinute(time);
444 /// <summary>
445 /// Overridden. Gives the second of the specified time.
446 /// </summary>
447 /// <param name="time">The
448 /// <see cref="T:System.DateTime"/> that specifies the
449 /// time.
450 /// </param>
451 /// <returns>An integer that gives the second of the specified time,
452 /// starting with 0.</returns>
453 /// <exception cref="T:System.ArgumentOutOfRangeException">
454 /// The exception is thrown if the
455 /// <see cref="T:System.DateTime"/> parameter is outside all
456 /// supported eras.
457 /// </exception>
458 public override int GetSecond(DateTime time) {
459 M_CheckDateTime(time);
460 return base.GetMinute(time);
462 #endif
464 /// <summary>
465 /// Overrideden. Adds months to a given date.
466 /// </summary>
467 /// <param name="time">The
468 /// <see cref="T:System.DateTime"/> to which to add
469 /// months.
470 /// </param>
471 /// <param name="months">The number of months to add.</param>
472 /// <returns>A new <see cref="T:System.DateTime"/> value, that
473 /// results from adding <paramref name="months"/> to the specified
474 /// DateTime.</returns>
475 /// <exception cref="T:System.ArgumentOutOfRangeException">
476 /// The exception is thrown if
477 /// <see cref="T:System.DateTime"/> return value is outside all
478 /// supported eras.
479 /// </exception>
480 public override DateTime AddMonths(DateTime time, int months) {
481 DateTime t = CCGregorianCalendar.AddMonths(time, months);
482 M_CheckDateTime(t);
483 return t;
486 /// <summary>
487 /// Overridden. Adds years to a given date.
488 /// </summary>
489 /// <param name="time">The
490 /// <see cref="T:System.DateTime"/> to which to add
491 /// years.
492 /// </param>
493 /// <param name="years">The number of years to add.</param>
494 /// <returns>A new <see cref="T:System.DateTime"/> value, that
495 /// results from adding <paramref name="years"/> to the specified
496 /// DateTime.</returns>
497 /// <exception cref="T:System.ArgumentOutOfRangeException">
498 /// The exception is thrown if
499 /// <see cref="T:System.DateTime"/> return value is outside all
500 /// supported eras.
501 /// </exception>
502 public override DateTime AddYears(DateTime time, int years) {
503 DateTime t = CCGregorianCalendar.AddYears(time, years);
504 M_CheckDateTime(t);
505 return t;
508 /// <summary>
509 /// Overriden. Gets the day of the month from
510 /// <paramref name="time"/>.
511 /// </summary>
512 /// <param name="time">The
513 /// <see cref="T:System.DateTime"/> that specifies a
514 /// date.
515 /// </param>
516 /// <returns>An integer giving the day of months, starting with 1.
517 /// </returns>
518 /// <exception cref="T:System.ArgumentOutOfRangeException">
519 /// The exception is thrown if the
520 /// <see cref="T:System.DateTime"/> parameter is outside all
521 /// supported eras.
522 /// </exception>
523 public override int GetDayOfMonth(DateTime time) {
524 M_CheckDateTime(time);
525 return CCGregorianCalendar.GetDayOfMonth(time);
528 /// <summary>
529 /// Overriden. Gets the day of the week from the specified date.
530 /// </summary>
531 /// <param name="time">The
532 /// <see cref="T:System.DateTime"/> that specifies a
533 /// date.
534 /// </param>
535 /// <returns>An integer giving the day of months, starting with 1.
536 /// </returns>
537 /// <exception cref="T:System.ArgumentOutOfRangeException">
538 /// The exception is thrown if the
539 /// <see cref="T:System.DateTime"/> parameter is outside all
540 /// supported eras.
541 /// </exception>
542 public override DayOfWeek GetDayOfWeek(DateTime time) {
543 M_CheckDateTime(time);
544 int rd = CCFixed.FromDateTime(time);
545 return (DayOfWeek)CCFixed.day_of_week(rd);
548 /// <summary>
549 /// Overridden. Gives the number of the day in the year.
550 /// </summary>
551 /// <param name="time">The
552 /// <see cref="T:System.DateTime"/> that specifies a
553 /// date.
554 /// </param>
555 /// <returns>An integer representing the day of the year,
556 /// starting with 1.</returns>
557 /// <exception cref="T:System.ArgumentOutOfRangeException">
558 /// The exception is thrown if the
559 /// <see cref="T:System.DateTime"/> parameter is outside all
560 /// supported eras.
561 /// </exception>
562 public override int GetDayOfYear(DateTime time) {
563 M_CheckDateTime(time);
564 return CCGregorianCalendar.GetDayOfYear(time);
567 /// <summary>
568 /// Overridden. Gives the number of days in the specified month
569 /// of the given year and era.
570 /// </summary>
571 /// <param name="year">An integer that gives the year.
572 /// </param>
573 /// <param name="month">An integer that gives the month, starting
574 /// with 1.</param>
575 /// <param name="era">An integer that gives the era of the specified
576 /// year.</param>
577 /// <returns>An integer that gives the number of days of the
578 /// specified month.</returns>
579 /// <exception cref="T:System.ArgumentOutOfRangeException">
580 /// The exception is thrown, if <paramref name="month"/>,
581 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
582 /// the allowed range.
583 /// </exception>
584 public override int GetDaysInMonth(int year, int month, int era) {
585 int gregorianYear = M_CheckYMEG(year, month, ref era);
586 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
589 /// <summary>
590 /// Overridden. Gives the number of days of the specified
591 /// year of the given era.
592 /// </summary>
593 /// <param name="year">An integer that specifies the year.
594 /// </param>
595 /// <param name="era">An ineger that specifies the era.
596 /// </param>
597 /// <returns>An integer that gives the number of days of the
598 /// specified year.</returns>
599 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
600 /// The exception is thrown, if
601 /// <paramref name="year"/> or <paramref name="era"/> are outside the
602 /// allowed range.
603 /// </exception>
604 public override int GetDaysInYear(int year, int era) {
605 int gregorianYear = M_CheckYEG(year, ref era);
606 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
610 /// <summary>
611 /// Overridden. Gives the era of the specified date.
612 /// </summary>
613 /// <param name="time">The
614 /// <see cref="T:System.DateTime"/> that specifies a
615 /// date.
616 /// </param>
617 /// <returns>An integer representing the era of the calendar.
618 /// </returns>
619 /// <exception cref="T:System.ArgumentOutOfRangeException">
620 /// The exception is thrown if the
621 /// <see cref="T:System.DateTime"/> parameter is outside all
622 /// supported eras.
623 /// </exception>
624 public override int GetEra(DateTime time) {
625 // M_CheckDateTime not needed, because EraYear does the
626 // right thing.
627 int rd = CCFixed.FromDateTime(time);
628 int era;
629 M_EraHandler.EraYear(out era, rd);
630 return era;
633 /// <summary>
634 /// Overridden. Gives the number of the month of the specified
635 /// date.
636 /// </summary>
637 /// <param name="time">The
638 /// <see cref="T:System.DateTime"/> that specifies a
639 /// date.
640 /// </param>
641 /// <returns>An integer representing the month,
642 /// starting with 1.</returns>
643 /// <exception cref="T:System.ArgumentOutOfRangeException">
644 /// The exception is thrown if the
645 /// <see cref="T:System.DateTime"/> parameter is outside all
646 /// supported eras.
647 /// </exception>
648 public override int GetMonth(DateTime time) {
649 M_CheckDateTime(time);
650 return CCGregorianCalendar.GetMonth(time);
653 /// <summary>
654 /// Overridden. Gives the number of months in the specified year
655 /// and era.
656 /// </summary>
657 /// <param name="year">An integer that specifies the year.
658 /// </param>
659 /// <param name="era">An integer that specifies the era.
660 /// </param>
661 /// <returns>An integer that gives the number of the months in the
662 /// specified year.</returns>
663 /// <exception cref="T:System.ArgumentOutOfRangeException">
664 /// The exception is thrown, if the year or the era are not valid.
665 /// </exception>
666 public override int GetMonthsInYear(int year, int era) {
667 M_CheckYE(year, ref era);
668 return 12;
671 /// <summary>
672 /// Overridden. Gives the number of the year of the specified
673 /// date.
674 /// </summary>
675 /// <param name="time">The
676 /// <see cref="T:System.DateTime"/> that specifies a
677 /// date.
678 /// </param>
679 /// <returns>An integer representing the year,
680 /// starting with 1.</returns>
681 /// <exception cref="T:System.ArgumentOutOfRangeException">
682 /// The exception is thrown if the
683 /// <see cref="T:System.DateTime"/> parameter is outside all
684 /// supported eras.
685 /// </exception>
686 public override int GetYear(DateTime time) {
687 // M_CheckDateTime not needed, because EraYeat does the
688 // right thing.
689 int rd = CCFixed.FromDateTime(time);
690 int era;
691 return M_EraHandler.EraYear(out era, rd);
694 /// <summary>
695 /// Overridden. Tells whether the given day
696 /// is a leap day.
697 /// </summary>
698 /// <param name="year">An integer that specifies the year in the
699 /// given era.
700 /// </param>
701 /// <param name="month">An integer that specifies the month.
702 /// </param>
703 /// <param name="day">An integer that specifies the day.
704 /// </param>
705 /// <param name="era">An integer that specifies the era.
706 /// </param>
707 /// <returns>A boolean that tells whether the given day is a leap
708 /// day.
709 /// </returns>
710 /// <exception cref="T:System.ArgumentOutOfRangeException">
711 /// The exception is thrown, if the year, month, day, or era is not
712 /// valid.
713 /// </exception>
714 public override bool IsLeapDay(int year, int month, int day, int era)
716 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
717 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
720 /// <summary>
721 /// Overridden. Tells whether the given month
722 /// is a leap month.
723 /// </summary>
724 /// <param name="year">An integer that specifies the year in the
725 /// given era.
726 /// </param>
727 /// <param name="month">An integer that specifies the month.
728 /// </param>
729 /// <param name="era">An integer that specifies the era.
730 /// </param>
731 /// <returns>A boolean that tells whether the given month is a leap
732 /// month.
733 /// </returns>
734 /// <exception cref="T:System.ArgumentOutOfRangeException">
735 /// The exception is thrown, if the year, month, or era is not
736 /// valid.
737 /// </exception>
738 public override bool IsLeapMonth(int year, int month, int era) {
739 M_CheckYMEG(year, month, ref era);
740 return false;
743 /// <summary>
744 /// Overridden. Tells whether the given year
745 /// is a leap year.
746 /// </summary>
747 /// <param name="year">An integer that specifies the year in the
748 /// given era.
749 /// </param>
750 /// <param name="era">An integer that specifies the era.
751 /// </param>
752 /// <returns>A boolean that tells whether the given year is a leap
753 /// year.
754 /// </returns>
755 /// <exception cref="T:System.ArgumentOutOfRangeException">
756 /// The exception is thrown, if the year or era is not
757 /// valid.
758 /// </exception>
759 public override bool IsLeapYear(int year, int era) {
760 int gregorianYear = M_CheckYEG(year, ref era);
761 return CCGregorianCalendar.is_leap_year(gregorianYear);
764 /// <summary>
765 /// Overridden. Creates the
766 /// <see cref="T:System.DateTime"/> from the parameters.
767 /// </summary>
768 /// <param name="year">An integer that gives the year in the
769 /// <paramref name="era"/>.
770 /// </param>
771 /// <param name="month">An integer that specifies the month.
772 /// </param>
773 /// <param name="day">An integer that specifies the day.
774 /// </param>
775 /// <param name="hour">An integer that specifies the hour.
776 /// </param>
777 /// <param name="minute">An integer that specifies the minute.
778 /// </param>
779 /// <param name="second">An integer that gives the second.
780 /// </param>
781 /// <param name="milliseconds">An integer that gives the
782 /// milliseconds.
783 /// </param>
784 /// <param name="era">An integer that specifies the era.
785 /// </param>
786 /// <returns>A
787 /// <see cref="T:system.DateTime"/> representig the date and time.
788 /// </returns>
789 /// <exception cref="T:System.ArgumentOutOfRangeException">
790 /// The exception is thrown, if at least one of the parameters
791 /// is out of range.
792 /// </exception>
793 public override DateTime ToDateTime(int year, int month, int day,
794 int hour, int minute, int second, int milliseconds,
795 int era)
797 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
798 M_CheckHMSM(hour, minute, second, milliseconds);
799 return CCGregorianCalendar.ToDateTime(
800 gregorianYear, month, day,
801 hour, minute, second, milliseconds);
805 /// <summary>
806 /// This functions returns simply the year for the Japanese calendar.
807 /// </summary>
808 /// <param name="year">An integer that gives the year.
809 /// </param>
810 /// <returns>The same argument as the year.
811 /// </returns>
812 /// <exception cref="T:System.ArgumentOutOfRangeException">
813 /// The exception is thrown if the year is negative or the resulting
814 /// year is invalid.
815 /// </exception>
816 public override int ToFourDigitYear(int year) {
817 if (year < 0)
818 throw new ArgumentOutOfRangeException(
819 "year", "Non-negative number required.");
820 int era = CurrentEra;
821 M_CheckYE(year, ref era);
822 return year;
825 #if NET_2_0
826 public override CalendarAlgorithmType AlgorithmType {
827 get {
828 return CalendarAlgorithmType.SolarCalendar;
832 static DateTime JapanMin = new DateTime (1868, 9, 8, 0, 0, 0);
833 static DateTime JapanMax = new DateTime (9999, 12, 31, 11, 59, 59);
835 public override DateTime MinSupportedDateTime {
836 get {
837 return JapanMin;
841 public override DateTime MaxSupportedDateTime {
842 get {
843 return JapanMax;
846 #endif
848 } // class JapaneseCalendar
850 } // namespace System.Globalization