3 // (C) Ulrich Kunitz 2002
6 namespace System.Globalization {
11 /// This is the Korean calendar. It differs from the Gegorian calendar only
12 /// in the year counting.
15 /// <para>The implementation uses the
16 /// <see cref="N:CalendricalCalculations"/> namespace.
20 public class KoreanCalendar : Calendar {
22 /// Static protected field storing the
23 /// <see cref="T:CalendricalCalculations.GregorianEraHandler"/>.
25 internal static readonly CCGregorianEraHandler M_EraHandler;
28 /// The standard era for the <see cref="T:KoreanCalendar"/>.
30 public const int KoreanEra = 1;
33 /// Static constructor, who creates and initializes
34 /// <see cref="F:M_EraHandler"/>.
36 static KoreanCalendar() {
37 M_EraHandler = new CCGregorianEraHandler();
38 M_EraHandler.appendEra(KoreanEra,
39 CCGregorianCalendar.fixed_from_dmy(1, 1, -2332));
43 /// Default constructor.
45 public KoreanCalendar() {
46 M_AbbrEraNames = new string[] {"K.C.E."};
47 M_EraNames = new string[] {"Korean Current Era"};
48 if (M_TwoDigitYearMax == 99)
49 M_TwoDigitYearMax = 4362;
52 /// <value>Overridden. Gives the eras supported by the
53 /// calendar as an array of integers.
55 public override int[] Eras {
57 return (int[])M_EraHandler.Eras.Clone();
61 int twoDigitYearMax = 4362;
63 public override int TwoDigitYearMax
66 return twoDigitYearMax;
69 M_ArgumentInRange ("value", value, 100, M_MaxYear);
71 twoDigitYearMax = value;
76 /// A protected method checking the era number.
78 /// <param name="era">The era number as reference. It is set
79 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
80 /// <exception name="T:System.ArgumentException">
81 /// The exception is thrown if the era is not supported by the class.
83 internal void M_CheckEra(ref int era) {
84 if (era == CurrentEra)
86 if (!M_EraHandler.ValidEra(era))
87 throw new ArgumentException("Era value was not valid.");
91 /// A protected method checking calendar year and the era number.
93 /// <param name="year">An integer representing the calendar year.
95 /// <param name="era">The era number as reference.</param>
96 /// <exception name="T:System.ArgumentException">
97 /// The exception is thrown if the era is not supported by the class.
99 /// <exception cref="T:System.ArgumentOutOfRangeException">
100 /// The exception is thrown if the calendar year is outside of
101 /// the supported range.
103 internal int M_CheckYEG(int year, ref int era) {
105 return M_EraHandler.GregorianYear(year, era);
109 /// Checks whether the year is the era is valid, if era = CurrentEra
110 /// the right value is set.
112 /// <param name="year">The year to check.</param>
113 /// <param name="era">The era to check.</Param>
114 /// <exception cref="T:ArgumentOutOfRangeException">
115 /// The exception will be thrown, if the year is not valid.
117 internal override void M_CheckYE(int year, ref int era) {
118 M_CheckYEG(year, ref era);
122 /// A protected method checking the calendar year, month, and
125 /// <param name="year">An integer representing the calendar year.
127 /// <param name="month">An integer giving the calendar month.
129 /// <param name="era">The era number as reference.</param>
130 /// <exception name="T:System.ArgumentException">
131 /// The exception is thrown if the era is not supported by the class.
133 /// <exception cref="T:System.ArgumentOutOfRangeException">
134 /// The exception is thrown if the calendar year or month is
135 /// outside of the supported range.
137 internal int M_CheckYMEG(int year, int month, ref int era) {
138 int gregorianYear = M_CheckYEG(year, ref era);
139 if (month < 1 || month > 12)
140 throw new ArgumentOutOfRangeException("month",
141 "Month must be between one and twelve.");
142 return gregorianYear;
146 /// A protected method checking the calendar day, month, and year
147 /// and the era number.
149 /// <param name="year">An integer representing the calendar year.
151 /// <param name="month">An integer giving the calendar month.
153 /// <param name="day">An integer giving the calendar day.
155 /// <param name="era">The era number as reference.</param>
156 /// <exception name="T:System.ArgumentException">
157 /// The exception is thrown if the era is not supported by the class.
159 /// <exception cref="T:System.ArgumentOutOfRangeException">
160 /// The exception is thrown if the calendar year, month, or day is
161 /// outside of the supported range.
163 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
165 int gregorianYear = M_CheckYMEG(year, month, ref era);
166 M_ArgumentInRange("day", day, 1,
167 GetDaysInMonth(year, month, era));
168 return gregorianYear;
172 /// Overrideden. Adds months to a given date.
174 /// <param name="time">The
175 /// <see cref="T:System.DateTime"/> to which to add
178 /// <param name="months">The number of months to add.</param>
179 /// <returns>A new <see cref="T:System.DateTime"/> value, that
180 /// results from adding <paramref name="months"/> to the specified
181 /// DateTime.</returns>
182 public override DateTime AddMonths(DateTime time, int months) {
183 return CCGregorianCalendar.AddMonths(time, months);
187 /// Overridden. Adds years to a given date.
189 /// <param name="time">The
190 /// <see cref="T:System.DateTime"/> to which to add
193 /// <param name="years">The number of years to add.</param>
194 /// <returns>A new <see cref="T:System.DateTime"/> value, that
195 /// results from adding <paramref name="years"/> to the specified
196 /// DateTime.</returns>
197 public override DateTime AddYears(DateTime time, int years) {
198 return CCGregorianCalendar.AddYears(time, years);
202 /// Overriden. Gets the day of the month from
203 /// <paramref name="time"/>.
205 /// <param name="time">The
206 /// <see cref="T:System.DateTime"/> that specifies a
209 /// <returns>An integer giving the day of months, starting with 1.
211 public override int GetDayOfMonth(DateTime time) {
212 return CCGregorianCalendar.GetDayOfMonth(time);
216 /// Overriden. Gets the day of the week from the specified date.
218 /// <param name="time">The
219 /// <see cref="T:System.DateTime"/> that specifies a
222 /// <returns>An integer giving the day of months, starting with 1.
224 public override DayOfWeek GetDayOfWeek(DateTime time) {
225 int rd = CCFixed.FromDateTime(time);
226 return (DayOfWeek)CCFixed.day_of_week(rd);
230 /// Overridden. Gives the number of the day in the year.
232 /// <param name="time">The
233 /// <see cref="T:System.DateTime"/> that specifies a
236 /// <returns>An integer representing the day of the year,
237 /// starting with 1.</returns>
238 public override int GetDayOfYear(DateTime time) {
239 return CCGregorianCalendar.GetDayOfYear(time);
243 /// Overridden. Gives the number of days in the specified month
244 /// of the given year and era.
246 /// <param name="year">An integer that gives the year.
248 /// <param name="month">An integer that gives the month, starting
250 /// <param name="era">An integer that gives the era of the specified
252 /// <returns>An integer that gives the number of days of the
253 /// specified month.</returns>
254 /// <exception cref="T:System.ArgumentOutOfRangeException">
255 /// The exception is thrown, if <paramref name="month"/>,
256 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
257 /// the allowed range.
259 public override int GetDaysInMonth(int year, int month, int era) {
260 int gregorianYear = M_CheckYMEG(year, month, ref era);
261 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
265 /// Overridden. Gives the number of days of the specified
266 /// year of the given era.
268 /// <param name="year">An integer that specifies the year.
270 /// <param name="era">An ineger that specifies the era.
272 /// <returns>An integer that gives the number of days of the
273 /// specified year.</returns>
274 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
275 /// The exception is thrown, if
276 /// <paramref name="year"/> or <paramref name="era"/> are outside the
279 public override int GetDaysInYear(int year, int era) {
280 int gregorianYear = M_CheckYEG(year, ref era);
281 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
285 /// Overridden. Gives the era of the specified date.
287 /// <param name="time">The
288 /// <see cref="T:System.DateTime"/> that specifies a
291 /// <returns>An integer representing the era of the calendar.
293 public override int GetEra(DateTime time) {
294 int rd = CCFixed.FromDateTime(time);
296 M_EraHandler.EraYear(out era, rd);
301 /// Overridden. Gives the number of the month of the specified
304 /// <param name="time">The
305 /// <see cref="T:System.DateTime"/> that specifies a
308 /// <returns>An integer representing the month,
309 /// starting with 1.</returns>
310 public override int GetMonth(DateTime time) {
311 return CCGregorianCalendar.GetMonth(time);
315 /// Overridden. Gives the number of months in the specified year
318 /// <param name="year">An integer that specifies the year.
320 /// <param name="era">An integer that specifies the era.
322 /// <returns>An integer that gives the number of the months in the
323 /// specified year.</returns>
324 /// <exception cref="T:System.ArgumentOutOfRangeException">
325 /// The exception is thrown, if the year or the era are not valid.
327 public override int GetMonthsInYear(int year, int era) {
328 M_CheckYEG(year, ref era);
333 /// Overridden. Gives the number of the year of the specified
336 /// <param name="time">The
337 /// <see cref="T:System.DateTime"/> that specifies a
340 /// <returns>An integer representing the year,
341 /// starting with 1.</returns>
342 public override int GetYear(DateTime time) {
343 int rd = CCFixed.FromDateTime(time);
345 return M_EraHandler.EraYear(out era, rd);
349 /// Overridden. Tells whether the given day
352 /// <param name="year">An integer that specifies the year in the
355 /// <param name="month">An integer that specifies the month.
357 /// <param name="day">An integer that specifies the day.
359 /// <param name="era">An integer that specifies the era.
361 /// <returns>A boolean that tells whether the given day is a leap
364 /// <exception cref="T:System.ArgumentOutOfRangeException">
365 /// The exception is thrown, if the year, month, day, or era is not
368 public override bool IsLeapDay(int year, int month, int day, int era)
370 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
371 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
375 /// Overridden. Tells whether the given month
378 /// <param name="year">An integer that specifies the year in the
381 /// <param name="month">An integer that specifies the month.
383 /// <param name="era">An integer that specifies the era.
385 /// <returns>A boolean that tells whether the given month is a leap
388 /// <exception cref="T:System.ArgumentOutOfRangeException">
389 /// The exception is thrown, if the year, month, or era is not
392 public override bool IsLeapMonth(int year, int month, int era) {
393 M_CheckYMEG(year, month, ref era);
398 /// Overridden. Tells whether the given year
401 /// <param name="year">An integer that specifies the year in the
404 /// <param name="era">An integer that specifies the era.
406 /// <returns>A boolean that tells whether the given year is a leap
409 /// <exception cref="T:System.ArgumentOutOfRangeException">
410 /// The exception is thrown, if the year or era is not
413 public override bool IsLeapYear(int year, int era) {
414 int gregorianYear = M_CheckYEG(year, ref era);
415 return CCGregorianCalendar.is_leap_year(gregorianYear);
419 /// Overridden. Creates the
420 /// <see cref="T:System.DateTime"/> from the parameters.
422 /// <param name="year">An integer that gives the year in the
423 /// <paramref name="era"/>.
425 /// <param name="month">An integer that specifies the month.
427 /// <param name="day">An integer that specifies the day.
429 /// <param name="hour">An integer that specifies the hour.
431 /// <param name="minute">An integer that specifies the minute.
433 /// <param name="second">An integer that gives the second.
435 /// <param name="milliseconds">An integer that gives the
438 /// <param name="era">An integer that specifies the era.
441 /// <see cref="T:system.DateTime"/> representig the date and time.
443 /// <exception cref="T:System.ArgumentOutOfRangeException">
444 /// The exception is thrown, if at least one of the parameters
447 public override DateTime ToDateTime(int year, int month, int day,
448 int hour, int minute, int second, int milliseconds,
451 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
452 M_CheckHMSM(hour, minute, second, milliseconds);
453 return CCGregorianCalendar.ToDateTime(gregorianYear,
454 month, day, hour, minute, second, milliseconds);
458 public override int ToFourDigitYear(int year)
460 throw new NotImplementedException();
463 } // class KoreanCalendar
465 } // namespace System.Globalization