JapaneseCalendar.cs 25 KB

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