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();
62 public override int TwoDigitYearMax
65 throw new NotImplementedException();
68 throw new NotImplementedException();
73 /// A protected method checking the era number.
75 /// <param name="era">The era number as reference. It is set
76 /// to <see cref="F:CurrentEra"/>, if the input value is 0.</param>
77 /// <exception name="T:System.ArgumentException">
78 /// The exception is thrown if the era is not supported by the class.
80 internal void M_CheckEra(ref int era) {
81 if (era == CurrentEra)
83 if (!M_EraHandler.ValidEra(era))
84 throw new ArgumentException("Era value was not valid.");
88 /// A protected method checking calendar year and the era number.
90 /// <param name="year">An integer representing the calendar year.
92 /// <param name="era">The era number as reference.</param>
93 /// <exception name="T:System.ArgumentException">
94 /// The exception is thrown if the era is not supported by the class.
96 /// <exception cref="T:System.ArgumentOutOfRangeException">
97 /// The exception is thrown if the calendar year is outside of
98 /// the supported range.
100 internal int M_CheckYEG(int year, ref int era) {
102 return M_EraHandler.GregorianYear(year, era);
106 /// Checks whether the year is the era is valid, if era = CurrentEra
107 /// the right value is set.
109 /// <param name="year">The year to check.</param>
110 /// <param name="era">The era to check.</Param>
111 /// <exception cref="T:ArgumentOutOfRangeException">
112 /// The exception will be thrown, if the year is not valid.
114 internal override void M_CheckYE(int year, ref int era) {
115 M_CheckYEG(year, ref era);
119 /// A protected method checking the calendar year, month, and
122 /// <param name="year">An integer representing the calendar year.
124 /// <param name="month">An integer giving the calendar month.
126 /// <param name="era">The era number as reference.</param>
127 /// <exception name="T:System.ArgumentException">
128 /// The exception is thrown if the era is not supported by the class.
130 /// <exception cref="T:System.ArgumentOutOfRangeException">
131 /// The exception is thrown if the calendar year or month is
132 /// outside of the supported range.
134 internal int M_CheckYMEG(int year, int month, ref int era) {
135 int gregorianYear = M_CheckYEG(year, ref era);
136 if (month < 1 || month > 12)
137 throw new ArgumentOutOfRangeException("month",
138 "Month must be between one and twelve.");
139 return gregorianYear;
143 /// A protected method checking the calendar day, month, and year
144 /// and the era number.
146 /// <param name="year">An integer representing the calendar year.
148 /// <param name="month">An integer giving the calendar month.
150 /// <param name="day">An integer giving the calendar day.
152 /// <param name="era">The era number as reference.</param>
153 /// <exception name="T:System.ArgumentException">
154 /// The exception is thrown if the era is not supported by the class.
156 /// <exception cref="T:System.ArgumentOutOfRangeException">
157 /// The exception is thrown if the calendar year, month, or day is
158 /// outside of the supported range.
160 internal int M_CheckYMDEG(int year, int month, int day, ref int era)
162 int gregorianYear = M_CheckYMEG(year, month, ref era);
163 M_ArgumentInRange("day", day, 1,
164 GetDaysInMonth(year, month, era));
165 return gregorianYear;
169 /// Overrideden. Adds months to a given date.
171 /// <param name="time">The
172 /// <see cref="T:System.DateTime"/> to which to add
175 /// <param name="months">The number of months to add.</param>
176 /// <returns>A new <see cref="T:System.DateTime"/> value, that
177 /// results from adding <paramref name="months"/> to the specified
178 /// DateTime.</returns>
179 public override DateTime AddMonths(DateTime time, int months) {
180 return CCGregorianCalendar.AddMonths(time, months);
184 /// Overridden. Adds years to a given date.
186 /// <param name="time">The
187 /// <see cref="T:System.DateTime"/> to which to add
190 /// <param name="years">The number of years to add.</param>
191 /// <returns>A new <see cref="T:System.DateTime"/> value, that
192 /// results from adding <paramref name="years"/> to the specified
193 /// DateTime.</returns>
194 public override DateTime AddYears(DateTime time, int years) {
195 return CCGregorianCalendar.AddYears(time, years);
199 /// Overriden. Gets the day of the month from
200 /// <paramref name="time"/>.
202 /// <param name="time">The
203 /// <see cref="T:System.DateTime"/> that specifies a
206 /// <returns>An integer giving the day of months, starting with 1.
208 public override int GetDayOfMonth(DateTime time) {
209 return CCGregorianCalendar.GetDayOfMonth(time);
213 /// Overriden. Gets the day of the week from the specified date.
215 /// <param name="time">The
216 /// <see cref="T:System.DateTime"/> that specifies a
219 /// <returns>An integer giving the day of months, starting with 1.
221 public override DayOfWeek GetDayOfWeek(DateTime time) {
222 int rd = CCFixed.FromDateTime(time);
223 return (DayOfWeek)CCFixed.day_of_week(rd);
227 /// Overridden. Gives the number of the day in the year.
229 /// <param name="time">The
230 /// <see cref="T:System.DateTime"/> that specifies a
233 /// <returns>An integer representing the day of the year,
234 /// starting with 1.</returns>
235 public override int GetDayOfYear(DateTime time) {
236 return CCGregorianCalendar.GetDayOfYear(time);
240 /// Overridden. Gives the number of days in the specified month
241 /// of the given year and era.
243 /// <param name="year">An integer that gives the year.
245 /// <param name="month">An integer that gives the month, starting
247 /// <param name="era">An integer that gives the era of the specified
249 /// <returns>An integer that gives the number of days of the
250 /// specified month.</returns>
251 /// <exception cref="T:System.ArgumentOutOfRangeException">
252 /// The exception is thrown, if <paramref name="month"/>,
253 /// <paramref name="year"/> ,or <paramref name="era"/> is outside
254 /// the allowed range.
256 public override int GetDaysInMonth(int year, int month, int era) {
257 int gregorianYear = M_CheckYMEG(year, month, ref era);
258 return CCGregorianCalendar.GetDaysInMonth(gregorianYear, month);
262 /// Overridden. Gives the number of days of the specified
263 /// year of the given era.
265 /// <param name="year">An integer that specifies the year.
267 /// <param name="era">An ineger that specifies the era.
269 /// <returns>An integer that gives the number of days of the
270 /// specified year.</returns>
271 /// <exception cref="T:System.ArgumentOutOfRangeExceiption">
272 /// The exception is thrown, if
273 /// <paramref name="year"/> or <paramref name="era"/> are outside the
276 public override int GetDaysInYear(int year, int era) {
277 int gregorianYear = M_CheckYEG(year, ref era);
278 return CCGregorianCalendar.GetDaysInYear(gregorianYear);
282 /// Overridden. Gives the era of the specified date.
284 /// <param name="time">The
285 /// <see cref="T:System.DateTime"/> that specifies a
288 /// <returns>An integer representing the era of the calendar.
290 public override int GetEra(DateTime time) {
291 int rd = CCFixed.FromDateTime(time);
293 M_EraHandler.EraYear(out era, rd);
298 /// Overridden. Gives the number of the month of the specified
301 /// <param name="time">The
302 /// <see cref="T:System.DateTime"/> that specifies a
305 /// <returns>An integer representing the month,
306 /// starting with 1.</returns>
307 public override int GetMonth(DateTime time) {
308 return CCGregorianCalendar.GetMonth(time);
312 /// Overridden. Gives the number of months in the specified year
315 /// <param name="year">An integer that specifies the year.
317 /// <param name="era">An integer that specifies the era.
319 /// <returns>An integer that gives the number of the months in the
320 /// specified year.</returns>
321 /// <exception cref="T:System.ArgumentOutOfRangeException">
322 /// The exception is thrown, if the year or the era are not valid.
324 public override int GetMonthsInYear(int year, int era) {
325 M_CheckYEG(year, ref era);
330 /// Overridden. Gives the number of the year of the specified
333 /// <param name="time">The
334 /// <see cref="T:System.DateTime"/> that specifies a
337 /// <returns>An integer representing the year,
338 /// starting with 1.</returns>
339 public override int GetYear(DateTime time) {
340 int rd = CCFixed.FromDateTime(time);
342 return M_EraHandler.EraYear(out era, rd);
346 /// Overridden. Tells whether the given day
349 /// <param name="year">An integer that specifies the year in the
352 /// <param name="month">An integer that specifies the month.
354 /// <param name="day">An integer that specifies the day.
356 /// <param name="era">An integer that specifies the era.
358 /// <returns>A boolean that tells whether the given day is a leap
361 /// <exception cref="T:System.ArgumentOutOfRangeException">
362 /// The exception is thrown, if the year, month, day, or era is not
365 public override bool IsLeapDay(int year, int month, int day, int era)
367 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
368 return CCGregorianCalendar.IsLeapDay(gregorianYear, month, day);
372 /// Overridden. Tells whether the given month
375 /// <param name="year">An integer that specifies the year in the
378 /// <param name="month">An integer that specifies the month.
380 /// <param name="era">An integer that specifies the era.
382 /// <returns>A boolean that tells whether the given month is a leap
385 /// <exception cref="T:System.ArgumentOutOfRangeException">
386 /// The exception is thrown, if the year, month, or era is not
389 public override bool IsLeapMonth(int year, int month, int era) {
390 M_CheckYMEG(year, month, ref era);
395 /// Overridden. Tells whether the given year
398 /// <param name="year">An integer that specifies the year in the
401 /// <param name="era">An integer that specifies the era.
403 /// <returns>A boolean that tells whether the given year is a leap
406 /// <exception cref="T:System.ArgumentOutOfRangeException">
407 /// The exception is thrown, if the year or era is not
410 public override bool IsLeapYear(int year, int era) {
411 int gregorianYear = M_CheckYEG(year, ref era);
412 return CCGregorianCalendar.is_leap_year(gregorianYear);
416 /// Overridden. Creates the
417 /// <see cref="T:System.DateTime"/> from the parameters.
419 /// <param name="year">An integer that gives the year in the
420 /// <paramref name="era"/>.
422 /// <param name="month">An integer that specifies the month.
424 /// <param name="day">An integer that specifies the day.
426 /// <param name="hour">An integer that specifies the hour.
428 /// <param name="minute">An integer that specifies the minute.
430 /// <param name="second">An integer that gives the second.
432 /// <param name="milliseconds">An integer that gives the
435 /// <param name="era">An integer that specifies the era.
438 /// <see cref="T:system.DateTime"/> representig the date and time.
440 /// <exception cref="T:System.ArgumentOutOfRangeException">
441 /// The exception is thrown, if at least one of the parameters
444 public override DateTime ToDateTime(int year, int month, int day,
445 int hour, int minute, int second, int milliseconds,
448 int gregorianYear = M_CheckYMDEG(year, month, day, ref era);
449 M_CheckHMSM(hour, minute, second, milliseconds);
450 return CCGregorianCalendar.ToDateTime(gregorianYear,
451 month, day, hour, minute, second, milliseconds);
455 public override int ToFourDigitYear(int year)
457 throw new NotImplementedException();
460 } // class KoreanCalendar
462 } // namespace System.Globalization