home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 5 / RISCWORLD_VOL5.iso / SOFTWARE / Issue3 / FAMILY / Calendar / Docs / ManHTML < prev    next >
Encoding:
Text File  |  2003-09-20  |  22.4 KB  |  695 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
  2. <HTML>
  3. <!-- Generated by TechWriter Professional+ 7.11 (10-Jun-00) -->
  4. <HEAD><TITLE>ADFS::Csite.$.C.User.!Calendar.Docs.Manual</TITLE></HEAD>
  5. <BODY TEXT="#000000" BGCOLOR="#FFFFFF">
  6. <H1 ALIGN=CENTER>The Calendar Module</H1>
  7.  
  8. <P ALIGN=CENTER>
  9. <I>This module was designed to provide SWIs with which a programmer can 
  10. easily convert dates between different calendars. It's design is aimed at 
  11. historical applications such as Genealogy. Implemented calendars include 
  12. Gregorian, Hebrew, Islam, Julian and French Revolutionary. The implementation 
  13. as a module was chosen rather then a C library  because SWI calls can be used 
  14. from any implementation language, such as BASIC, Assembler and C.</I>
  15.  
  16.  
  17.  
  18. <P ALIGN=CENTER>
  19. <B>Disclaimer</B>
  20.  
  21. <P ALIGN=CENTER>
  22. This module is in no way intended to be defining any particular calendar. If 
  23. you find any errors in the results produced by this module please report them 
  24.  to me and an improved version will be made as soon as feasible.
  25.  
  26. <P ALIGN=CENTER>
  27. In fact, you are invited to test the code as much as possible in order to 
  28. find any possible errors. Please make sure the discrepancy you found is 
  29. indeed due to an error in the module and not, e.g. due to misreading of a 
  30. printed calendar.
  31.  
  32. <P ALIGN=CENTER>
  33. The implementer of this module uses the Gregorian calendar in daily life, and 
  34. all knowledge of other calendars comes from books and the Internet.
  35.  
  36. <H1 ALIGN=CENTER>1.     Purpose</H1>
  37.  
  38. <H2 ALIGN=RIGHT>Why this module</H2>
  39.  
  40. <P>
  41. This module was originally designed to do calendar calculations and 
  42. conversions for a genealogical application. When investigating your ancestry 
  43. you will quickly have to deal with dates more than a hundred years ago. Not 
  44. only must they be written down (a simple string would suffice), calculations 
  45. are also usefull. For example, you might want to put the children in a family 
  46. in chronological order of birthdate.
  47.  
  48. <P>
  49. Most programming languages and computer systems supply some kind of built-in 
  50. date manipulation system. However, they usually don't go very far back in the 
  51. past. Unix and it's derivatives, and as a result the standard C library 
  52. functions, use a counter for the number of seconds since 1970­Jan­1, 
  53. 00:00 GMT. Other systems count days from 1900­Jan­1. RISC OS 
  54. does this.
  55.  
  56. <P>
  57. Another problem is that the built-in systems usually only support the 
  58. Gregorian calendar. When dealing with history you will bump into the French 
  59. Revolutionary calendar and the Julian calendar. These will have to be 
  60. converted to and compared with the Gregorian dates.
  61.  
  62. <P>
  63. Another application is the simple printing of calendars. Here, lots of 
  64. knowledge other than a simple sequence of dates is usefull: What day of the 
  65. week is Jan­1 in a specific year? How many days in a specific month? What 
  66. weeknumber should you assign to each week. Etcetera.
  67.  
  68. <H2 ALIGN=RIGHT>What it does</H2>
  69.  
  70. <P>
  71. Once the notion is there that different calendars need to be supported, more 
  72. types are quickly added to the list, such as the Hebrew and the Islamic 
  73. calendar. If routines were to be written to convert from each calender type 
  74. to each other type, the number of combinations runs quickly out of hand. 
  75. After N calendars you need to write 2*N routines to add a single extra 
  76. calendar.
  77.  
  78. <P>
  79. To solve this, an age­old and obvious solution is used. Number the days 
  80. in history sequentially, starting at a suitable starting point. This makes 
  81. conversion of a date between two calendars an easy, two­step process. 
  82. Sorting dates chronologically becomes trivial.
  83.  
  84. <H2 ALIGN=RIGHT>What it does not</H2>
  85.  
  86. <P>
  87. Because the number of days since, say, 1­Jan­1 is already over 
  88. 730000, it was decided not to include the time of day into the system. As 
  89. seen above this would quickly limit the range of the dates that can be 
  90. calculated in a 32 bit system. This also avoids problems with the different 
  91. notions of when a day begins: at midnight, at noon, at dawn, at dusk? (Don't 
  92. laugh, these are valid methods used on a daily basis.)
  93.  
  94. <P>
  95. One thing this module definitely wants to avoid is returning strings for the 
  96. dates. This means keeping a table not only of January, February, etc, but 
  97. also of Jan, Feb, etc, with options for passing either or both. This is 
  98. needed for each calendar type. The problem is compounded by 
  99. internationalisation: each language has it's own names for the months and the 
  100. weekdays. And what about the Hebrew or Islamic calendars. The English words 
  101. for the months are just approximations. Many languages may not even their own 
  102. representation. And pretty soon someone will appreciate a Unicode version 
  103. with Hebrew or Arabic characters.
  104.  
  105. <P>
  106. And what about formatting? The user will want to pass a format string 
  107. specifying the layout.
  108.  
  109. <P>
  110. A total nightmare would be an attempt to interpret dates in strings. Coding 
  111. for that would be about 100 times more work than only handling numbers.
  112.  
  113. <H1 ALIGN=CENTER>2.     Different calendars</H1>
  114.  
  115. <H2 ALIGN=RIGHT>Which ones</H2>
  116.  
  117. <P>
  118. There are many different calendars in use in the modern day. Predominant in 
  119. the western world is the Gregorian calendar. In many parts of the world the 
  120. Islamic calendar is used. The Hebrew calendar is also current. When dealing 
  121. with historic events you may come across the Julian calendar, which preceded 
  122. the Gregorian calendar, and the French Revolutionary calendar. Today and in 
  123. the past, many other calendars are and were used.
  124.  
  125. <H2 ALIGN=RIGHT>The Julian Calendar</H2>
  126.  
  127. <P>
  128. Based on the antique Roman calendar, this system was introduced by Julius 
  129. Caesar in 46 BC. By that time they were 90 days off with the seasons. In his 
  130. honour the Roman month Quintilis was renamed to Julius. Astronomers had 
  131. determined that the solar year was 365.25 days long. To handle this, the year 
  132. was made to count 365 days and a leap day was added every four years to 
  133. Februarius, which was then the last month of the year.
  134.  
  135. <P>
  136. Application of the new calendar was in the beginning rather messy. Emperor 
  137. Augustus sorted things out. He was bestowed the same honour as Julius, and 
  138. month Sextilis was renamed to Augustus. The number of days in each month and 
  139. their names that were then laid down are still in use in the modern Gregorian 
  140. calendar. 
  141.  
  142. <P>
  143. The years were usually counted by using the year of rule of a monarch or a 
  144. pope. It was only in the 6th century AD that Dionysius Exiguus established 
  145. the notion of Anno Domini as a result calculations for future dates of Easter 
  146. he made.
  147.  
  148. <P>
  149. The Julian calendar is now fully replaced by the Gregorian calendar in the 
  150. Western world. The Greek- and Russian-Orthodox churches still use the Julian 
  151. calendar.
  152.  
  153. <H2 ALIGN=RIGHT>The Gregorian calendar</H2>
  154.  
  155. <P>
  156. This calendar was developed in the 16th century under authority of pope 
  157. Gregory XIII to resolve inaccuracies in the Julian calendar. The difference 
  158. is that no longer every year divisible by four is a leap year. Years 
  159. divisible by 100 are not leap years, except when they are divisible by 400. 
  160. This means that the year 1600 was a leap year, 1700, 1800 and 1900 were not, 
  161. but 2000 was. This calendar is expected to be accurate for at least 30000 
  162. years. 
  163.  
  164. <P>
  165. To synchronise the calendar with the seasons, March­21 was desired to 
  166. fall on the equinox. It was known that during the Council of Nicea (AD 325) 
  167. the equinox fell on that day. The number of days neccesary to compensate was 
  168. calculated to be 10. It was therefore decided to introduce the Gregorian 
  169. calendar by skipping from the 4th of October 1582 to the 15th of October. 
  170. This happened in the entire Roman Catholic world.
  171.  
  172. <P>
  173. But exactly because this calendar is a Roman Catholic invention, the change 
  174. was not immediately adopted everywhere. Protestant England and it's colonies 
  175. for instance waited until 1752. Russian-orthodox Russia held out until after 
  176. the Russian Revolution (that is why the October Revolution was always 
  177. celebrated in November in the USSR). Greek-orthodox Greece delayed until 
  178. 1923. And allthough the Greek and Russian states changed to the Gregorian 
  179. calendar, the Greek and  Russian Orthodox churches still use the Julian 
  180. calendar, for instance to calculate Easter.
  181.  
  182. <P>
  183. In some places, like the fledgeling Republic of the Netherlands, introduction 
  184. was a local matter and spread out over several decades. Often both dates were 
  185. used together in documents or the indication S.V. (stilo veteri, old style) 
  186. or S.N. (stilo novo, new style) was added.
  187.  
  188. <P>
  189. Note by the way that there is a lot more to reading dates in old documents. 
  190. For instance, in those days the year was normally taken to begin at Easter, 
  191. not on the 1st of January. So if you read "19 of February 1555" it is very 
  192. well possible that this translates to the modern 19th of February 1556, a 
  193. year later than you might expect at face value.
  194.  
  195. <P>
  196. These kinds of problems interpreting old dates however fall outside the scope 
  197. of this manual. You are referred to the literature about this subject.
  198.  
  199. <H2 ALIGN=RIGHT>The Islamic calendar</H2>
  200.  
  201. <P>
  202. (Note: My knowledge of this calendar is limited. No statement in this section 
  203. should be taken as irrefutable fact.) The Islamic calendar is a lunar 
  204. calendar, where each month follows a phase cycle of the moon. Based on the 
  205. fact that the period between two equal phases of the moon is about 29½ 
  206. days (29.53069 to be exact) the months alternatively have 29 and 30 days. The 
  207. calendar has 12 months, adding up to a year of 354 days. Because 12 actual 
  208. moon cycles make 354.36828 days, a leap day is frequently added. In the 
  209. Islamic calendar there are 11 leap years in every 30 years, making the 
  210. average year 354.36666 days long. This misses out only 1 day in about 620 
  211. Islamic years. As we are now in year 1422 the difference is no more than 2 
  212. days. Not bad for a calendar designed 1380 years ago.
  213.  
  214. <P>
  215. Note that this lunar calendar has no direct connection to the seasons, which 
  216. are related to the sun. In fact, the Islamic year is about 11 days shorter 
  217. than the Gregorian year. This means that each year the dates in the Islamic 
  218. calendar shift slightly when compared to the Gregorian calendar. It goes 
  219. round once in about every 34 solar years. This also means that 35 Islamic 
  220. years go by in 34 solar years.
  221.  
  222. <H2 ALIGN=RIGHT>The Hebrew calendar</H2>
  223.  
  224. <P>
  225. (Note: My knowledge of this calendar is limited. No statement in this section 
  226. should be taken as irrefutable fact.) The Hebrew calendar as used since 378 
  227. AD is a lunisolar calendar. This means it has months of 29 or 30 days that 
  228. keep in step with the lunar cycle, and the resulting difference of about 11 
  229. days with the solar year is compensated by adding an extra month every 7 out 
  230. of 19 years. Leap days are added for fine tuning.
  231.  
  232. <P>
  233. Although this calendar is highly accurate, it is also very complicated. Three 
  234. of the thirteen months can be either 29 or 30 days. The extra (leap) month is 
  235. added in the middle of the year. The calculation of the number of days in a 
  236. specific Hebrew year is lengthy and contortious.
  237.  
  238. <H2 ALIGN=RIGHT>The French Revolutionary calendar</H2>
  239.  
  240. <P>
  241. The French Revolution happened in the middle of the philosophical period 
  242. known as Rationalism. A clean break was made with outdated silly and 
  243. irrational institutions. They were replaced with sensible, rational things. 
  244. One of the great successes is the metric system of measurement, which does 
  245. away with such silly things as having three separate, non-compatible systems 
  246. of measuring weight, and using weight units to measure volume. One of it's 
  247. failures was the Revolutionary calendar.
  248.  
  249. <P>
  250. The year was divided into twelve months of 30 days which were given beautiful 
  251. poetic names. This gives 360 days. The remaining 5 or 6 days were added to 
  252. the end of the year as "jours complémentaires" (additional days). 
  253. While they were at it, the weeks and days were decimalised, with each month 
  254. divided into three "décades" of ten days each. A day would consist of 
  255. 10 hours of 100 minutes, with 100 seconds to the minute. (Note that this 
  256. would result in 100,000 seconds per day instead of the current 86400. The 
  257. second would have become slightly shorter.)
  258.  
  259. <P>
  260. The 10 hour day was never introduced as there were no clocks to show it and 
  261. conversion was too complicated. The months and the 10 day week were 
  262. instituted on the 5th of October 1793. The day the Republic was proclaimed, 
  263. the 22 of September 1792, also the day of the autum equinox, was chosen as 
  264. the starting point of the calendar. Note that like many other calendars the 
  265. year 1 occurs before the calendar is actually introduced.
  266.  
  267. <P>
  268. The 10 day week was abolished on the 31 of march 1802, because it hindered 
  269. the celebration of Sunday in the still very Roman Catholic France.
  270.  
  271. <P>
  272. The calendar did not last very much longer. Napoleon abolished it on the 11th 
  273. of September 1805, after it had served less than 12 years.
  274.  
  275. <P>
  276. Before that happened, France under Napoleon had conquered large parts of 
  277. Europe and introduced their calendar there. So even outside France you may 
  278. find documents dated with French Revolutionary dates.
  279.  
  280. <H1 ALIGN=CENTER>3.     How it works</H1>
  281.  
  282. <H2 ALIGN=RIGHT>Julian Day</H2>
  283.  
  284. <P>
  285. As a basis for the conversion, a unique reference number was needed for every 
  286. day in history.  As days always follow one another in an orderly fashion, it 
  287. is very unlikely that any mistakes were made in the past in counting the 
  288. days. So, as a reference, each day is given a consecutive number. This module 
  289. chooses an existing system, know as the Julian Day number. This was 
  290. introduced by Justus Scaliger in 1583. It's starting point lies in 4713 BC. 
  291. The Julian Day was chosen because it is an existing system and is in current 
  292. use, namely in astronomy.
  293.  
  294. <P>
  295. Note: in previous (pre-0.10) versions of the module the starting point was 
  296. the first day in the Gregorian calendar, the 1st of January in the year 1, 
  297. which was taken as day 1.
  298.  
  299. <H2 ALIGN=RIGHT>Conversions</H2>
  300.  
  301. <P>
  302. The module implements three SWIs.
  303.  
  304. <H2 ALIGN=RIGHT>JDayToDate</H2>
  305.  
  306. <P>
  307. The first converts from a Julian Day number to the year, month and day of a 
  308. particular calendar.
  309.  
  310. <H2 ALIGN=RIGHT>DateToJDay</H2>
  311.  
  312. <P>
  313. The second does the opposite conversion. A given triplet of year, month and 
  314. day of the month in a particular calendar is converted to a Julian Day number.
  315.  
  316. <H2 ALIGN=RIGHT>WeekToJDay</H2>
  317.  
  318. <P>
  319. The third is similar to DateToJDay, but uses year, week of the year and day 
  320. of the week as input data and converts them to a Julian Day number.
  321.  
  322. <H2 ALIGN=RIGHT>JDayToWeek</H2>
  323.  
  324. <P>
  325. This is the reverse of WeekToJDay. Given a Julian Day number it calculates 
  326. the year, week of the year and day of the week.
  327.  
  328. <H2 ALIGN=RIGHT>Calculations</H2>
  329.  
  330. <P>
  331. Calculating the Julian Day number from the date is relatively 
  332. straightforward. For example in the Gregorian calendar simply add the day of 
  333. the month to the number of days in the previous months in this year to get 
  334. the days in the given year, and then add 365 days times the number of 
  335. previous years, with corrections for leap years.
  336.  
  337. <P>
  338. The reverse is generally more difficult. As a simple solution, the code makes 
  339. an educated guess for the date and then uses the Date-To-Gregorian-Day 
  340. routine described above to see how close the guess is. In more detail it goes 
  341. like this:
  342.  
  343. <P>
  344. First a low estimate for the year is calculated by dividing the day number by 
  345. 366 (one day more than the normal number of days in  year). Then the year is 
  346. increased until the first of January of the next year has a day number that 
  347. is bigger than the one given. We now have the year.
  348.  
  349. <P>
  350. Next, the months in that year are checked in sequence until the month is 
  351. found of which the last day converts to a day number  which is equal to or 
  352. higher than the given number. We now also have the month.
  353.  
  354. <P>
  355. Finally, the day of the month is simply found by subtracting the day number 
  356. for  the first day of that month in the year we found from the given day 
  357. number and adding 1.
  358.  
  359. <H2 ALIGN=RIGHT>Input ranges</H2>
  360.  
  361. <P>
  362. The effect of this method is that every Julian Day converts to exactly one 
  363. date in a specific calendar. On the other hand, conversions from a date to a 
  364. Julian Day accept even the most outrageous values for year, month and day. 
  365. For example if 2002/1/60 (the 60th of January 2002) is given, it is correctly 
  366. converted to day number 730909. Converting back results in 2002/3/1, or the 
  367. first of March in the same year, which is indeed the 60th day in that year. 
  368. This is useful in cases where one is not certain if  a date is valid in a 
  369. specific calendar.
  370.  
  371. <H1 ALIGN=CENTER>4.     SWI Calls</H1>
  372.  
  373. <H2 ALIGN=RIGHT>General</H2>
  374.  
  375. <P>
  376. An effort has been made to keep the assignment of registers the same for all 
  377. SWIs. R0 is always used to pass the calendar type. R1 always holds the Julian 
  378. Day number, either on entry or on exit. Year, month and day values are always 
  379. in R2 upwards. This means that they don't disturb R0  or R1.
  380.  
  381. <P>
  382. The result is that converting back and forth between two calenders in 
  383. assembly becomes very easy: First call Calendar_DateToJDay with a given year, 
  384. month and day for one calendar. You then get the Julian Day number in R1. 
  385. Then set the calender type in R0 to the calendar you want to convert to, and 
  386. call the reverse function, Calendar_JDayToDate. The converted date is then in 
  387. R2-R4.
  388.  
  389. <P>
  390. Another feature that is common to all Calendar SWIs is that they are not 
  391. fussy about the date values. Silly dates like 2000/13/61 are easily converted 
  392. to the corect Julian Day number.
  393.  
  394. <H2 ALIGN=RIGHT>Errors</H2>
  395.  
  396. <P>
  397. The SWIs can return errors in the following situations:
  398.  
  399. <UL>
  400.  
  401. <LI>The calendar type is unknown in this module. The value passed in R0 is 
  402. probably wildly out of range.
  403.  
  404. <LI>The calendar type is not implemented yet. Note that early versions of the 
  405. module may not support all of the calendar types listed in this manual.
  406.  
  407. <LI>A particular SWI is not implemented for a particular calendar type.
  408.  
  409. </UL>
  410. <P>
  411. More errors may be added in future.
  412.  
  413. <H2 ALIGN=RIGHT>Calendar types</H2>
  414.  
  415. <P>
  416. The following codes are available for calendar types:
  417.  
  418. <DIV ALIGN=CENTER>
  419. <TABLE WIDTH="100%" CELLPADDING=2>
  420. <TR><TD>1
  421.  
  422. <TD>Julian
  423.  
  424. <TR><TD>2
  425.  
  426. <TD>Gregorian
  427.  
  428. <TR><TD>3
  429.  
  430. <TD>Hebrew
  431.  
  432. <TR><TD>4
  433.  
  434. <TD>Islamic
  435.  
  436. <TR><TD>5
  437.  
  438. <TD>Revolutionary (10-day weeks)
  439.  
  440. <TR><TD>6
  441.  
  442. <TD>Revolutionary (7-day weeks)
  443.  
  444. </TABLE>
  445. </DIV>
  446. <P>
  447. Some remarks:
  448.  
  449. <UL>
  450.  
  451. <LI>There is no calendar type 0. The list starts at 1.
  452.  
  453. <LI>The French Revolutionary calendar is split in two types, depending on the 
  454. use of the decimal or the normal week. For calculations which do not involve 
  455. weekdays (like JDayToDate or DateToJDay) there is no difference between the 
  456. two.
  457.  
  458. </UL>
  459. <H2 ALIGN=RIGHT>Julian Day to date</H2>
  460.  
  461. <P>
  462. <B><FONT SIZE="+2">Calendar_JDayToDate (SWI &55F80)</FONT></B>
  463.  
  464. <P>
  465. Convert a Julian Day number to a date in a specific calendar.
  466.  
  467. <P>
  468. On entry
  469.  
  470. <P>
  471.         R0 = Type of calendar
  472.  
  473. <P>
  474.         R1 = Julian Day number
  475.  
  476. <P>
  477. On exit
  478.  
  479. <P>
  480.         R0 - R1 = preserved
  481.  
  482. <P>
  483.         R2 = Year
  484.  
  485. <P>
  486.         R3 = Month
  487.  
  488. <P>
  489.         R4 = Day of the month
  490.  
  491. <P>
  492. Interrupts
  493.  
  494. <P>
  495.         Interrupt status is not altered
  496.  
  497. <P>
  498.         Fast interrupts are enabled
  499.  
  500. <P>
  501. Processor Mode
  502.  
  503. <P>
  504.         Processor is in SVC mode
  505.  
  506. <P>
  507. Re-entrancy
  508.  
  509. <P>
  510.         SWI is re-entrant
  511.  
  512. <H2 ALIGN=RIGHT>Use</H2>
  513.  
  514. <P>
  515. Calendar_JDayToDate converts a Julian Day number to the year, month and day 
  516. of the month in a specific calendar.
  517.  
  518. <H2 ALIGN=RIGHT>Date to Julian Day</H2>
  519.  
  520. <P>
  521. <B><FONT SIZE="+2">Calendar_DateToJDay (SWI &55F81)</FONT></B>
  522.  
  523. <P>
  524. On entry
  525.  
  526. <P>
  527.         R0 = Type of calendar
  528.  
  529. <P>
  530.         R1 = (unused)
  531.  
  532. <P>
  533.         R2 = Year
  534.  
  535. <P>
  536.         R3 = Month
  537.  
  538. <P>
  539.         R4 = Day of the month
  540.  
  541. <P>
  542. On exit
  543.  
  544. <P>
  545.         R0 = preserved
  546.  
  547. <P>
  548.         R1 = Julian Day number
  549.  
  550. <P>
  551.         R2 - R4 = preserved
  552.  
  553. <H2 ALIGN=RIGHT>Use</H2>
  554.  
  555. <P>
  556. Calendar_DateToJDay converts  the year, month and day of the month in a 
  557. specific calendar to the Julian Day number.
  558.  
  559. <H2 ALIGN=RIGHT>Julian Day to Week day</H2>
  560.  
  561. <P>
  562. <B><FONT SIZE="+2">Calendar_JDayToWeek</FONT></B>
  563.  
  564. <P>
  565. On entry
  566.  
  567. <P>
  568.         R0 = Type of calendar
  569.  
  570. <P>
  571.         R1 = Julian Day number
  572.  
  573. <P>
  574. On exit
  575.  
  576. <P>
  577.         R0 - R1 = preserved
  578.  
  579. <P>
  580.         R2 = Year
  581.  
  582. <P>
  583.         R3 = Week
  584.  
  585. <P>
  586.         R4 = Day of the week
  587.  
  588. <H2 ALIGN=RIGHT>Use</H2>
  589.  
  590. <P>
  591. Calendar_JDayToWeek converts a Julian Day number to the year, week of the 
  592. year and day of the week in a specific calendar. For Julian, Gregorian and 
  593. Revolutionary-7 calendars it follows the ISO 8601. This means that Monday is 
  594. counted as the first day of the week (day 1), and the first week of the year 
  595. is the week in which Jan­4 lies. For the other types of calendar we have 
  596. not enough information at the time to implement this SWI. If you have an 
  597. accurate description of the algorithm or the rules for one of them, please 
  598. send them to us.
  599.  
  600. <H2 ALIGN=RIGHT>Week to Julian Day</H2>
  601.  
  602. <P>
  603. <B><FONT SIZE="+2">Calendar_WeekToJDay</FONT></B>
  604.  
  605. <P>
  606. On entry
  607.  
  608. <P>
  609.         R0 = Type of calendar
  610.  
  611. <P>
  612.         R1 = (unused)
  613.  
  614. <P>
  615.         R2 = Year
  616.  
  617. <P>
  618.         R3 = Week of the year
  619.  
  620. <P>
  621.         R4 = Day of the week
  622.  
  623. <P>
  624. On exit
  625.  
  626. <P>
  627.         R0 = preserved
  628.  
  629. <P>
  630.         R1 = Julian Day number
  631.  
  632. <P>
  633.         R2 - R4 = preserved
  634.  
  635. <H2 ALIGN=RIGHT>Use</H2>
  636.  
  637. <P>
  638. Calendar_WeekToJDay converts a the year, week of the year and day of the week 
  639. to Julian Day number in a specific calendar. For Julian, Gregorian and 
  640. Revolutionary-7 calendars it follows the ISO 8601. This means that Monday is 
  641. counted as the first day of the week (day 1), and the first week of the year 
  642. is the week in which Jan­4 lies. For the other types of calendar we have 
  643. not enough information at the time to implement this SWI. If you have an 
  644. accurate description of the algorithm or the rules for one of them, please 
  645. send them to us.
  646.  
  647. <H2 ALIGN=RIGHT>CheckDate</H2>
  648.  
  649. <P>
  650. <B><FONT SIZE="+2">Calendar_CheckDate</FONT></B>
  651.  
  652. <P>
  653. On entry
  654.  
  655. <P>
  656.         R0 = Type of calendar
  657.  
  658. <P>
  659.         R1 = (unused)
  660.  
  661. <P>
  662.         R2 = Year
  663.  
  664. <P>
  665.         R3 = Month
  666.  
  667. <P>
  668.         R4 = Day of the month
  669.  
  670. <P>
  671. On exit
  672.  
  673. <P>
  674.         R0 - R1 = preserved
  675.  
  676. <P>
  677.         R2  >=0 if date is valid, <0 if date is not valid
  678.  
  679. <H2 ALIGN=RIGHT>Use</H2>
  680.  
  681. <P>
  682. The date given is checked to see if it is a valid date for the given 
  683. calendar. This is done by the simple method of first converting the date to a 
  684. Julian Day Number, converting it back again and then checking whether the 
  685. year, month and day of the month calculated are the same as those given. This 
  686. catches things like "April 31" and "1999 Feb 29", and also the more radical 
  687. "2000 Jan 61" or "2001-14-31". These examples are for days of the month or 
  688. months wich have too high a number, but it should also work for days of the 
  689. month or months which are zero or negative. In the Hebrew calendar it will 
  690. also catch out the less trivial case of using of the month Veadar in years 
  691. when it is not present.
  692.  
  693. </BODY>
  694. </HTML>
  695.