TaiwanCalendar.cs 24 KB

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