home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / date-33.087.lha / Date-33.087 / Amiga / M2 / txt / Date.mod < prev    next >
Encoding:
Modula Implementation  |  1994-04-13  |  101.6 KB  |  4,403 lines

  1.  IMPLEMENTATION MODULE Date; (* Copyright 1994 Kai Hofmann *)
  2.  
  3. (*
  4. ******* Date/--history-- ****************************************************
  5. *
  6. *   NAME
  7. *    history -- This is the development history of the Date module
  8. *
  9. *   VERSION
  10. *    $VER: Date 33.087 (10.04.1994)
  11. *
  12. *   HISTORY
  13. *    16.01.1994 -    Procedures: JulianLeapYear, GregorianLeapYear &
  14. *            HeisLeapYear initiated.
  15. *    22.01.1994 -    Procedures: JulianMonthDays, GregorianMonthDays,
  16. *            HeisMonthDays, JulianYearDays, GregorianYearDays,
  17. *            HeisYearDays, JulianDayDiff, GregorianDayDiff,
  18. *            HeisDayDiff, JulianDaySmaller, GregorianDaySmaller,
  19. *            HeisDaySmaller, JulianWeekday, GregorianWeekday,
  20. *            HeisWeekday, JulianDaysBeforeWeekday,
  21. *            GregorianDaysBeforeWeekday, HeisDaysBeforeWeekday,
  22. *            JulianDaysAfterWeekday, GregorianDaysAfterWeekday,
  23. *            HeisDaysAfterWeekday JulianDiffDate, FreeDate
  24. *            initiated.
  25. *            Types: Weekdays, Date, DatePtr initiated.
  26. *            Vars of Gregorian reform initiated
  27. *            (for changing to different countries)
  28. *    23.01.1994 -    Procedures: JulianDiffDate finished,
  29. *            GregorianDiffDate, HeisDiffDate, JYearToScaliger,
  30. *            GYearToScaliger, HYearToScaliger, ScaligerYearToJ,
  31. *            ScaligerYearToG, ScaligerYearToH, JSYearToJD,
  32. *            GSYearToJD, HSYearToJD, JDtoMJD, MJDtoJD, JulianToJD,
  33. *            GregorianToJD, HeisToJD, TimeToJD, JDToTime, FreeTime
  34. *            initiated.
  35. *            Types: Time, TimePtr initiated.
  36. *    28.01.1994 -    Procedures: GregorianMoonAge, MoonMonthAge,
  37. *            GregorianEaster initiated.
  38. *    30.01.1994 -    Procedures: JulianDiffDate, GregorianDiffDate,
  39. *            HeisDiffDate, JDtoTime, GregorianEaster edited
  40. *            (changing return value from ptr to VAL variables).
  41. *            Procedures: FreeDate, FreeTime deleted.
  42. *            Types: Date, DatePtr, Time, TimePtr deleted (not
  43. *            longer needed, because of the procedure changes).
  44. *            Procedures: GregorianMoonAge, GregorianEaster changed
  45. *            year parameter from CARDINAL to INTEGER (this is more
  46. *            consistent to the rest of the library).
  47. *            Bugs removed: GregorianWeekday, HeisWeekday
  48. *            (before removing, the weekday for leapyears was
  49. *            wrong)
  50. *            Procedure: GregorianEaster finished.
  51. *    30.01.1994 -    Ported to Oberon-2
  52. *    31.01.1994 -    Compiled with Oberon-2 V3.11
  53. *    12.02.1994 -    Procedures: TimeZoneFactor, LMT, TimeToSec, SecToTime
  54. *            initiated.
  55. *            Version-String installed :)
  56. *    12.02.1994 -    Starting translation to SAS C 6.51
  57. *            Date.h translated
  58. *    13.02.1994 -    Continuation of C translation
  59. *    17.02.1994 -    New Oberon-2 Port, because yesterday Daniel Armor
  60. *            gives me a little hint about the SHORT command
  61. *            (i was not knowing about this!)
  62. *    17.02.1994 -    Little bug in Autodocs removed
  63. *            making this text as Date/--history-- autodoc
  64. *    17.02.1994 -    Continuation of C translation
  65. *    18.02.1994 -    Finished with C translation
  66. *    19.02.1994 -    C bugs removed (thanx to SAS for helping a C-Lamer
  67. *            like me!), some optimizations done too.
  68. *    19.02.1994 -    Oberon-2 version compiled with V40.17 includes
  69. *    21.02.1994 -    Starting to write Modula-II testmodule
  70. *            Vars for the begining of Heis calculation initiated.
  71. *            Fixed little bugs in GregorianWeekday, HeisWeekday,
  72. *            TimeToSec, SecToTime
  73. *            Return-value of LMT changed to LONGINT!
  74. *            Converting testmodule to Oberon-2
  75. *    22.02.1994 -    Converting testmodule to C
  76. *    23.02.1994 -    I noticed, that i forgot the 3 funktions
  77. *            JulianWeek, GregorianWeek, HeisWeek
  78. *    24.02.1994 -    Initiated the 3 forgotten funktions
  79. *    26.02.1994 -    Initiating new GregorianEastern with Gauß-algorithms
  80. *            but ONLY for 1900-2099!
  81. *    27.02.1994 -    Bug fixed in JulianWeekday
  82. *            Bugs fixed in JulianDayDiff, GregorianDayDiff,
  83. *            HeisDayDiff
  84. *            JulianDayGreater, GregorianDayGreater,
  85. *            HeisDayGreater Initiated.
  86. *    02.03.1994 -    Little bug fixed in HeisdayDiff
  87. *            Bugs from 27.02. fixed in Modula-II and Oberon-2
  88. *            versions
  89. *            I found the way to extend Gregorian Easter!
  90. *            Little bug fixed in JulianWeek, GregorianWeek,
  91. *            HeisWeek (~(M2) is not !(C))
  92. *    05.03.1994 -    Some internal bugs removed
  93. *            New internal procedures GregorianSB,
  94. *            GregorianJHSB, GregorianJHStartSB!
  95. *            Extending GregorianEaster :)
  96. *    11.03.1994 -    Things from 05.03. done in Modula-II and Oberon
  97. *    12.03.1994 -    If __SASC is defined autoinitalization instead of
  98. *            _DateInit will be used!
  99. *    13.03.1994 -    After studying the SAS C Manual again i decided to
  100. *            check for __SASC_650 instead of __SASC because of
  101. *            the available of priorities!
  102. *            Setting the priority of _DateInit for
  103. *            autoinitalization to 600!
  104. *    15.03.1994 -    Making Date as library
  105. *    16.03.1994 -    Some work on the Autodocs was done
  106. *            Eleminating OldGregorianEaster by comments
  107. *            (ANSI: STOP bad standards like that there are NO
  108. *             nestedcomments possible in C!!!)
  109. *    19.03.1994 -    Some work on the Autodocs was done in the M2 Code
  110. *    20.03.1994 -    Some work on the Autodocs was done in the Oberon Code
  111. *    22.03.1994 -    In JDtoMJD, MJD to JD an L was added to the constant
  112. *            In GregorianWeekday(), HeisWeekday(),
  113. *            JulianDiffDate(), GregorianDiffDate(),
  114. *            HeisDiffDate(), JDToTime() i have inserted
  115. *            conversions (found with Borland C++ 4.0)
  116. *    24.03.1994 -    Making SunOS4.1.3, SunOS5.3(Solaris2.3) &
  117. *            RS6000 AIX3.2.? binaries with gcc
  118. *            Eliminating nested commends by inserting a space
  119. *            between / and * (i hate this ANSI C standard
  120. *            feature for commends :(
  121. *    27.03.1994 -    Adding library register assignments to the autodocs
  122. *    03.04.1994 -    Little fixes for the SAS C++ Compiler
  123. *            Little bug fixed in the M2 version of GregorianEaster
  124. *    10.04.1994 -    Changing from Shareware to Gift Ware ;-)
  125. *
  126. *****************************************************************************
  127. *
  128. *
  129. *)
  130.  
  131. (*
  132. ******* Date/--background-- *************************************************
  133. *
  134. *   NAME
  135. *    Date -- This module was designed to help calc. calendar dates (V33)
  136. *
  137. *   FUNCTION
  138. *    I now about the date routines in the Amiga-OS(TM), but i decided
  139. *    not to use them, because of their limited functionality and of
  140. *    the portability of this Module!
  141. *
  142. *   NOTES
  143. *    A tropical year is 365.2422 days! / 365d, 5h, 48min, 46sec
  144. *    A moon month is 29.53059 days! / 29d, 12h, 44min, 2.9 sec
  145. *    A moon phase is 7.38265 days!
  146. *
  147. *    (german) Books who helped me creating this:
  148. *        Kleine Naturwissenschaftliche Bibliothek, Band 23
  149. *        Ewige Kalender
  150. *        A.W. Butkewitsch & M.S. Selikson
  151. *        5. Auflage
  152. *        Teubner, Leipzig 1974
  153. *        ISBN 3-322-00393-0
  154. *
  155. *        Tag und Woche, Monat und Jahr: eine Kulturgeschichte des
  156. *        Kalenders
  157. *        Rudolf Wendorff
  158. *        Westdeutscher, Opladen 1993
  159. *        ISBN 3-531-12417-X
  160. *
  161. *        Kalender und Chronologie: Bekanntes & Unbekanntes aus der
  162. *        Kalenderwissenschaft
  163. *        Heinz Zemanek
  164. *        4. Auflage
  165. *        Oldenbourg, München 1987
  166. *        ISBN 3-486-20447-5
  167. *
  168. *        Meyers Handbuch
  169. *        über das Weltall
  170. *        Karl Schaifers & Gerhard Traving
  171. *        5. Auflage
  172. *        Bibliographisches Institut Mannheim 1973
  173. *        ISBN 3-411-00940-3
  174. *
  175. *        Meyers Handbuch
  176. *        über das Weltall
  177. *        Karl Schaifers & Gerhard Traving
  178. *        5. Auflage
  179. *        Bibliographisches Institut Mannheim 1973
  180. *        ISBN 3-411-00940-3
  181. *
  182. *    (english) Books who helped me creating this:
  183. *        Mathematical Astronomy with a Pocket Calculator
  184. *        Aubrey Jones Fras
  185. *        unknown(first) Edition
  186. *        David & Charles Newton Abbot, London 1978
  187. *        ISBN 0-7153-7675-6
  188. *
  189. *   COPYRIGHT
  190. *    This module is Copyright 1994 by Kai Hofmann - all rights reserved!
  191. *    For private use, Public Domain, Gift Ware, Freeware and Shareware
  192. *    you could use this module under following conditions:
  193. *    - You send me a little gift (money is very welcome :)
  194. *        For Bank Accocunt see below - but *ONLY* send in DM
  195. *        to this Bank Account!!!
  196. *      Other nice gifts: all Amiga hardware, and i am searching for a
  197. *      good old 1541 (C64 floppy)
  198. *    - You include a notice in your product, that you use this library
  199. *      and that it is Copyright by Kai Hofmann!
  200. *    If you want to redistribute this library read the following points:
  201. *    - Redistribution warranty is given to:
  202. *        Fred Fish for his great Amiga-Software-Library
  203. *        The german SAAR AG PD-Library
  204. *        The german AMOK PD-Library
  205. *        All public accessible INTERNET servers and PHONE boxes!
  206. *        All other who NOT take more than DM 5.- for one disk
  207. *        ALL other who NOT take more than DM 50.- for one CD
  208. *    For commercial use send me DM 200.-
  209. *    But if you are Apple or Microsoft you have to send (20000.- US$)
  210. *
  211. *   DISCLAIMER
  212. *
  213. *      THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
  214. *   APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  215. *   HOLDER AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
  216. *   OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
  217. *   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  218. *   PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  219. *   PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE
  220. *   COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
  221. *
  222. *      IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  223. *   WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY REDISTRIBUTE THE
  224. *   PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
  225. *   GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  226. *   USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS
  227. *   OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
  228. *   THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
  229. *   PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
  230. *   POSSIBILITY OF SUCH DAMAGES.
  231. *
  232. *   ADDITIONAL INFORMATIONS
  233. *    I have tried to make portable/usefull and i hope bugfree software
  234. *    for eternity - but this seems to be impossible (sorry!) :)
  235. *    So i hope YOU will pay a fee for this.
  236. *
  237. *   AUTHOR
  238. *    Kai Hofmann
  239. *    Arberger Heerstraße 92
  240. *    28307 Bremen
  241. *    Germany
  242. *    EMail: i07m@alf.zfn.uni-bremen.de
  243. *    (no phone - i hate it!)
  244. *
  245. *    Bank account : 1203 7503
  246. *    Account owner: Kai Hofmann
  247. *    Bank code    : 290 501 01
  248. *    Bank name    : Sparkasse in Bremen
  249. *    Bank address : 28307 Bremen / Germany
  250. *
  251. *****************************************************************************
  252. *
  253. *
  254. *)
  255.  (*
  256.  (*$ StackChk       := FALSE *)
  257.  (*$ RangeChk       := FALSE *)
  258.  (*$ OverflowChk    := FALSE *)
  259.  (*$ NilChk         := FALSE *)
  260.  (*$ CaseChk        := FALSE *)
  261.  (*$ ReturnChk      := FALSE *)
  262.  (*$ LargeVars      := FALSE *)
  263.  (*$ EntryClear     := TRUE  *)
  264.  (*$ Volatile       := TRUE  *)
  265.  (*$ StackParms     := TRUE  *)
  266.  (*$ CStrings       := TRUE  *)
  267.  *)
  268.  
  269.  
  270.  VAR
  271.     BeforeGregorianDay, BeforeGregorianMonth,
  272.     AfterGregorianDay, AfterGregorianMonth,
  273.     StartHeisDay, StartHeisMonth            : SHORTCARD;
  274.     BeforeGregorianYear, AfterGregorianYear,
  275.     StartHeisYear                    : INTEGER;
  276.  
  277.  (* ----------------------------------------------------------------------- *)
  278.  
  279.  PROCEDURE JulianLeapYear(year : INTEGER) : BOOLEAN;
  280.  
  281. (*
  282. ******* Date/JulianLeapYear *************************************************
  283. *
  284. *   NAME
  285. *    JulianLeapYear -- Checks if a year is a leap year for jj. (V33)
  286. *
  287. *   SYNOPSIS
  288. *    leapyear := JulianLeapYear(year);
  289. *
  290. *    PROCEDURE JulianLeapYear(year : INTEGER) : BOOLEAN;
  291. *
  292. *   FUNCTION
  293. *    JulianLeapYear checks if a year is a leap year in the julian calendar
  294. *    For years after Chr. it checks if the year is dividable by 4.
  295. *    For years before Chr. a leap year must have a modulo 4 value of 1
  296. *
  297. *   INPUTS
  298. *    year - The year which should be checked (from -32768 to 32767)
  299. *        I think only values from -7 to 1582 are valid, because of
  300. *        the variant that was done on -8 by Augustus!
  301. *
  302. *   RESULT
  303. *    leapyear - TRUE if the year is a leap year, otherwise false.
  304. *
  305. *   EXAMPLE
  306. *    ...
  307. *    IF JulianLeapYear(1994) THEN
  308. *      WriteString("leap year!");
  309. *    ELSE
  310. *      WriteString("no leap year!");
  311. *    END;
  312. *    WriteLn;
  313. *    ...
  314. *
  315. *   NOTES
  316. *    A year is 365.25 days long!
  317. *    Use this function only for values from -7 to 1582!
  318. *
  319. *   BUGS
  320. *    No known bugs.
  321. *
  322. *   SEE ALSO
  323. *    GregorianLeapYear(),HeisLeapYear()
  324. *
  325. *****************************************************************************
  326. *
  327. *
  328. *)
  329.  
  330.  BEGIN
  331.    IF year <= 0 THEN
  332.      RETURN(ABS(year) MOD 4 = 1);
  333.    ELSE    (* year > 0 *)
  334.      RETURN(year MOD 4 = 0);
  335.    END;
  336.  END JulianLeapYear;
  337.  
  338.  
  339.  PROCEDURE GregorianLeapYear(year : INTEGER) : BOOLEAN;
  340.  
  341. (*
  342. ******* Date/GregorianLeapYear **********************************************
  343. *
  344. *   NAME
  345. *    GregorianLeapYear -- Checks if a year is a leap year. (V33)
  346. *
  347. *   SYNOPSIS
  348. *    leapyear := GregorianLeapYear(year);
  349. *
  350. *    PROCEDURE GregorianLeapYear(year : INTEGER) : BOOLEAN;
  351. *
  352. *   FUNCTION
  353. *    GregorianLeapYear checks if a year is a leap year.
  354. *    For years after 1582 all years dividable by 4 are leap years,
  355. *    without years dividable by 100, but years dividable by 400
  356. *    are leap years again!
  357. *    For years before 1582 see JulianLeapYear().
  358. *
  359. *   INPUTS
  360. *    year - The year which should be checked (from -32768 to 32767)
  361. *        I think only values from -7 to 3200 are valid, because of
  362. *        the variant that was done on -8 by Augustus!
  363. *
  364. *   RESULT
  365. *    leapyear - TRUE if the year is a leap year, otherwise false.
  366. *
  367. *   EXAMPLE
  368. *    ...
  369. *    IF GregorianLeapYear(1994) THEN
  370. *      WriteString("leap year!");
  371. *    ELSE
  372. *      WriteString("no leap year!");
  373. *    END;
  374. *    WriteLn;
  375. *    ...
  376. *
  377. *   NOTES
  378. *    A year is 365.2425 days long!
  379. *    Use this function only for values from -7 to 3200!
  380. *
  381. *   BUGS
  382. *    No known bugs.
  383. *
  384. *   SEE ALSO
  385. *    JulianLeapYear(),HeisLeapYear()
  386. *
  387. *****************************************************************************
  388. *
  389. *
  390. *)
  391.  
  392.  BEGIN
  393.    IF year < BeforeGregorianYear THEN    (* Year of the Gregorian reform *)
  394.      RETURN(JulianLeapYear(year));
  395.    ELSE    (* AfterGregorianYear reform *)
  396.      RETURN((year MOD 4 = 0) AND ((year MOD 100 > 0) OR (year MOD 400 = 0)));
  397.    END;
  398.  END GregorianLeapYear;
  399.  
  400.  
  401.  PROCEDURE HeisLeapYear(year : INTEGER) : BOOLEAN;
  402.  
  403. (*
  404. ******* Date/HeisLeapYear ***************************************************
  405. *
  406. *   NAME
  407. *    HeisLeapYear -- Checks if a year is a leap year. (V33)
  408. *
  409. *   SYNOPSIS
  410. *    leapyear := HeisLeapYear(year);
  411. *
  412. *    PROCEDURE HeisLeapYear(year : INTEGER) : BOOLEAN;
  413. *
  414. *   FUNCTION
  415. *    HeisLeapYear checks if a year is a leap year.
  416. *    For years after 1582 see GregorianLeapYear(),
  417. *    The correction from N. Heis says, that all years dividable by
  418. *    3200 are no longer leap years!
  419. *    For years before 1582 see JulianLeapYear
  420. *
  421. *   INPUTS
  422. *    year - The year which should be checked (from -32768 to 32767)
  423. *        I think only values from -7 to 8000 are valid, because of
  424. *        the variant that was done on -8 by Augustus!
  425. *
  426. *   RESULT
  427. *    leapyear - TRUE if the year is a leap year, otherwise false.
  428. *
  429. *   EXAMPLE
  430. *    ...
  431. *    IF HeisLeapYear(1994) THEN
  432. *      WriteString("leap year!");
  433. *    ELSE
  434. *      WriteString("no leap year!");
  435. *    END;
  436. *    WriteLn;
  437. *    ...
  438. *
  439. *   NOTES
  440. *    A year is now 365.2421875 days!
  441. *    Use this function only for values from -7 to 8000!
  442. *
  443. *   BUGS
  444. *    No known bugs.
  445. *
  446. *   SEE ALSO
  447. *    JulianLeapYear(),GregorianLeapYear()
  448. *
  449. *****************************************************************************
  450. *
  451. *
  452. *)
  453.  
  454.  BEGIN
  455.    IF year < BeforeGregorianYear THEN    (* Year of the Gregorian reform *)
  456.      RETURN(JulianLeapYear(year));
  457.    ELSE (* year >= AfterGregorianYear *)
  458.      IF year MOD 3200 = 0 THEN    (* Correction from N. Heis *)
  459.        RETURN(FALSE);        (* (no leap year all 3200 years) *)
  460.      ELSE
  461.        RETURN(GregorianLeapYear(year));
  462.      END;
  463.    END;
  464.  END HeisLeapYear;
  465.  
  466.  (* ----------------------------------------------------------------------- *)
  467.  
  468.  PROCEDURE JulianMonthDays(month : SHORTCARD; year : INTEGER) : SHORTCARD;
  469.  
  470. (*
  471. ******* Date/JulianMonthDays ************************************************
  472. *
  473. *   NAME
  474. *    JulianMonthDays -- Gives back the number of days of a month. (V33)
  475. *
  476. *   SYNOPSIS
  477. *    days := JulianMonthDays(month,year);
  478. *
  479. *    PROCEDURE JulianMonthDays(month : SHORTCARD;
  480. *        year : INTEGER) : SHORTCARD;
  481. *
  482. *   FUNCTION
  483. *    JulianMonthDays gives you back the number of days a month in
  484. *    a specified year have.
  485. *
  486. *   INPUTS
  487. *    month - The month from wich you want to get the number of days.
  488. *    year  - The year in which the month is.
  489. *
  490. *   RESULT
  491. *    days - The number of days the month uses, or 0 if you use
  492. *        a wrong month.
  493. *
  494. *   EXAMPLE
  495. *    ...
  496. *    days := JulianMonthDays(1,1994);
  497. *    WriteString("Days of January 1994 : ");
  498. *    WriteCard(days,2); WriteLn;
  499. *    ...
  500. *
  501. *   NOTES
  502. *    Its is better only to use this function for years from -7 to 1582!
  503. *
  504. *   BUGS
  505. *    No known bugs.
  506. *
  507. *   SEE ALSO
  508. *    JulianLeapYear(),GregorianMonthDays(),HeisMonthDays()
  509. *
  510. *****************************************************************************
  511. *
  512. *
  513. *)
  514.  
  515.  BEGIN
  516.    IF month IN {1,3,5,7,8,10,12} THEN
  517.      RETURN(31);
  518.    ELSIF month IN {4,6,9,11} THEN
  519.      RETURN(30);
  520.    ELSIF (month = 2) AND JulianLeapYear(year) THEN
  521.      RETURN(29);
  522.    ELSIF (month = 2) AND (NOT JulianLeapYear(year)) THEN
  523.      RETURN(28);
  524.    ELSE (* Error - wrong month *)
  525.      RETURN(0);
  526.    END;
  527.  END JulianMonthDays;
  528.  
  529.  
  530.  PROCEDURE GregorianMonthDays(month : SHORTCARD; year : INTEGER) : SHORTCARD;
  531.  
  532. (*
  533. ******* Date/GregorianMonthDays *********************************************
  534. *
  535. *   NAME
  536. *    GregorianMonthDays -- Gives back the number of days of a month. (V33)
  537. *
  538. *   SYNOPSIS
  539. *    days := GregorianMonthDays(month,year);
  540. *
  541. *    PROCEDURE GregorianMonthDays(month : SHORTCARD;
  542. *        year : INTEGER) : SHORTCARD;
  543. *
  544. *   FUNCTION
  545. *    GregorianMonthDays gives you back the number of days a month in
  546. *    a specified year have.
  547. *    For the year 1582 and the month 10 there are only 21 days,
  548. *    because of the Gregorian-reform 10 days are delete from
  549. *    the month (for more look out for books about this!)
  550. *
  551. *   INPUTS
  552. *    month - The month from wich you want to get the number of days.
  553. *    year  - The year in which the month is.
  554. *
  555. *   RESULT
  556. *    days - The number of days the month uses, or 0 if you use
  557. *        a wrong month.
  558. *
  559. *   EXAMPLE
  560. *    ...
  561. *    days := GregorianMonthDays(1,1994);
  562. *    WriteString("Days of January 1994 : ");
  563. *    WriteCard(days,2); WriteLn;
  564. *    ...
  565. *
  566. *   NOTES
  567. *    Use this function only for years from -7 to 3200!
  568. *
  569. *   BUGS
  570. *    If the reform in a country is not in the same month an error will
  571. *    occur!
  572. *
  573. *   SEE ALSO
  574. *    GregorianLeapYear(),JulianMonthDays(),HeisMonthDays()
  575. *
  576. *****************************************************************************
  577. *
  578. *
  579. *)
  580.  
  581.  BEGIN
  582.    IF (year = AfterGregorianYear) AND (month = AfterGregorianMonth) THEN
  583.      (* 10 days canceled by Gregor XIII
  584.         in countries who chnaged later are more days *)
  585.      RETURN(31-((AfterGregorianDay-BeforeGregorianDay)-1));
  586.    ELSIF (month = 2) AND GregorianLeapYear(year) THEN
  587.      RETURN(29);
  588.    ELSIF (month = 2) AND (NOT GregorianLeapYear(year)) THEN
  589.      RETURN(28);
  590.    ELSE (* use Julian fkt for other calcs. *)
  591.      RETURN(JulianMonthDays(month,year));
  592.    END;
  593.  END GregorianMonthDays;
  594.  
  595.  
  596.  PROCEDURE HeisMonthDays(month : SHORTCARD; year : INTEGER) : SHORTCARD;
  597.  
  598. (*
  599. ******* Date/HeisMonthDays **************************************************
  600. *
  601. *   NAME
  602. *    HeisMonthDays -- Gives back the number of days of a month. (V33)
  603. *
  604. *   SYNOPSIS
  605. *    days := HeisMonthDays(month,year);
  606. *
  607. *    PROCEDURE HeisMonthDays(month : SHORTCARD;
  608. *        year : INTEGER) : SHORTCARD;
  609. *
  610. *   FUNCTION
  611. *    HeisMonthDays gives you back the number of days a month in
  612. *    a specified year have.
  613. *    For the year 1582 and the month 10 there are only 21 days,
  614. *    because of the Gregorian-reform 10 days are delete from
  615. *    the month (for more look out for books about this!)
  616. *
  617. *   INPUTS
  618. *    month - The month from wich you want to get the number of days.
  619. *    year  - The year in which the month is.
  620. *
  621. *   RESULT
  622. *    days - The number of days the month uses, or 0 if you use
  623. *        a wrong month.
  624. *
  625. *   EXAMPLE
  626. *    ...
  627. *    days := HeisMonthDays(1,1994);
  628. *    WriteString("Days of January 1994 : ");
  629. *    WriteCard(days,2); WriteLn;
  630. *    ...
  631. *
  632. *   NOTES
  633. *    Use this function only for years from -7 to 8000!
  634. *
  635. *   BUGS
  636. *    See GregorianMonthDays!
  637. *
  638. *   SEE ALSO
  639. *    HeisLeapYear(),JulianMonthDays(),GregorianMonthDays()
  640. *
  641. *****************************************************************************
  642. *
  643. *
  644. *)
  645.  
  646.  BEGIN
  647.    IF (month = 2) AND HeisLeapYear(year) THEN
  648.      RETURN(29);
  649.    ELSIF (month = 2) AND (NOT HeisLeapYear(year)) THEN
  650.      RETURN(28);
  651.    ELSE (* use Gregorian fkt for other calcs *)
  652.      RETURN(GregorianMonthDays(month,year));
  653.    END;
  654.  END HeisMonthDays;
  655.  
  656.  (* ----------------------------------------------------------------------- *)
  657.  
  658.  PROCEDURE JulianYearDays(year : INTEGER) : CARDINAL;
  659.  
  660. (*
  661. ******* Date/JulianYearDays *************************************************
  662. *
  663. *   NAME
  664. *    JulianYearDays -- Gives back the number of days in a year. (V33)
  665. *
  666. *   SYNOPSIS
  667. *    days := JulianYearDays(year);
  668. *
  669. *    PROCEDURE JulianYearDays(year : INTEGER) : CARDINAL;
  670. *
  671. *   FUNCTION
  672. *    JulianYearDays gives you back the number of days in
  673. *    a specified year.
  674. *
  675. *   INPUTS
  676. *    year  - The year in which to count the days.
  677. *
  678. *   RESULT
  679. *    days - The number of days the year uses.
  680. *
  681. *   EXAMPLE
  682. *    ...
  683. *    days := JulianYearDays(1994);
  684. *    WriteString("Days of 1994 : ");
  685. *    WriteCard(days,3); WriteLn;
  686. *    ...
  687. *
  688. *   NOTES
  689. *    Its is better only to use this function for years from -7 to 1582!
  690. *
  691. *   BUGS
  692. *    No known bugs.
  693. *
  694. *   SEE ALSO
  695. *    JulianMonthDays(),GregorianYearDays(),HeisYearDays()
  696. *
  697. *****************************************************************************
  698. *
  699. *
  700. *)
  701.  
  702.  VAR
  703.     month    : SHORTCARD;
  704.     days    : CARDINAL;
  705.  
  706.  BEGIN
  707.    days := 0;
  708.    FOR month := 1 TO 12 DO (* add the days of all 12 month *)
  709.      days := days + JulianMonthDays(month,year);
  710.    END;
  711.    RETURN(days);
  712.  END JulianYearDays;
  713.  
  714.  
  715.  PROCEDURE GregorianYearDays(year : INTEGER) : CARDINAL;
  716.  
  717. (*
  718. ******* Date/GregorianYearDays **********************************************
  719. *
  720. *   NAME
  721. *    GregorianYearDays -- Gives back the number of days in a year. (V33)
  722. *
  723. *   SYNOPSIS
  724. *    days := GregorianYearDays(year);
  725. *
  726. *    PROCEDURE GregorianYearDays(year : INTEGER) : CARDINAL;
  727. *
  728. *   FUNCTION
  729. *    GregorianYearDays gives you back the number of days in
  730. *    a specified year.
  731. *
  732. *   INPUTS
  733. *    year  - The year in which to count the days.
  734. *
  735. *   RESULT
  736. *    days - The number of days the year uses.
  737. *
  738. *   EXAMPLE
  739. *    ...
  740. *    days := GregorianYearDays(1994);
  741. *    WriteString("Days of 1994 : ");
  742. *    WriteCard(days,3); WriteLn;
  743. *    ...
  744. *
  745. *   NOTES
  746. *    Its is better only to use this function for years from -7 to 3200!
  747. *
  748. *   BUGS
  749. *    No known bugs.
  750. *
  751. *   SEE ALSO
  752. *    GregorianMonthDays(),JulianYearDays(),HeisYearDays()
  753. *
  754. *****************************************************************************
  755. *
  756. *
  757. *)
  758.  
  759.  VAR
  760.     month    : SHORTCARD;
  761.     days    : CARDINAL;
  762.  
  763.  BEGIN
  764.    days := 0;
  765.    FOR month := 1 TO 12 DO (* add the days of all 12 month *)
  766.      days := days + GregorianMonthDays(month,year);
  767.    END;
  768.    RETURN(days);
  769.  END GregorianYearDays;
  770.  
  771.  
  772.  PROCEDURE HeisYearDays(year : INTEGER) : CARDINAL;
  773.  
  774. (*
  775. ******* Date/HeisYearDays ***************************************************
  776. *
  777. *   NAME
  778. *    HeisYearDays -- Gives back the number of days in a year. (V33)
  779. *
  780. *   SYNOPSIS
  781. *    days := HeisYearDays(year);
  782. *
  783. *    PROCEDURE HeisYearDays(year : INTEGER) : CARDINAL;
  784. *
  785. *   FUNCTION
  786. *    HeisYearDays gives you back the number of days in
  787. *    a specified year.
  788. *
  789. *   INPUTS
  790. *    year  - The year in which to count the days.
  791. *
  792. *   RESULT
  793. *    days - The number of days the year uses.
  794. *
  795. *   EXAMPLE
  796. *    ...
  797. *    days := HeisYearDays(1994);
  798. *    WriteString("Days of 1994 : ");
  799. *    WriteCard(days,3); WriteLn;
  800. *    ...
  801. *
  802. *   NOTES
  803. *    Its is better only to use this function for years from -7 to 8000!
  804. *
  805. *   BUGS
  806. *    No known bugs.
  807. *
  808. *   SEE ALSO
  809. *    HeisMonthDays(),JulianYearDays(),GregorianYearDays()
  810. *
  811. *****************************************************************************
  812. *
  813. *
  814. *)
  815.  
  816.  VAR
  817.     month    : SHORTCARD;
  818.     days    : CARDINAL;
  819.  
  820.  BEGIN
  821.    days := 0;
  822.    FOR month := 1 TO 12 DO (* add the days of all 12 month *)
  823.      days := days + HeisMonthDays(month,year);
  824.    END;
  825.    RETURN(days);
  826.  END HeisYearDays;
  827.  
  828.  (* ----------------------------------------------------------------------- *)
  829.  
  830.  PROCEDURE JulianDaySmaller(day1,month1 : SHORTCARD; year1 : INTEGER;
  831.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  832.  
  833. (*
  834. ******* Date/JulianDaySmaller ***********************************************
  835. *
  836. *   NAME
  837. *    JulianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  838. *
  839. *   SYNOPSIS
  840. *    smaller := JulianDaySmaller(day1,month1,year1,day2,month2,year2);
  841. *
  842. *    PROCEDURE JulianDaySmaller(day1,month1 : SHORTCARD; year1 : INTEGER;
  843. *        day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  844. *
  845. *   FUNCTION
  846. *    JulianDaySmaller test if date1 is smaller than date2.
  847. *
  848. *   INPUTS
  849. *    day1   - day of the first date
  850. *    month1 - month of the first date
  851. *    year1  - year of the first date
  852. *    day2   - day of the second date
  853. *    month2 - month of the second month
  854. *    year2  - year of the second date
  855. *
  856. *   RESULT
  857. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  858. *
  859. *   EXAMPLE
  860. *    ...
  861. *    IF JulianDaySmaller(18,9,1970,22,1,1994) THEN
  862. *      WriteString("<"); WriteLn;
  863. *    ELSE
  864. *      WriteString(">="); WriteLn;
  865. *    END;
  866. *    ...
  867. *
  868. *   NOTES
  869. *    Its is better only to use this function for years from -7 to 1582!
  870. *
  871. *   BUGS
  872. *    No known bugs.
  873. *
  874. *   SEE ALSO
  875. *    GregorianDaySmaller(),HeisDaySmaller()
  876. *
  877. *****************************************************************************
  878. *
  879. *
  880. *)
  881.  
  882.  BEGIN
  883.    IF year1 = year2 THEN
  884.      IF month1 = month2 THEN
  885.        RETURN(day1 < day2);
  886.      ELSE
  887.        RETURN(month1 < month2);
  888.      END;
  889.    ELSE
  890.      RETURN(year1 < year2);
  891.    END;
  892.  END JulianDaySmaller;
  893.  
  894.  
  895.  PROCEDURE GregorianDaySmaller(day1,month1 : SHORTCARD; year1 : INTEGER;
  896.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  897.  
  898. (*
  899. ******* Date/GregorianDaySmaller ********************************************
  900. *
  901. *   NAME
  902. *    GregorianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  903. *
  904. *   SYNOPSIS
  905. *    smaller := GregorianDaySmaller(day1,month1,year1,day2,month2,year2);
  906. *
  907. *    PROCEDURE GregorianDaySmaller(day1,month1 : SHORTCARD;
  908. *        year1 : INTEGER; day2,month2 : SHORTCARD;
  909. *        year2 : INTEGER) : BOOLEAN;
  910. *
  911. *   FUNCTION
  912. *    GregorianDaySmaller test if date1 is smaller than date2.
  913. *
  914. *   INPUTS
  915. *    day1   - day of the first date
  916. *    month1 - month of the first date
  917. *    year1  - year of the first date
  918. *    day2   - day of the second date
  919. *    month2 - month of the second month
  920. *    year2  - year of the second date
  921. *
  922. *   RESULT
  923. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  924. *
  925. *   EXAMPLE
  926. *    ...
  927. *    IF GregorianDaySmaller(18,9,1970,22,1,1994) THEN
  928. *      WriteString("<"); WriteLn;
  929. *    ELSE
  930. *      WriteString(">="); WriteLn;
  931. *    END;
  932. *    ...
  933. *
  934. *   NOTES
  935. *    Its is better only to use this function for years from -7 to 3200!
  936. *
  937. *   BUGS
  938. *    No known bugs.
  939. *
  940. *   SEE ALSO
  941. *    JulianDaySmaller(),HeisDaySmaller()
  942. *
  943. *****************************************************************************
  944. *
  945. *
  946. *)
  947.  
  948.  BEGIN
  949.    RETURN(JulianDaySmaller(day1,month1,year1,day2,month2,year2));
  950.  END GregorianDaySmaller;
  951.  
  952.  
  953.  PROCEDURE HeisDaySmaller(day1,month1 : SHORTCARD; year1 : INTEGER;
  954.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  955.  
  956. (*
  957. ******* Date/HeisDaySmaller *************************************************
  958. *
  959. *   NAME
  960. *    HeisDaySmaller -- Checks if date1 is smaller than date2. (V33)
  961. *
  962. *   SYNOPSIS
  963. *    smaller := HeisDaySmaller(day1,month1,year1,day2,month2,year2);
  964. *
  965. *    PROCEDURE HeisDaySmaller(day1,month1 : SHORTCARD; year1 : INTEGER;
  966. *        day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  967. *
  968. *   FUNCTION
  969. *    HeisDaySmaller test if date1 is smaller than date2.
  970. *
  971. *   INPUTS
  972. *    day1   - day of the first date
  973. *    month1 - month of the first date
  974. *    year1  - year of the first date
  975. *    day2   - day of the second date
  976. *    month2 - month of the second month
  977. *    year2  - year of the second date
  978. *
  979. *   RESULT
  980. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  981. *
  982. *   EXAMPLE
  983. *    ...
  984. *    IF HeisDaySmaller(18,9,1970,22,1,1994) THEN
  985. *      WriteString("<"); WriteLn;
  986. *    ELSE
  987. *      WriteString(">="); WriteLn;
  988. *    END;
  989. *    ...
  990. *
  991. *   NOTES
  992. *    Its is better only to use this function for years from -7 to 8000!
  993. *
  994. *   BUGS
  995. *    No known bugs.
  996. *
  997. *   SEE ALSO
  998. *    JulianDaySmaller(),GregorianDaySmaller()
  999. *
  1000. *****************************************************************************
  1001. *
  1002. *
  1003. *)
  1004.  
  1005.  BEGIN
  1006.    (* To avoid bugs if differences to JulianDaySmaller was found! *)
  1007.    RETURN(GregorianDaySmaller(day1,month1,year1,day2,month2,year2));
  1008.  END HeisDaySmaller;
  1009.  
  1010.  (* ----------------------------------------------------------------------- *)
  1011.  
  1012.  PROCEDURE JulianDayGreater(day1,month1 : SHORTCARD; year1 : INTEGER;
  1013.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  1014.  
  1015. (*
  1016. ******* Date/JulianDayGreater ***********************************************
  1017. *
  1018. *   NAME
  1019. *    JulianDayGreater -- Checks if date1 is greater than date2. (V33)
  1020. *
  1021. *   SYNOPSIS
  1022. *    greater := JulianDayGreater(day1,month1,year1,day2,month2,year2);
  1023. *
  1024. *    PROCEDURE JulianDayGreater(day1,month1 : SHORTCARD; year1 : INTEGER;
  1025. *        day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  1026. *
  1027. *   FUNCTION
  1028. *    JulianDayGreater test if date1 is greater than date2.
  1029. *
  1030. *   INPUTS
  1031. *    day1   - day of the first date
  1032. *    month1 - month of the first date
  1033. *    year1  - year of the first date
  1034. *    day2   - day of the second date
  1035. *    month2 - month of the second month
  1036. *    year2  - year of the second date
  1037. *
  1038. *   RESULT
  1039. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1040. *
  1041. *   EXAMPLE
  1042. *    ...
  1043. *    IF JulianDayGreater(18,9,1970,22,1,1994) THEN
  1044. *      WriteString(">"); WriteLn;
  1045. *    ELSE
  1046. *      WriteString("<="); WriteLn;
  1047. *    END;
  1048. *    ...
  1049. *
  1050. *   NOTES
  1051. *    Its is better only to use this function for years from -7 to 1582!
  1052. *
  1053. *   BUGS
  1054. *    No known bugs.
  1055. *
  1056. *   SEE ALSO
  1057. *    GregorianDayGreater(),HeisDayGreater()
  1058. *
  1059. *****************************************************************************
  1060. *
  1061. *
  1062. *)
  1063.  
  1064.  BEGIN
  1065.    IF year1 = year2 THEN
  1066.      IF month1 = month2 THEN
  1067.        RETURN(day1 > day2);
  1068.      ELSE
  1069.        RETURN(month1 > month2);
  1070.      END;
  1071.    ELSE
  1072.      RETURN(year1 > year2);
  1073.    END;
  1074.  END JulianDayGreater;
  1075.  
  1076.  
  1077.  PROCEDURE GregorianDayGreater(day1,month1 : SHORTCARD; year1 : INTEGER;
  1078.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  1079.  
  1080. (*
  1081. ******* Date/GregorianDayGreater ********************************************
  1082. *
  1083. *   NAME
  1084. *    GregorianDayGreater -- Checks if date1 is greater than date2. (V33)
  1085. *
  1086. *   SYNOPSIS
  1087. *    greater := GregorianDayGreater(day1,month1,year1,day2,month2,year2);
  1088. *
  1089. *    PROCEDURE GregorianDayGreater(day1,month1 : SHORTCARD;
  1090. *        year1 : INTEGER; day2,month2 : SHORTCARD;
  1091. *        year2 : INTEGER) : BOOLEAN;
  1092. *
  1093. *   FUNCTION
  1094. *    GregorianDayGreater test if date1 is greater than date2.
  1095. *
  1096. *   INPUTS
  1097. *    day1   - day of the first date
  1098. *    month1 - month of the first date
  1099. *    year1  - year of the first date
  1100. *    day2   - day of the second date
  1101. *    month2 - month of the second month
  1102. *    year2  - year of the second date
  1103. *
  1104. *   RESULT
  1105. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1106. *
  1107. *   EXAMPLE
  1108. *    ...
  1109. *    IF GregorianDayGreater(18,9,1970,22,1,1994) THEN
  1110. *      WriteString(">"); WriteLn;
  1111. *    ELSE
  1112. *      WriteString("<="); WriteLn;
  1113. *    END;
  1114. *    ...
  1115. *
  1116. *   NOTES
  1117. *    Its is better only to use this function for years from -7 to 3200!
  1118. *
  1119. *   BUGS
  1120. *    No known bugs.
  1121. *
  1122. *   SEE ALSO
  1123. *    JuliandayGreater(),HeisDayGreater()
  1124. *
  1125. *****************************************************************************
  1126. *
  1127. *
  1128. *)
  1129.  
  1130.  BEGIN
  1131.    RETURN(JulianDayGreater(day1,month1,year1,day2,month2,year2));
  1132.  END GregorianDayGreater;
  1133.  
  1134.  
  1135.  PROCEDURE HeisDayGreater(day1,month1 : SHORTCARD; year1 : INTEGER;
  1136.             day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  1137.  
  1138. (*
  1139. ******* Date/HeisDayGreater *************************************************
  1140. *
  1141. *   NAME
  1142. *    HeisDayGreater -- Checks if date1 is greater than date2. (V33)
  1143. *
  1144. *   SYNOPSIS
  1145. *    greater := HeisDayGreater(day1,month1,year1,day2,month2,year2);
  1146. *
  1147. *    PROCEDURE HeisDayGreater(day1,month1 : SHORTCARD; year1 : INTEGER;
  1148. *        day2,month2 : SHORTCARD; year2 : INTEGER) : BOOLEAN;
  1149. *
  1150. *   FUNCTION
  1151. *    HeisDayGreater test if date1 is greater than date2.
  1152. *
  1153. *   INPUTS
  1154. *    day1   - day of the first date
  1155. *    month1 - month of the first date
  1156. *    year1  - year of the first date
  1157. *    day2   - day of the second date
  1158. *    month2 - month of the second month
  1159. *    year2  - year of the second date
  1160. *
  1161. *   RESULT
  1162. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1163. *
  1164. *   EXAMPLE
  1165. *    ...
  1166. *    IF HeisDayGreater(18,9,1970,22,1,1994) THEN
  1167. *      WriteString(">"); WriteLn;
  1168. *    ELSE
  1169. *      WriteString("<="); WriteLn;
  1170. *    END;
  1171. *    ...
  1172. *
  1173. *   NOTES
  1174. *    Its is better only to use this function for years from -7 to 8000!
  1175. *
  1176. *   BUGS
  1177. *    No known bugs.
  1178. *
  1179. *   SEE ALSO
  1180. *    JulianDayGreater(),GregorianDayGreater()
  1181. *
  1182. *****************************************************************************
  1183. *
  1184. *
  1185. *)
  1186.  
  1187.  BEGIN
  1188.    (* To avoid bugs if differences to JulianDayGreater was found! *)
  1189.    RETURN(GregorianDayGreater(day1,month1,year1,day2,month2,year2));
  1190.  END HeisDayGreater;
  1191.  
  1192.  (* ----------------------------------------------------------------------- *)
  1193.  
  1194.  PROCEDURE JulianDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1195.             day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1196.  
  1197. (*
  1198. ******* Date/JulianDayDiff **************************************************
  1199. *
  1200. *   NAME
  1201. *    JulianDayDiff -- Calculates the days between 2 dates. (V33)
  1202. *
  1203. *   SYNOPSIS
  1204. *    days := JulianDayDiff(day1,month1,year1,day2,month2,year2);
  1205. *
  1206. *    PROCEDURE JulianDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1207. *        day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1208. *
  1209. *   FUNCTION
  1210. *    JulianDayDiff gives you back the number of days between
  1211. *    two specified dates.
  1212. *
  1213. *   INPUTS
  1214. *    day1   - day of the first date
  1215. *    month1 - month of the first date
  1216. *    year1  - year of the first date
  1217. *    day2   - day of the second date
  1218. *    month2 - month of the second month
  1219. *    year2  - year of the second date
  1220. *
  1221. *   RESULT
  1222. *    days - The number of days between the two dates
  1223. *        (positive if date1 <= date2).
  1224. *
  1225. *   EXAMPLE
  1226. *    ...
  1227. *    days := JulianDayDiff(18,9,1970,22,1,1994);
  1228. *    WriteString("Age of Kai Hofmann in days : ");
  1229. *    WriteInt(days,10); WriteLn;
  1230. *    ...
  1231. *
  1232. *   NOTES
  1233. *    Its is better only to use this function for years from -7 to 1582!
  1234. *
  1235. *   BUGS
  1236. *    No known bugs.
  1237. *
  1238. *   SEE ALSO
  1239. *    GregorianDayDiff(),HeisDayDiff(),JulianMonthDays(),JulianYearDays()
  1240. *
  1241. *****************************************************************************
  1242. *
  1243. *
  1244. *)
  1245.  
  1246.  VAR
  1247.     t1,t2 : LONGCARD;
  1248.  
  1249.  BEGIN
  1250.    t1 := day1; (* set days left in the actual month *)
  1251.    t2 := day2;
  1252.  
  1253.    WHILE month1 > 1 DO (* calc days left by the gone month of the year1 *)
  1254.      DEC(month1);
  1255.      t1 := t1 + JulianMonthDays(month1,year1);
  1256.    END;
  1257.  
  1258.    WHILE month2 > 1 DO (* calc days left by the gone month of the year2 *)
  1259.      DEC(month2);
  1260.      t2 := t2 + JulianMonthDays(month2,year2);
  1261.    END;
  1262.  
  1263.    WHILE year1 > year2 DO (* calc days of diff years *)
  1264.      DEC(year1);
  1265.      t1 := t1 + JulianYearDays(year1);
  1266.    END;
  1267.  
  1268.    WHILE year1 < year2 DO (* calc days of diff years *)
  1269.      DEC(year2);
  1270.      t2 := t2 + JulianYearDays(year2);
  1271.    END;
  1272.  
  1273.    RETURN(LONGINT(t2)-LONGINT(t1));
  1274.  END JulianDayDiff;
  1275.  
  1276.  
  1277.  PROCEDURE GregorianDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1278.             day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1279.  
  1280. (*
  1281. ******* Date/GregorianDayDiff ***********************************************
  1282. *
  1283. *   NAME
  1284. *    GregorianDayDiff -- Calculates the days between 2 dates. (V33)
  1285. *
  1286. *   SYNOPSIS
  1287. *    days := GregorianDayDiff(day1,month1,year1,day2,month2,year2);
  1288. *
  1289. *    PROCEDURE GregorianDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1290. *        day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1291. *
  1292. *   FUNCTION
  1293. *    GregorianDayDiff gives you back the number of days between
  1294. *    two specified dates.
  1295. *
  1296. *   INPUTS
  1297. *    day1   - day of the first date
  1298. *    month1 - month of the first date
  1299. *    year1  - year of the first date
  1300. *    day2   - day of the second date
  1301. *    month2 - month of the second month
  1302. *    year2  - year of the second date
  1303. *
  1304. *   RESULT
  1305. *    days - The number of days between the two dates
  1306. *        (positive if date1 <= date2).
  1307. *
  1308. *   EXAMPLE
  1309. *    ...
  1310. *    days := GregorianDayDiff(18,9,1970,22,1,1994);
  1311. *    WriteString("Age of Kai Hofmann in days : ");
  1312. *    WriteInt(days,10); WriteLn;
  1313. *    ...
  1314. *
  1315. *   NOTES
  1316. *    Its is better only to use this function for years from -7 to 3200!
  1317. *
  1318. *   BUGS
  1319. *    If you use on of the dates 5.10.1582 to 14.10.1582 you will become
  1320. *    wrong output, because this days don't exist!
  1321. *
  1322. *   SEE ALSO
  1323. *    JulianDayDiff(),HeisDayDiff(),GregorianDaySmaller(),
  1324. *    GregorianDayGreater(),GregorianMonthDays(),GregorianYearDays()
  1325. *
  1326. *****************************************************************************
  1327. *
  1328. *
  1329. *)
  1330.  
  1331.  VAR
  1332.     t1,t2 : LONGCARD;
  1333.  
  1334.  BEGIN
  1335.    t1 := day1; (* set days left in the actual month *)
  1336.    t2 := day2;
  1337.  
  1338.    IF (year1 = 1582) AND (month1 = 10) THEN
  1339.      IF (day1 < 5) AND GregorianDaySmaller(day1,month1,year1,day2,month2,year2) AND GregorianDaySmaller(day2,month2,year2,1,11,1582) AND GregorianDayGreater(day2,month2,year2,14,10,1582) THEN
  1340.        t2 := t2 - 10;
  1341.      END;
  1342.      IF day1 > 14 THEN
  1343.        IF GregorianDaySmaller(day1,month1,year1,day2,month2,year2) AND GregorianDayGreater(day2,month2,year2,31,10,1582) THEN
  1344.          t2 := t2 +10;
  1345.        END;
  1346.        IF GregorianDayGreater(day1,month1,year1,day2,month2,year2) AND GregorianDaySmaller(day2,month2,year2,5,10,1582) THEN
  1347.          t1 := t1 -10;
  1348.        END;
  1349.      END;
  1350.    END;
  1351.  
  1352.    IF (year2 = 1582) AND (month2 = 10) AND (day2 > 14) THEN
  1353.      IF GregorianDaySmaller(day2,month2,year2,day1,month1,year1) AND GregorianDayGreater(day1,month1,year1,31,10,1582) THEN
  1354.        t1 := t1 +10;
  1355.      END;
  1356.      IF GregorianDayGreater(day2,month2,year2,day1,month1,year1) AND GregorianDaySmaller(day1,month1,year1,1,10,1582) THEN
  1357.        t2 := t2 -10;
  1358.      END;
  1359.    END;
  1360.  
  1361.    WHILE month1 > 1 DO (* calc days left by the gone month of the year1 *)
  1362.      DEC(month1);
  1363.      t1 := t1 + GregorianMonthDays(month1,year1);
  1364.    END;
  1365.  
  1366.    WHILE month2 > 1 DO (* calc days left by the gone month of the year2 *)
  1367.      DEC(month2);
  1368.      t2 := t2 + GregorianMonthDays(month2,year2);
  1369.    END;
  1370.  
  1371.    WHILE year1 > year2 DO (* calc days of diff years *)
  1372.      DEC(year1);
  1373.      t1 := t1 + GregorianYearDays(year1);
  1374.    END;
  1375.  
  1376.    WHILE year1 < year2 DO (* calc days of diff years *)
  1377.      DEC(year2);
  1378.      t2 := t2 + GregorianYearDays(year2);
  1379.    END;
  1380.  
  1381.    RETURN(LONGINT(t2)-LONGINT(t1));
  1382.  END GregorianDayDiff;
  1383.  
  1384.  
  1385.  PROCEDURE HeisDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1386.             day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1387.  
  1388. (*
  1389. ******* Date/HeisDayDiff ****************************************************
  1390. *
  1391. *   NAME
  1392. *    HeisDayDiff -- Calculates the days between 2 dates. (V33)
  1393. *
  1394. *   SYNOPSIS
  1395. *    days := HeisDayDiff(day1,month1,year1,day2,month2,year2);
  1396. *
  1397. *    PROCEDURE HeisDayDiff(day1,month1 : SHORTCARD; year1 : INTEGER;
  1398. *        day2,month2 : SHORTCARD; year2 : INTEGER) : LONGINT;
  1399. *
  1400. *   FUNCTION
  1401. *    HeisDayDiff gives you back the number of days between
  1402. *    two specified dates.
  1403. *
  1404. *   INPUTS
  1405. *    day1   - day of the first date
  1406. *    month1 - month of the first date
  1407. *    year1  - year of the first date
  1408. *    day2   - day of the second date
  1409. *    month2 - month of the second month
  1410. *    year2  - year of the second date
  1411. *
  1412. *   RESULT
  1413. *    days - The number of days between the two dates
  1414. *        (positive if date1 <= date2).
  1415. *
  1416. *   EXAMPLE
  1417. *    ...
  1418. *    days := HeisDayDiff(18,9,1970,22,1,1994);
  1419. *    WriteString("Age of Kai Hofmann in days : ");
  1420. *    WriteInt(days,10); WriteLn;
  1421. *    ...
  1422. *
  1423. *   NOTES
  1424. *    Its is better only to use this function for years from -7 to 8000!
  1425. *
  1426. *   BUGS
  1427. *    If you use on of the dates 5.10.1582 to 14.10.1582 you will become
  1428. *    wrong output, because this days don't exist!
  1429. *
  1430. *   SEE ALSO
  1431. *    JulianDayDiff(),GregorianDayDiff(),HeisDaySmaller(),HeisDayGreater(),
  1432. *    HeisMonthDays(),HeisYearDays()
  1433. *
  1434. *****************************************************************************
  1435. *
  1436. *
  1437. *)
  1438.  
  1439.  VAR
  1440.     t1,t2 : LONGCARD;
  1441.  
  1442.  BEGIN
  1443.    t1 := day1; (* set days left in the actual month *)
  1444.    t2 := day2;
  1445.  
  1446.    IF (year1 = 1582) AND (month1 = 10) THEN
  1447.      IF (day1 < 5) AND HeisDaySmaller(day1,month1,year1,day2,month2,year2) AND HeisDaySmaller(day2,month2,year2,1,11,1582) AND HeisDayGreater(day2,month2,year2,14,10,1582) THEN
  1448.        t2 := t2 - 10;
  1449.      END;
  1450.      IF day1 > 14 THEN
  1451.        IF HeisDaySmaller(day1,month1,year1,day2,month2,year2) AND HeisDayGreater(day2,month2,year2,31,10,1582) THEN
  1452.          t2 := t2 +10;
  1453.        END;
  1454.        IF HeisDayGreater(day1,month1,year1,day2,month2,year2) AND HeisDaySmaller(day2,month2,year2,5,10,1582) THEN
  1455.          t1 := t1 -10;
  1456.        END;
  1457.      END;
  1458.    END;
  1459.  
  1460.    IF (year2 = 1582) AND (month2 = 10) AND (day2 > 14) THEN
  1461.      IF HeisDaySmaller(day2,month2,year2,day1,month1,year1) AND HeisDayGreater(day1,month1,year1,31,10,1582) THEN
  1462.        t1 := t1 +10;
  1463.      END;
  1464.      IF HeisDayGreater(day2,month2,year2,day1,month1,year1) AND HeisDaySmaller(day1,month1,year1,1,10,1582) THEN
  1465.        t2 := t2 -10;
  1466.      END;
  1467.    END;
  1468.  
  1469.    WHILE month1 > 1 DO (* calc days left by the gone month of the year1 *)
  1470.      DEC(month1);
  1471.      t1 := t1 + HeisMonthDays(month1,year1);
  1472.    END;
  1473.  
  1474.    WHILE month2 > 1 DO (* calc days left by the gone month of the year2 *)
  1475.      DEC(month2);
  1476.      t2 := t2 + HeisMonthDays(month2,year2);
  1477.    END;
  1478.  
  1479.    WHILE year1 > year2 DO (* calc days of diff years *)
  1480.      DEC(year1);
  1481.      t1 := t1 + HeisYearDays(year1);
  1482.    END;
  1483.  
  1484.    WHILE year1 < year2 DO (* calc days of diff years *)
  1485.      DEC(year2);
  1486.      t2 := t2 + HeisYearDays(year2);
  1487.    END;
  1488.  
  1489.    RETURN(LONGINT(t2)-LONGINT(t1));
  1490.  END HeisDayDiff;
  1491.  
  1492.  (* ----------------------------------------------------------------------- *)
  1493.  
  1494.  PROCEDURE JulianWeekday(day,month : SHORTCARD; year : INTEGER) : Weekdays;
  1495.  
  1496. (*
  1497. ******* Date/JulianWeekday **************************************************
  1498. *
  1499. *   NAME
  1500. *    JulianWeekday -- Gets the weekday of a specified date. (V33)
  1501. *
  1502. *   SYNOPSIS
  1503. *    weekday := JulianWeekday(day,month,year);
  1504. *
  1505. *    PROCEDURE JulianWeekday(day,month : SHORTCARD;
  1506. *        year : INTEGER) : Weekday;
  1507. *
  1508. *   FUNCTION
  1509. *    JulianWeekday gets the weekday for a specified date.
  1510. *
  1511. *   INPUTS
  1512. *    day   - day of the date
  1513. *    month - month of the date
  1514. *    year  - year of the date
  1515. *
  1516. *   RESULT
  1517. *    weekday - This result is of type:
  1518. *        Weekdays := (dayerr,monday,tuesday,wednesday,thursday,freiday,
  1519. *        saturday,sunday);
  1520. *        dayerr will show you, that an error occurs!
  1521. *
  1522. *   EXAMPLE
  1523. *    ...
  1524. *    weekday := JulianWeekday(4,10,1582);
  1525. *    IF weekday = dayerr THEN
  1526. *    ...
  1527. *    END;
  1528. *    ...
  1529. *
  1530. *   NOTES
  1531. *    Its is better only to use this function for years from 0 to 1582!
  1532. *    In this version no dayerr will occur!
  1533. *
  1534. *   BUGS
  1535. *    For years < 0 errors could occur, or systemcrashs(?).
  1536. *
  1537. *   SEE ALSO
  1538. *    GregorianWeekday(),HeisWeekday()
  1539. *
  1540. *****************************************************************************
  1541. *
  1542. *
  1543. *)
  1544.  
  1545.  VAR
  1546.     decade,wday    : SHORTCARD;
  1547.  
  1548.  BEGIN
  1549.    (* January and february dates must be 13 and 14 of the year before! *)
  1550.    IF month IN {1,2} THEN
  1551.      month := 12 + month;
  1552.      DEC(year);
  1553.    END;
  1554.    decade := year - ((year DIV 100) * 100);
  1555.    (* Formula from Ch. Zeller in 1877 *)
  1556.    wday := (day + (((month+1) * 26) DIV 10) + decade + (decade DIV 4)
  1557.                     + 5 - SHORTCARD(year DIV 100)) MOD 7;
  1558.    (* Convert (1-su 2-mo 3-tu 4-we 5-th 6-fr 7/0-sa) to normal days *)
  1559.    IF wday = 0 THEN
  1560.      wday := 6;
  1561.    ELSE
  1562.      DEC(wday);
  1563.      IF wday = 0 THEN
  1564.        wday := 7;
  1565.      END;
  1566.    END;
  1567.    RETURN(Weekdays(wday));
  1568.  END JulianWeekday;
  1569.  
  1570.  
  1571.  PROCEDURE GregorianWeekday(day,month : SHORTCARD; year : INTEGER) : Weekdays;
  1572.  
  1573. (*
  1574. ******* Date/GregorianWeekday ***********************************************
  1575. *
  1576. *   NAME
  1577. *    GregorianWeekday -- Gets the weekday of a specified date. (V33)
  1578. *
  1579. *   SYNOPSIS
  1580. *    weekday := GregorianWeekday(day,month,year);
  1581. *
  1582. *    PROCEDURE GregorianWeekday(day,month : SHORTCARD;
  1583. *        year : INTEGER) : Weekday;
  1584. *
  1585. *   FUNCTION
  1586. *    GregorianWeekday gets the weekday for a specified date.
  1587. *
  1588. *   INPUTS
  1589. *    day   - day of the date
  1590. *    month - month of the date
  1591. *    year  - year of the date
  1592. *
  1593. *   RESULT
  1594. *    weekday - This result is of type:
  1595. *        Weekdays = (dayerr,monday,tuesday,wednesday,thursday,freiday,
  1596. *        saturday,sunday);
  1597. *        dayerr will show you, that an error occurs!
  1598. *
  1599. *   EXAMPLE
  1600. *    ...
  1601. *    weekday := GregorianWeekday(22,1,1994);
  1602. *    IF weekday = dayerr THEN
  1603. *    ...
  1604. *    END;
  1605. *    ...
  1606. *
  1607. *   NOTES
  1608. *    Its is better only to use this function for years from -7 to 3200!
  1609. *    In this version dayerr will only occur for the 10 lost days :)
  1610. *
  1611. *   BUGS
  1612. *    It's not possible to use years < 0 (for more see JulianWeekday()).
  1613. *
  1614. *   SEE ALSO
  1615. *    JulianWeekday(),HeisWeekday(),GregorianDaySmaller(),
  1616. *    GregorianLeapYear()
  1617. *
  1618. *****************************************************************************
  1619. *
  1620. *
  1621. *)
  1622.  
  1623.  VAR
  1624.     weekday    : Weekdays;
  1625.     wd    : CARDINAL;
  1626.  
  1627.  BEGIN
  1628.    IF GregorianDaySmaller(day,month,year,BeforeGregorianDay+1,
  1629.                 BeforeGregorianMonth,BeforeGregorianYear) THEN
  1630.      RETURN(JulianWeekday(day,month,year));
  1631.    ELSIF GregorianDaySmaller(day,month,year,AfterGregorianDay,
  1632.                 AfterGregorianMonth,AfterGregorianYear) THEN
  1633.      RETURN(dayerr);
  1634.    ELSE
  1635.      (* Formula from J. I. Perelman 1909 *)
  1636.      wd := year + (year DIV 4) - (year DIV 100) + (year DIV 400)
  1637.                 + GregorianDayDiff(1,1,year,day,month,year);
  1638.      IF GregorianLeapYear(year) THEN
  1639.        DEC(wd);
  1640.      END;
  1641.      weekday := Weekdays(wd MOD 7);
  1642.      IF weekday = dayerr THEN
  1643.        weekday := sunday;
  1644.      END;
  1645.      RETURN(weekday);
  1646.    END;
  1647.  END GregorianWeekday;
  1648.  
  1649.  
  1650.  PROCEDURE HeisWeekday(day,month : SHORTCARD; year : INTEGER) : Weekdays;
  1651.  
  1652. (*
  1653. ******* Date/HeisWeekday ****************************************************
  1654. *
  1655. *   NAME
  1656. *    HeisWeekday -- Gets the weekday of a specified date. (V33)
  1657. *
  1658. *   SYNOPSIS
  1659. *    weekday := HeisWeekday(day,month,year);
  1660. *
  1661. *    PROCEDURE HeisWeekday(day,month : SHORTCARD;
  1662. *        year : INTEGER) : Weekday;
  1663. *
  1664. *   FUNCTION
  1665. *    HeisWeekday gets the weekday for a specified date.
  1666. *
  1667. *   INPUTS
  1668. *    day   - day of the date
  1669. *    month - month of the date
  1670. *    year  - year of the date
  1671. *
  1672. *   RESULT
  1673. *    weekday - This result is of type:
  1674. *        Weekdays = (dayerr,monday,tuesday,wednesday,thursday,freiday,
  1675. *        saturday,sunday);
  1676. *        dayerr will show you, that an error occurs!
  1677. *
  1678. *   EXAMPLE
  1679. *    ...
  1680. *    weekday := HeisWeekday(22,1,1994);
  1681. *    IF weekday = dayerr THEN
  1682. *    ...
  1683. *    END;
  1684. *    ...
  1685. *
  1686. *   NOTES
  1687. *    Its is better only to use this function for years from -7 to 8000!
  1688. *    In this version dayerr will only occur for the 10 lost days :)
  1689. *
  1690. *   BUGS
  1691. *    Its not possible to use year < 0 (see JulianWeekday() for more).
  1692. *
  1693. *   SEE ALSO
  1694. *    JulianWeekday(),GregorianWeekday(),HeisDaySmaller(),HeisLeapYear(),
  1695. *    HeisDayDiff()
  1696. *
  1697. *****************************************************************************
  1698. *
  1699. *
  1700. *)
  1701.  
  1702.  VAR
  1703.     weekday    : Weekdays;
  1704.     wd    : CARDINAL;
  1705.  
  1706.  BEGIN
  1707.    IF HeisDaySmaller(day,month,year,StartHeisDay,
  1708.                 StartHeisMonth,StartHeisYear) THEN
  1709.      RETURN(GregorianWeekday(day,month,year));
  1710.    ELSE
  1711.      (* Formula from J. I. Perelman 1909 - extended for N.Heis in 01.1994
  1712.     by Kai Hofmann *)
  1713.      wd := year + (year DIV 4) - (year DIV 100) + (year DIV 400)
  1714.         - (year DIV 3200) + HeisDayDiff(1,1,year,day,month,year);
  1715.      IF HeisLeapYear(year) THEN
  1716.        DEC(wd);
  1717.      END;
  1718.      weekday := Weekdays(wd MOD 7);
  1719.      IF weekday = dayerr THEN
  1720.        weekday := sunday;
  1721.      END;
  1722.      RETURN(weekday);
  1723.    END;
  1724.  END HeisWeekday;
  1725.  
  1726.  (* ----------------------------------------------------------------------- *)
  1727.  
  1728.  PROCEDURE JulianDaysBeforeWeekday(day,month : SHORTCARD;
  1729.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1730.  
  1731. (*
  1732. ******* Date/JulianDaysBeforeWeekday ****************************************
  1733. *
  1734. *   NAME
  1735. *    JulianDaysBeforeWeekday -- Returns the diff to the wday before. (V33)
  1736. *
  1737. *   SYNOPSIS
  1738. *    days := JulianDaysBeforeWeekday(day,month,year,weekday);
  1739. *
  1740. *    PROCEDURE JulianDaysBeforeWeekday(day,month : SHORTCARD;
  1741. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1742. *
  1743. *   FUNCTION
  1744. *    Returns the days to the weekday before the specified date.
  1745. *    So if you specifie the 22.1.1994 (saturday) and thursday
  1746. *    you get back 2!
  1747. *    If you specifie the 22.1.1994 and saturday you became back 0
  1748. *    (the same day)!
  1749. *
  1750. *   INPUTS
  1751. *    day     - day of the date
  1752. *    month   - month of the date
  1753. *    year    - year of the date
  1754. *    weekday - weekday to search for building difference
  1755. *
  1756. *   RESULT
  1757. *    days - The days back to the searched weekday (0-6)
  1758. *        If you get back 8 an error occurs!
  1759. *
  1760. *   EXAMPLE
  1761. *    ...
  1762. *    days := JulianDaysBeforeWeekday(22,1,1994,thursday);
  1763. *    ...
  1764. *
  1765. *   NOTES
  1766. *    Its better to use this fkt only from -7 to 1582!
  1767. *
  1768. *   BUGS
  1769. *    See JulianWeekday()!
  1770. *
  1771. *   SEE ALSO
  1772. *    GregorianDaysBeforeWeekday(),HeisDaysBeforeWeekday(),JulianWeekday()
  1773. *
  1774. *****************************************************************************
  1775. *
  1776. *
  1777. *)
  1778.  
  1779.  VAR
  1780.     wday    : Weekdays;
  1781.  
  1782.  BEGIN
  1783.    IF weekday = dayerr THEN
  1784.      RETURN(8);
  1785.    ELSE
  1786.      wday := JulianWeekday(day,month,year);
  1787.      IF wday >= weekday THEN
  1788.        RETURN(SHORTCARD(wday)-SHORTCARD(weekday));
  1789.      ELSE (* wday < weekday *)
  1790.        RETURN(7-SHORTCARD(weekday)+SHORTCARD(wday));
  1791.      END;
  1792.    END;
  1793.  END JulianDaysBeforeWeekday;
  1794.  
  1795.  
  1796.  PROCEDURE GregorianDaysBeforeWeekday(day,month : SHORTCARD;
  1797.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1798.  
  1799. (*
  1800. ******* Date/GregorianDaysBeforeWeekday *************************************
  1801. *
  1802. *   NAME
  1803. *    GregorianDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  1804. *
  1805. *   SYNOPSIS
  1806. *    days := GregorianDaysBeforeWeekday(day,month,year,weekday);
  1807. *
  1808. *    PROCEDURE GregorianDaysBeforeWeekday(day,month : SHORTCARD;
  1809. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1810. *
  1811. *   FUNCTION
  1812. *    Returns the days to the weekday before the specified date.
  1813. *    So if you specifie the 22.1.1994 (saturday) and thursday
  1814. *    you get back 2!
  1815. *    If you specifie the 22.1.1994 and saturday you became back 0
  1816. *    (the same day)!
  1817. *
  1818. *   INPUTS
  1819. *    day     - day of the date
  1820. *    month   - month of the date
  1821. *    year    - year of the date
  1822. *    weekday - weekday to search for building difference
  1823. *
  1824. *   RESULT
  1825. *    days - The days back to the searched weekday (1-7)
  1826. *        If you get back 8 an error occurs!
  1827. *
  1828. *   EXAMPLE
  1829. *    ...
  1830. *    days := GregorianDaysBeforeWeekday(22,1,1994,thursday);
  1831. *    ...
  1832. *
  1833. *   NOTES
  1834. *    Its better to use this fkt only from -7 to 3200!
  1835. *
  1836. *   BUGS
  1837. *    See GregorianWeekday()!
  1838. *
  1839. *   SEE ALSO
  1840. *    JulianDaysBeforeWeekday(),HeisDaysBeforeWeekday(),GregorianWeekday()
  1841. *
  1842. *****************************************************************************
  1843. *
  1844. *
  1845. *)
  1846.  
  1847.  VAR
  1848.     wday    : Weekdays;
  1849.  
  1850.  BEGIN
  1851.    IF weekday = dayerr THEN
  1852.      RETURN(8);
  1853.    ELSE
  1854.      wday := GregorianWeekday(day,month,year);
  1855.      IF wday >= weekday THEN
  1856.        RETURN(SHORTCARD(wday)-SHORTCARD(weekday));
  1857.      ELSE (* wday < weekday *)
  1858.        RETURN(7-SHORTCARD(weekday)+SHORTCARD(wday));
  1859.      END;
  1860.    END;
  1861.  END GregorianDaysBeforeWeekday;
  1862.  
  1863.  
  1864.  PROCEDURE HeisDaysBeforeWeekday(day,month : SHORTCARD;
  1865.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1866.  
  1867. (*
  1868. ******* Date/HeisDaysBeforeWeekday ******************************************
  1869. *
  1870. *   NAME
  1871. *    HeisDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  1872. *
  1873. *   SYNOPSIS
  1874. *    days := HeisDaysBeforeWeekday(day,month,year,weekday);
  1875. *
  1876. *    PROCEDURE HeisDaysBeforeWeekday(day,month : SHORTCARD;
  1877. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1878. *
  1879. *   FUNCTION
  1880. *    Returns the days to the weekday before the specified date.
  1881. *    So if you specifie the 22.1.1994 (saturday) and thursday
  1882. *    you get back 2!
  1883. *    If you specifie the 22.1.1994 and saturday you became back 0
  1884. *    (the same day)!
  1885. *
  1886. *   INPUTS
  1887. *    day     - day of the date
  1888. *    month   - month of the date
  1889. *    year    - year of the date
  1890. *    weekday - weekday to search for building difference
  1891. *
  1892. *   RESULT
  1893. *    days - The days back to the searched weekday (1-7)
  1894. *        If you get back 8 an error occurs!
  1895. *
  1896. *   EXAMPLE
  1897. *    ...
  1898. *    days := HeisDaysBeforeWeekday(22,1,1994,thursday);
  1899. *    ...
  1900. *
  1901. *   NOTES
  1902. *    Its better to use this fkt only from -7 to 8000!
  1903. *
  1904. *   BUGS
  1905. *    See HeisWeekday()!
  1906. *
  1907. *   SEE ALSO
  1908. *    JulianDaysBeforeWeekday(),GregorianDaysBeforeWeekday(),HeisWeekday()
  1909. *
  1910. *****************************************************************************
  1911. *
  1912. *
  1913. *)
  1914.  
  1915.  VAR
  1916.     wday    : Weekdays;
  1917.  
  1918.  BEGIN
  1919.    IF weekday = dayerr THEN
  1920.      RETURN(8);
  1921.    ELSE
  1922.      wday := HeisWeekday(day,month,year);
  1923.      IF wday >= weekday THEN
  1924.        RETURN(SHORTCARD(wday)-SHORTCARD(weekday));
  1925.      ELSE (* wday < weekday *)
  1926.        RETURN(7-SHORTCARD(weekday)+SHORTCARD(wday));
  1927.      END;
  1928.    END;
  1929.  END HeisDaysBeforeWeekday;
  1930.  
  1931.  (* ----------------------------------------------------------------------- *)
  1932.  
  1933.  PROCEDURE JulianDaysAfterWeekday(day,month : SHORTCARD;
  1934.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1935.  
  1936. (*
  1937. ******* Date/JulianDaysAfterWeekday *****************************************
  1938. *
  1939. *   NAME
  1940. *    JulianDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  1941. *
  1942. *   SYNOPSIS
  1943. *    days := JulianDaysAfterWeekday(day,month,year,weekday);
  1944. *
  1945. *    PROCEDURE JulianDaysAfterWeekday(day,month : SHORTCARD;
  1946. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  1947. *
  1948. *   FUNCTION
  1949. *    Returns the days to the weekday after the specified date.
  1950. *    So if you specifie the 22.1.1994 (saturday) and thursday
  1951. *    you get back 5!
  1952. *    If you specifie the 22.1.1994 and saturday you became back 0
  1953. *    (the same day)!
  1954. *
  1955. *   INPUTS
  1956. *    day     - day of the date
  1957. *    month   - month of the date
  1958. *    year    - year of the date
  1959. *    weekday - weekday to search for building difference
  1960. *
  1961. *   RESULT
  1962. *    days - The days after to the searched weekday.
  1963. *
  1964. *   EXAMPLE
  1965. *    ...
  1966. *    days := JulianDaysAfterWeekday(22,1,1994,thursday);
  1967. *    ...
  1968. *
  1969. *   NOTES
  1970. *    Its better to use this fkt only from -7 to 1582!
  1971. *
  1972. *   BUGS
  1973. *    See JulianWeekday()!
  1974. *
  1975. *   SEE ALSO
  1976. *    GregorianDaysAfterWeekday(),HeisDaysAfterWeekday(),JulianWeekday()
  1977. *
  1978. *****************************************************************************
  1979. *
  1980. *
  1981. *)
  1982.  
  1983.  VAR
  1984.     wday    : Weekdays;
  1985.  
  1986.  BEGIN
  1987.    IF weekday = dayerr THEN
  1988.      RETURN(8);
  1989.    ELSE
  1990.      wday := JulianWeekday(day,month,year);
  1991.      IF wday <= weekday THEN
  1992.        RETURN(SHORTCARD(weekday)-SHORTCARD(wday));
  1993.      ELSE (* wday > weekday *)
  1994.        RETURN(7-SHORTCARD(wday)+SHORTCARD(weekday));
  1995.      END;
  1996.    END;
  1997.  END JulianDaysAfterWeekday;
  1998.  
  1999.  
  2000.  PROCEDURE GregorianDaysAfterWeekday(day,month : SHORTCARD;
  2001.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  2002.  
  2003. (*
  2004. ******* Date/GregorianDaysAfterWeekday **************************************
  2005. *
  2006. *   NAME
  2007. *    GregorianDaysAfterWeekday -- Returns the diff to wday after. (V33)
  2008. *
  2009. *   SYNOPSIS
  2010. *    days := GregorianDaysAfterWeekday(day,month,year,weekday);
  2011. *
  2012. *    PROCEDURE GregorianDaysAfterWeekday(day,month : SHORTCARD;
  2013. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  2014. *
  2015. *   FUNCTION
  2016. *    Returns the days to the weekday after the specified date.
  2017. *    So if you specifie the 22.1.1994 (saturday) and thursday
  2018. *    you get back 5!
  2019. *    If you specifie the 22.1.1994 and saturday you became back 0
  2020. *    (the same day)!
  2021. *
  2022. *   INPUTS
  2023. *    day     - day of the date
  2024. *    month   - month of the date
  2025. *    year    - year of the date
  2026. *    weekday - weekday to search for building difference
  2027. *
  2028. *   RESULT
  2029. *    days - The days after to the searched weekday.
  2030. *
  2031. *   EXAMPLE
  2032. *    ...
  2033. *    days := GregorianDaysAfterWeekday(22,1,1994,thursday);
  2034. *    ...
  2035. *
  2036. *   NOTES
  2037. *    Its better to use this fkt only from -7 to 3200!
  2038. *
  2039. *   BUGS
  2040. *    See GregorianWeekday()!
  2041. *
  2042. *   SEE ALSO
  2043. *    JulianDaysAfterWeekday(),HeisDaysAfterWeekday(),GregorianWeekday()
  2044. *
  2045. *****************************************************************************
  2046. *
  2047. *
  2048. *)
  2049.  
  2050.  VAR
  2051.     wday    : Weekdays;
  2052.  
  2053.  BEGIN
  2054.    IF weekday = dayerr THEN
  2055.      RETURN(8);
  2056.    ELSE
  2057.      wday := GregorianWeekday(day,month,year);
  2058.      IF wday <= weekday THEN
  2059.        RETURN(SHORTCARD(weekday)-SHORTCARD(wday));
  2060.      ELSE (* wday > weekday *)
  2061.        RETURN(7-SHORTCARD(wday)+SHORTCARD(weekday));
  2062.      END;
  2063.    END;
  2064.  END GregorianDaysAfterWeekday;
  2065.  
  2066.  
  2067.  PROCEDURE HeisDaysAfterWeekday(day,month : SHORTCARD;
  2068.             year : INTEGER; weekday : Weekdays) : SHORTCARD;
  2069.  
  2070. (*
  2071. ******* Date/HeisDaysAfterWeekday *******************************************
  2072. *
  2073. *   NAME
  2074. *    HeisDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  2075. *
  2076. *   SYNOPSIS
  2077. *    days := HeisDaysAfterWeekday(day,month,year,weekday);
  2078. *
  2079. *    PROCEDURE HeisDaysAfterWeekday(day,month : SHORTCARD;
  2080. *        year : INTEGER; weekday : Weekdays) : SHORTCARD;
  2081. *
  2082. *   FUNCTION
  2083. *    Returns the days to the weekday after the specified date.
  2084. *    So if you specifie the 22.1.1994 (saturday) and thursday
  2085. *    you get back 5!
  2086. *    If you specifie the 22.1.1994 and saturday you became back 0
  2087. *    (the same day)!
  2088. *
  2089. *   INPUTS
  2090. *    day     - day of the date
  2091. *    month   - month of the date
  2092. *    year    - year of the date
  2093. *    weekday - weekday to search for building difference
  2094. *
  2095. *   RESULT
  2096. *    days - The days after to the searched weekday.
  2097. *
  2098. *   EXAMPLE
  2099. *    ...
  2100. *    days := HeisDaysAfterWeekday(22,1,1994,thursday);
  2101. *    ...
  2102. *
  2103. *   NOTES
  2104. *    Its better to use this fkt only from -7 to 8000!
  2105. *
  2106. *   BUGS
  2107. *    See HeisWeekday()!
  2108. *
  2109. *   SEE ALSO
  2110. *    JulianDaysAfterWeekday(),GregorianDaysAfterWeekday(),HeisWeekday()
  2111. *
  2112. *****************************************************************************
  2113. *
  2114. *
  2115. *)
  2116.  
  2117.  VAR
  2118.     wday    : Weekdays;
  2119.  
  2120.  BEGIN
  2121.    IF weekday = dayerr THEN
  2122.      RETURN(8);
  2123.    ELSE
  2124.      wday := HeisWeekday(day,month,year);
  2125.      IF wday <= weekday THEN
  2126.        RETURN(SHORTCARD(weekday)-SHORTCARD(wday));
  2127.      ELSE (* wday > weekday *)
  2128.        RETURN(7-SHORTCARD(wday)+SHORTCARD(weekday));
  2129.      END;
  2130.    END;
  2131.  END HeisDaysAfterWeekday;
  2132.  
  2133.  (* ----------------------------------------------------------------------- *)
  2134.  
  2135.  PROCEDURE JulianDiffDate(day,month : SHORTCARD;
  2136.     year,days : INTEGER; VAR dday,dmonth : SHORTCARD; VAR dyear : INTEGER);
  2137.  
  2138. (*
  2139. ******* Date/JulianDiffDate *************************************************
  2140. *
  2141. *   NAME
  2142. *    JulianDiffDate -- Returns the date for a diff to another date. (V33)
  2143. *
  2144. *   SYNOPSIS
  2145. *    JulianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2146. *
  2147. *    PROCEDURE JulianDiffDate(day,month : SHORTCARD; year,days : INTEGER;
  2148. *        VAR dday,dmonth : SHORTCARD; VAR dyear : INTEGER);
  2149. *
  2150. *   FUNCTION
  2151. *    Returns the date wich lies diffdays before/after the specified date.
  2152. *
  2153. *   INPUTS
  2154. *    day      - day of the date
  2155. *    month    - month of the date
  2156. *    year     - year of the date
  2157. *    diffdays - difference to the date in days
  2158. *
  2159. *   RESULT
  2160. *    dday   - Destination day
  2161. *    dmonth - Destination month
  2162. *    dyear  - Destination year
  2163. *
  2164. *   EXAMPLE
  2165. *    ...
  2166. *    JulianDiffDate(23,1,1994,7,dday,dmonth,dyear);
  2167. *    ...
  2168. *
  2169. *   NOTES
  2170. *    Its better to use this fkt only from -7 to 1582!
  2171. *
  2172. *   BUGS
  2173. *    unknown.
  2174. *
  2175. *   SEE ALSO
  2176. *    GregorianDiffDate(),HeisDiffDate(),JulianDayDiff()
  2177. *
  2178. *****************************************************************************
  2179. *
  2180. *
  2181. *)
  2182.  
  2183.  VAR
  2184.     ddays    : INTEGER;
  2185.  
  2186.  BEGIN
  2187.    dday := day;
  2188.    dmonth := month;
  2189.    dyear := year;
  2190.    IF days >= 0 THEN (* add *)
  2191.      ddays := JulianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2192.      WHILE days >= ddays DO (* years *)
  2193.        dday := 1;
  2194.        dmonth := 1;
  2195.        INC(dyear);
  2196.        days := days - ddays;
  2197.        ddays := JulianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2198.      END;
  2199.      ddays := JulianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2200.      WHILE days >= ddays DO (* months *)
  2201.        dday := 1;
  2202.        INC(dmonth);
  2203.        days := days - ddays;
  2204.        ddays := JulianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2205.      END;
  2206.      IF days > 0 THEN (* days *)
  2207.        dday := dday + SHORTCARD(days);
  2208.      END;
  2209.    ELSE (* sub *)
  2210.      ddays := JulianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2211.      WHILE days <= ddays DO (* years *)
  2212.        dday := 31;
  2213.        dmonth := 12;
  2214.        DEC(dyear);
  2215.        days := days - ddays;
  2216.        ddays := JulianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2217.      END;
  2218.      ddays := JulianDayDiff(dday,dmonth,dyear,JulianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2219.      WHILE days <= ddays DO (* months *)
  2220.        dday := JulianMonthDays(dmonth-1,dyear);
  2221.        DEC(dmonth);
  2222.        days := days - ddays;
  2223.        ddays := JulianDayDiff(dday,dmonth,dyear,JulianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2224.      END;
  2225.      IF days < 0 THEN
  2226.        dday := dday - SHORTCARD(ABS(days));
  2227.      END;
  2228.    END;
  2229.  END JulianDiffDate;
  2230.  
  2231.  
  2232.  PROCEDURE GregorianDiffDate(day,month : SHORTCARD;
  2233.     year,days : INTEGER; VAR dday,dmonth : SHORTCARD; VAR dyear : INTEGER);
  2234.  
  2235. (*
  2236. ******* Date/GregorianDiffDate **********************************************
  2237. *
  2238. *   NAME
  2239. *    GregorianDiffDate -- Returns the diff date to another date. (V33)
  2240. *
  2241. *   SYNOPSIS
  2242. *    GregorianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2243. *
  2244. *    PROCEDURE GregorianDiffDate(day,month : SHORTCARD;
  2245. *        year,days : INTEGER; VAR dday,dmonth : SHORTCARD;
  2246. *        VAR dyear : INTEGER);
  2247. *
  2248. *   FUNCTION
  2249. *    Returns the date wich lies diffdays before/after the specified date.
  2250. *
  2251. *   INPUTS
  2252. *    day      - day of the date
  2253. *    month    - month of the date
  2254. *    year     - year of the date
  2255. *    diffdays - difference to the date in days
  2256. *
  2257. *   RESULT
  2258. *    dday   - Destination day
  2259. *    dmonth - Destination month
  2260. *    dyear  - Destination year
  2261. *
  2262. *   EXAMPLE
  2263. *    ...
  2264. *    GregorianDiffDate(23,1,1994,7,dday,dmonth,dyear);
  2265. *    ...
  2266. *
  2267. *   NOTES
  2268. *    Its better to use this fkt only from -7 to 3200!
  2269. *
  2270. *   BUGS
  2271. *    unknown.
  2272. *
  2273. *   SEE ALSO
  2274. *    GregorianDayDiff(),JulianDiffDate(),HeisDiffDate()
  2275. *
  2276. *****************************************************************************
  2277. *
  2278. *
  2279. *)
  2280.  
  2281.  VAR
  2282.     ddays    : INTEGER;
  2283.  
  2284.  BEGIN
  2285.    dday := day;
  2286.    dmonth := month;
  2287.    dyear := year;
  2288.    IF days >= 0 THEN (* add *)
  2289.      ddays := GregorianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2290.      WHILE days >= ddays DO (* years *)
  2291.        dday := 1;
  2292.        dmonth := 1;
  2293.        INC(dyear);
  2294.        days := days - ddays;
  2295.        ddays := GregorianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2296.      END;
  2297.      ddays := GregorianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2298.      WHILE days >= ddays DO (* months *)
  2299.        dday := 1;
  2300.        INC(dmonth);
  2301.        days := days - ddays;
  2302.        ddays := GregorianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2303.      END;
  2304.      IF days > 0 THEN (* days *)
  2305.        dday := dday + SHORTCARD(days);
  2306.      END;
  2307.    ELSE (* sub *)
  2308.      ddays := GregorianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2309.      WHILE days <= ddays DO (* years *)
  2310.        dday := 31;
  2311.        dmonth := 12;
  2312.        DEC(dyear);
  2313.        days := days - ddays;
  2314.        ddays := GregorianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2315.      END;
  2316.      ddays := GregorianDayDiff(dday,dmonth,dyear,GregorianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2317.      WHILE days <= ddays DO (* months *)
  2318.        dday := GregorianMonthDays(dmonth-1,dyear);
  2319.        DEC(dmonth);
  2320.        days := days - ddays;
  2321.        ddays := GregorianDayDiff(dday,dmonth,dyear,GregorianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2322.      END;
  2323.      IF days < 0 THEN
  2324.        dday := dday - SHORTCARD(ABS(days));
  2325.      END;
  2326.    END;
  2327.  END GregorianDiffDate;
  2328.  
  2329.  
  2330.  PROCEDURE HeisDiffDate(day,month : SHORTCARD; year,days : INTEGER;
  2331.             VAR dday,dmonth : SHORTCARD; VAR dyear : INTEGER);
  2332.  
  2333. (*
  2334. ******* Date/HeisDiffDate ***************************************************
  2335. *
  2336. *   NAME
  2337. *    HeisDiffDate -- Returns the date for a diff to another date. (V33)
  2338. *
  2339. *   SYNOPSIS
  2340. *    HeisDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2341. *
  2342. *    PROCEDURE HeisDiffDate(day,month : SHORTCARD; year,days : INTEGER;
  2343. *         VAR dday,dmonth : SHORTCARD; VAR dyear : INTEGER);
  2344. *
  2345. *   FUNCTION
  2346. *    Returns the date wich lies diffdays before/after the specified date.
  2347. *
  2348. *   INPUTS
  2349. *    day      - day of the date
  2350. *    month    - month of the date
  2351. *    year     - year of the date
  2352. *    diffdays - difference to the date in days
  2353. *
  2354. *   RESULT
  2355. *    dday   - Destination day
  2356. *    dmonth - Destination month
  2357. *    dyear  - Destination year
  2358. *
  2359. *   EXAMPLE
  2360. *    ...
  2361. *    HeisDiffDate(23,1,1994,7,dday,dmonth,dyear);
  2362. *    ...
  2363. *
  2364. *   NOTES
  2365. *    Its better to use this fkt only from -7 to 8000!
  2366. *
  2367. *   BUGS
  2368. *    unknown.
  2369. *
  2370. *   SEE ALSO
  2371. *    HeisDayDiff(),JulianDiffDate(),GregorianDiffDate()
  2372. *
  2373. *****************************************************************************
  2374. *
  2375. *
  2376. *)
  2377.  
  2378.  VAR
  2379.     ddays    : INTEGER;
  2380.  
  2381.  BEGIN
  2382.    dday := day;
  2383.    dmonth := month;
  2384.    dyear := year;
  2385.    IF days >= 0 THEN (* add *)
  2386.      ddays := HeisDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2387.      WHILE days >= ddays DO (* years *)
  2388.        dday := 1;
  2389.        dmonth := 1;
  2390.        INC(dyear);
  2391.        days := days - ddays;
  2392.        ddays := HeisDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2393.      END;
  2394.      ddays := HeisDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2395.      WHILE days >= ddays DO (* months *)
  2396.        dday := 1;
  2397.        INC(dmonth);
  2398.        days := days - ddays;
  2399.        ddays := HeisDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2400.      END;
  2401.      IF days > 0 THEN (* days *)
  2402.        dday := dday + SHORTCARD(days);
  2403.      END;
  2404.    ELSE (* sub *)
  2405.      ddays := HeisDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2406.      WHILE days <= ddays DO (* years *)
  2407.        dday := 31;
  2408.        dmonth := 12;
  2409.        DEC(dyear);
  2410.        days := days - ddays;
  2411.        ddays := HeisDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2412.      END;
  2413.      ddays := HeisDayDiff(dday,dmonth,dyear,HeisMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2414.      WHILE days <= ddays DO (* months *)
  2415.        dday := HeisMonthDays(dmonth-1,dyear);
  2416.        DEC(dmonth);
  2417.        days := days - ddays;
  2418.        ddays := HeisDayDiff(dday,dmonth,dyear,HeisMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2419.      END;
  2420.      IF days < 0 THEN
  2421.        dday := dday - SHORTCARD(ABS(days));
  2422.      END;
  2423.    END;
  2424.  END HeisDiffDate;
  2425.  
  2426.  (* ----------------------------------------------------------------------- *)
  2427.  
  2428.  PROCEDURE JYearToScaliger(year : INTEGER) : CARDINAL;
  2429.  
  2430. (*
  2431. ******* Date/JYearToScaliger ************************************************
  2432. *
  2433. *   NAME
  2434. *    JYearToScaliger -- Returns the year as Scaliger year. (V33)
  2435. *
  2436. *   SYNOPSIS
  2437. *    syear := JYearToScaliger(year);
  2438. *
  2439. *    PROCEDURE JYearToScaliger(year : INTEGER) : CARDINAL;
  2440. *
  2441. *   FUNCTION
  2442. *    Returns the Scaliger year.
  2443. *
  2444. *   INPUTS
  2445. *    year     - Julian year
  2446. *
  2447. *   RESULT
  2448. *    syear - The Scaliger year
  2449. *
  2450. *   EXAMPLE
  2451. *    ...
  2452. *    syear := JYearToScaliger(1582);
  2453. *    ...
  2454. *
  2455. *   NOTES
  2456. *    Its better to use this fkt only from -7 to 1582!
  2457. *
  2458. *   BUGS
  2459. *    unknown.
  2460. *
  2461. *   SEE ALSO
  2462. *    GYearToScaliger(),HYearToScaliger()
  2463. *
  2464. *****************************************************************************
  2465. *
  2466. *
  2467. *)
  2468.  
  2469.  BEGIN
  2470.    IF (year < 0) AND (year > -4714) THEN
  2471.      RETURN(4714+year);
  2472.    ELSIF (year > 0) AND (year < 3268) THEN
  2473.      RETURN(4713+year);
  2474.    ELSE
  2475.      RETURN(0);
  2476.    END;
  2477.  END JYearToScaliger;
  2478.  
  2479.  
  2480.  PROCEDURE GYearToScaliger(year : INTEGER) : CARDINAL;
  2481.  
  2482. (*
  2483. ******* Date/GYearToScaliger ************************************************
  2484. *
  2485. *   NAME
  2486. *    GYearToScaliger -- Returns the year as Scaliger year. (V33)
  2487. *
  2488. *   SYNOPSIS
  2489. *    syear := GYearToScaliger(year);
  2490. *
  2491. *    PROCEDURE GYearToScaliger(year : INTEGER) : CARDINAL;
  2492. *
  2493. *   FUNCTION
  2494. *    Returns the Scaliger year.
  2495. *
  2496. *   INPUTS
  2497. *    year     - Gregorian year
  2498. *
  2499. *   RESULT
  2500. *    syear - The Scaliger year
  2501. *
  2502. *   EXAMPLE
  2503. *    ...
  2504. *    syear := GYearToScaliger(1994);
  2505. *    ...
  2506. *
  2507. *   NOTES
  2508. *    Its better to use this fkt only from -7 to 3200!
  2509. *
  2510. *   BUGS
  2511. *    unknown.
  2512. *
  2513. *   SEE ALSO
  2514. *    JYearToScaliger(),HYearToScaliger()
  2515. *
  2516. *****************************************************************************
  2517. *
  2518. *
  2519. *)
  2520.  
  2521.  BEGIN
  2522.    (* if other calcs are better use here! *)
  2523.    RETURN(JYearToScaliger(year));
  2524.  END GYearToScaliger;
  2525.  
  2526.  
  2527.  PROCEDURE HYearToScaliger(year : INTEGER) : CARDINAL;
  2528.  
  2529. (*
  2530. ******* Date/HYearToScaliger ************************************************
  2531. *
  2532. *   NAME
  2533. *    HYearToScaliger -- Returns the year as Scaliger year. (V33)
  2534. *
  2535. *   SYNOPSIS
  2536. *    syear := HYearToScaliger(year);
  2537. *
  2538. *    PROCEDURE HYearToScaliger(year : INTEGER) : CARDINAL;
  2539. *
  2540. *   FUNCTION
  2541. *    Returns the Scaliger year.
  2542. *
  2543. *   INPUTS
  2544. *    year     - Heis year
  2545. *
  2546. *   RESULT
  2547. *    syear - The Scaliger year
  2548. *
  2549. *   EXAMPLE
  2550. *    ...
  2551. *    syear := HYearToScaliger(1994);
  2552. *    ...
  2553. *
  2554. *   NOTES
  2555. *    Its better to use this fkt only from -7 to 8000!
  2556. *
  2557. *   BUGS
  2558. *    The Scaliger period is defined to 3268!!!.
  2559. *
  2560. *   SEE ALSO
  2561. *    JYearToScaliger(),GYearToScliger()
  2562. *
  2563. *****************************************************************************
  2564. *
  2565. *
  2566. *)
  2567.  
  2568.  BEGIN
  2569.    (* for compatiblities if GYearToScaliger will be changed *)
  2570.    RETURN(GYearToScaliger(year));
  2571.  END HYearToScaliger;
  2572.  
  2573.  (* ----------------------------------------------------------------------- *)
  2574.  
  2575.  PROCEDURE ScaligerYearToJ(syear : CARDINAL) : INTEGER;
  2576.  
  2577. (*
  2578. ******* Date/ScaligerYearToJ ************************************************
  2579. *
  2580. *   NAME
  2581. *    ScaligerYearToJ -- Returns the Scaliger year as Julian year. (V33)
  2582. *
  2583. *   SYNOPSIS
  2584. *    year := ScaligerYearToJ(syear);
  2585. *
  2586. *    PROCEDURE ScaligerYearToJ(syear : CARDINAL) : INTEGER;
  2587. *
  2588. *   FUNCTION
  2589. *    Returns the Julian year of a Scaliger year.
  2590. *
  2591. *   INPUTS
  2592. *    syear     - Scaliger year
  2593. *
  2594. *   RESULT
  2595. *    year - The Julian year
  2596. *
  2597. *   EXAMPLE
  2598. *    ...
  2599. *    year := ScaligerYearToJ(4800);
  2600. *    ...
  2601. *
  2602. *   NOTES
  2603. *    Its better to use this fkt only from 4707 to 6295!
  2604. *
  2605. *   BUGS
  2606. *    unknown.
  2607. *
  2608. *   SEE ALSO
  2609. *    ScaligerYearToG(),ScaligerYearToH()
  2610. *
  2611. *****************************************************************************
  2612. *
  2613. *
  2614. *)
  2615.  
  2616.  BEGIN
  2617.    IF (syear < 4714) THEN
  2618.      RETURN(4714+syear);
  2619.    ELSE
  2620.      RETURN(syear-4713);
  2621.    END;
  2622.  END ScaligerYearToJ;
  2623.  
  2624.  
  2625.  PROCEDURE ScaligerYearToG(syear : CARDINAL) : INTEGER;
  2626.  
  2627. (*
  2628. ******* Date/ScaligerYearToG ************************************************
  2629. *
  2630. *   NAME
  2631. *    ScaligerYearToG -- Returns the Scaliger year as Gregorian year. (V33)
  2632. *
  2633. *   SYNOPSIS
  2634. *    year := ScaligerYearToG(syear);
  2635. *
  2636. *    PROCEDURE ScaligerYearToG(syear : CARDINAL) : INTEGER;
  2637. *
  2638. *   FUNCTION
  2639. *    Returns the Gregorian year of a Scaliger year.
  2640. *
  2641. *   INPUTS
  2642. *    syear     - Scaliger year
  2643. *
  2644. *   RESULT
  2645. *    year - The Gregorian year
  2646. *
  2647. *   EXAMPLE
  2648. *    ...
  2649. *    year := ScaligerYearToG(6400);
  2650. *    ...
  2651. *
  2652. *   NOTES
  2653. *    Its better to use this fkt only from 4707 to 7981!
  2654. *
  2655. *   BUGS
  2656. *    unknown.
  2657. *
  2658. *   SEE ALSO
  2659. *    ScaligerYearToJ(),ScaligerYearToH()
  2660. *
  2661. *****************************************************************************
  2662. *
  2663. *
  2664. *)
  2665.  
  2666.  BEGIN
  2667.    RETURN(ScaligerYearToJ(syear));
  2668.  END ScaligerYearToG;
  2669.  
  2670.  
  2671.  PROCEDURE ScaligerYearToH(syear : CARDINAL) : INTEGER;
  2672.  
  2673. (*
  2674. ******* Date/ScaligerYearToH ************************************************
  2675. *
  2676. *   NAME
  2677. *    ScaligerYearToH -- Returns the Scaliger year as Heis year. (V33)
  2678. *
  2679. *   SYNOPSIS
  2680. *    year := ScaligerYearToH(syear);
  2681. *
  2682. *    PROCEDURE ScaligerYearToH(syear : CARDINAL) : INTEGER;
  2683. *
  2684. *   FUNCTION
  2685. *    Returns the Heis year of a Scaliger year.
  2686. *
  2687. *   INPUTS
  2688. *    syear     - Scaliger year
  2689. *
  2690. *   RESULT
  2691. *    year - The Heis year
  2692. *
  2693. *   EXAMPLE
  2694. *    ...
  2695. *    year := ScaligerYearToH(7000);
  2696. *    ...
  2697. *
  2698. *   NOTES
  2699. *    Its better to use this fkt only from 4707 to 7981!
  2700. *
  2701. *   BUGS
  2702. *    unknown.
  2703. *
  2704. *   SEE ALSO
  2705. *    ScaligerYearToJ(),ScaligerYearToG()
  2706. *
  2707. *****************************************************************************
  2708. *
  2709. *
  2710. *)
  2711.  
  2712.  VAR
  2713.     year    : INTEGER;
  2714.  
  2715.  BEGIN (* for compatibilitie if ScaligerYearToG is changed! *)
  2716.    RETURN(ScaligerYearToG(syear));
  2717.  END ScaligerYearToH;
  2718.  
  2719.  (* ----------------------------------------------------------------------- *)
  2720.  
  2721.  PROCEDURE JSYearToJD(syear : CARDINAL) : LONGCARD;
  2722.  
  2723. (*
  2724. ******* Date/JSYearToJD *****************************************************
  2725. *
  2726. *   NAME
  2727. *    JSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  2728. *
  2729. *   SYNOPSIS
  2730. *    jd := JSYearToJD(syear);
  2731. *
  2732. *    PROCEDURE JSYearToJD(syear : CARDINAL) : LONGCARD;
  2733. *
  2734. *   FUNCTION
  2735. *    Returns the Julianday of a Scaliger year.
  2736. *
  2737. *   INPUTS
  2738. *    syear     - Scaliger year
  2739. *
  2740. *   RESULT
  2741. *    jd - The Julianday
  2742. *
  2743. *   EXAMPLE
  2744. *    ...
  2745. *    jd := JSYearToJD(4800);
  2746. *    ...
  2747. *
  2748. *   NOTES
  2749. *    Its better to use this fkt only from 4707 to 6295!
  2750. *
  2751. *   BUGS
  2752. *    unknown.
  2753. *
  2754. *   SEE ALSO
  2755. *    GSYearToJD(),HSYearToJD()
  2756. *
  2757. *****************************************************************************
  2758. *
  2759. *
  2760. *)
  2761.  
  2762.  BEGIN
  2763.    RETURN((LONGCARD(syear)-1)*365+(LONGCARD(syear)+2) DIV 4);
  2764.  END JSYearToJD;
  2765.  
  2766.  
  2767.  PROCEDURE GSYearToJD(syear : CARDINAL) : LONGCARD;
  2768.  
  2769. (*
  2770. ******* Date/GSYearToJD *****************************************************
  2771. *
  2772. *   NAME
  2773. *    GSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  2774. *
  2775. *   SYNOPSIS
  2776. *    jd := GSYearToJD(syear);
  2777. *
  2778. *    PROCEDURE GSYearToJD(syear : CARDINAL) : LONGCARD;
  2779. *
  2780. *   FUNCTION
  2781. *    Returns the Julianday of a Scaliger year.
  2782. *
  2783. *   INPUTS
  2784. *    syear     - Scaliger year
  2785. *
  2786. *   RESULT
  2787. *    jd - The Julianday
  2788. *
  2789. *   EXAMPLE
  2790. *    ...
  2791. *    jd := GSYearToJD(4800);
  2792. *    ...
  2793. *
  2794. *   NOTES
  2795. *    Its better to use this fkt only from 4707 to 7981!
  2796. *
  2797. *   BUGS
  2798. *    unknown.
  2799. *
  2800. *   SEE ALSO
  2801. *    JSYearToJD(),HSYearToJD(),GregorianDayDiff(),ScaligerYearToG()
  2802. *
  2803. *****************************************************************************
  2804. *
  2805. *
  2806. *)
  2807.  
  2808.  BEGIN
  2809.    IF syear < 6296 THEN (* 1583 *)
  2810.      RETURN(JSYearToJD(syear));
  2811.    ELSE
  2812.      RETURN(JSYearToJD(6296)-10+LONGCARD(GregorianDayDiff(1,1,1583,1,1,ScaligerYearToG(syear))));
  2813.    END;
  2814.  END GSYearToJD;
  2815.  
  2816.  
  2817.  PROCEDURE HSYearToJD(syear : CARDINAL) : LONGCARD;
  2818.  
  2819. (*
  2820. ******* Date/HSYearToJD *****************************************************
  2821. *
  2822. *   NAME
  2823. *    HSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  2824. *
  2825. *   SYNOPSIS
  2826. *    jd := HSYearToJD(syear);
  2827. *
  2828. *    PROCEDURE HSYearToJD(syear : CARDINAL) : LONGCARD;
  2829. *
  2830. *   FUNCTION
  2831. *    Returns the Julianday of a Scaliger year.
  2832. *
  2833. *   INPUTS
  2834. *    syear     - Scaliger year
  2835. *
  2836. *   RESULT
  2837. *    jd - The Julianday
  2838. *
  2839. *   EXAMPLE
  2840. *    ...
  2841. *    jd := HSYearToJD(6700);
  2842. *    ...
  2843. *
  2844. *   NOTES
  2845. *    Its better to use this fkt only from 4707 to 7981!
  2846. *    In this version only GSYearToJD() is called, because the
  2847. *    Scaliger period is only valid to 3268
  2848. *
  2849. *   BUGS
  2850. *    unknown.
  2851. *
  2852. *   SEE ALSO
  2853. *    JSYearToJD(),GSYearToJD()
  2854. *
  2855. *****************************************************************************
  2856. *
  2857. *
  2858. *)
  2859.  
  2860.  BEGIN
  2861.    RETURN(GSYearToJD(syear));
  2862.  END HSYearToJD;
  2863.  
  2864.  (* ----------------------------------------------------------------------- *)
  2865.  
  2866.  PROCEDURE JDtoMJD(jd : LONGCARD) : LONGCARD;
  2867.  
  2868. (*
  2869. ******* Date/JDtoMJD ********************************************************
  2870. *
  2871. *   NAME
  2872. *    JDtoMJD -- Switches from JD to MJD. (V33)
  2873. *
  2874. *   SYNOPSIS
  2875. *    mjd := JDtoMJD(jd);
  2876. *
  2877. *    PROCEDURE JDtoMJD(jd : LONGCARD) : LONGCARD;
  2878. *
  2879. *   FUNCTION
  2880. *    Returns the Modified Julianday of a Julianday.
  2881. *
  2882. *   INPUTS
  2883. *    jd - Julianday
  2884. *
  2885. *   RESULT
  2886. *    mjd - The Modified Julianday
  2887. *
  2888. *   EXAMPLE
  2889. *    ...
  2890. *    mjd := JDtoMJD(2449354);
  2891. *    ...
  2892. *
  2893. *   NOTES
  2894. *    none
  2895. *
  2896. *   BUGS
  2897. *    Only use this funktion for jd > 2400001, because mjd is only
  2898. *    defined for this, otherwise system will crash!
  2899. *
  2900. *   SEE ALSO
  2901. *    MJDtoJD()
  2902. *
  2903. *****************************************************************************
  2904. *
  2905. *
  2906. *)
  2907.  
  2908.  BEGIN
  2909.    RETURN(jd-2400001);
  2910.  END JDtoMJD;
  2911.  
  2912.  
  2913.  PROCEDURE MJDtoJD(mjd : LONGCARD) : LONGCARD;
  2914.  
  2915. (*
  2916. ******* Date/MJDtoJD ********************************************************
  2917. *
  2918. *   NAME
  2919. *    MJDtoJD -- Switches from MJD to JD. (V33)
  2920. *
  2921. *   SYNOPSIS
  2922. *    jd := MJDtoJD(mjd);
  2923. *
  2924. *    PROCEDURE MJDtoJD(mjd : LONGCARD) : LONGCARD;
  2925. *
  2926. *   FUNCTION
  2927. *    Returns the Julianday of a Modified Julianday.
  2928. *
  2929. *   INPUTS
  2930. *    mjd - Modified Julianday
  2931. *
  2932. *   RESULT
  2933. *    jd - The Julianday
  2934. *
  2935. *   EXAMPLE
  2936. *    ...
  2937. *    jd := JDtoMJD(49353);
  2938. *    ...
  2939. *
  2940. *   NOTES
  2941. *    none
  2942. *
  2943. *   BUGS
  2944. *    unknown.
  2945. *
  2946. *   SEE ALSO
  2947. *    MJDtoJD()
  2948. *
  2949. *****************************************************************************
  2950. *
  2951. *
  2952. *)
  2953.  
  2954.  BEGIN
  2955.    RETURN(mjd+2400001);
  2956.  END MJDtoJD;
  2957.  
  2958.  (* ----------------------------------------------------------------------- *)
  2959.  
  2960.  PROCEDURE JulianToJD(day,month : SHORTCARD; year : INTEGER) : LONGCARD;
  2961.  
  2962. (*
  2963. ******* Date/JulianToJD *****************************************************
  2964. *
  2965. *   NAME
  2966. *    JulianToJD -- Returns the JD for a date. (V33)
  2967. *
  2968. *   SYNOPSIS
  2969. *    jd := JulianToJD(day,month,year);
  2970. *
  2971. *    PROCEDURE JulianToJD(day,month : SHORTCARD;
  2972. *        year : INTEGER) : LONGCARD;
  2973. *
  2974. *   FUNCTION
  2975. *    Returns the JD for a Julian date.
  2976. *
  2977. *   INPUTS
  2978. *    day      - day of the date to convert
  2979. *    month    - month of the date to convert
  2980. *    year     - year of the date to convert
  2981. *
  2982. *   RESULT
  2983. *    jd - This is the JD
  2984. *
  2985. *   EXAMPLE
  2986. *    ...
  2987. *    jd := JulianToJD(23,1,1994);
  2988. *    ...
  2989. *
  2990. *   NOTES
  2991. *    Its better to use this fkt only from -7 to 1582!
  2992. *
  2993. *   BUGS
  2994. *    unknown.
  2995. *
  2996. *   SEE ALSO
  2997. *    GregorianToJD(),HeisToJD(),JSYearToJD(),JYearToScaliger(),
  2998. *    JulianDayDiff()
  2999. *
  3000. *****************************************************************************
  3001. *
  3002. *
  3003. *)
  3004.  
  3005.  BEGIN
  3006.    RETURN(JSYearToJD(JYearToScaliger(year))+LONGCARD(JulianDayDiff(1,1,year,day,month,year)));
  3007.  END JulianToJD;
  3008.  
  3009.  
  3010.  PROCEDURE GregorianToJD(day,month : SHORTCARD; year : INTEGER) : LONGCARD;
  3011.  
  3012. (*
  3013. ******* Date/GregorianToJD **************************************************
  3014. *
  3015. *   NAME
  3016. *    GregorianToJD -- Returns the JD for a date. (V33)
  3017. *
  3018. *   SYNOPSIS
  3019. *    jd := GregorianToJD(day,month,year);
  3020. *
  3021. *    PROCEDURE GregorianToJD(day,month : SHORTCARD;
  3022. *        year : INTEGER) : LONGCARD;
  3023. *
  3024. *   FUNCTION
  3025. *    Returns the JD for a Gregorian date.
  3026. *
  3027. *   INPUTS
  3028. *    day      - day of the date to convert
  3029. *    month    - month of the date to convert
  3030. *    year     - year of the date to convert
  3031. *
  3032. *   RESULT
  3033. *    jd - This is the JD
  3034. *
  3035. *   EXAMPLE
  3036. *    ...
  3037. *    jd := GregorianToJD(23,1,1994);
  3038. *    ...
  3039. *
  3040. *   NOTES
  3041. *    Its better to use this fkt only from -7 to 3200!
  3042. *
  3043. *   BUGS
  3044. *    unknown.
  3045. *
  3046. *   SEE ALSO
  3047. *    JulianToJD(),HeisToJD(),GSYearToJD(),GYearToScaliger(),
  3048. *    GregorianDayDiff()
  3049. *
  3050. *****************************************************************************
  3051. *
  3052. *
  3053. *)
  3054.  
  3055.  BEGIN
  3056.    RETURN(GSYearToJD(GYearToScaliger(year))+LONGCARD(GregorianDayDiff(1,1,year,day,month,year)));
  3057.  END GregorianToJD;
  3058.  
  3059.  
  3060.  PROCEDURE HeisToJD(day,month : SHORTCARD; year : INTEGER) : LONGCARD;
  3061.  
  3062. (*
  3063. ******* Date/HeisToJD *******************************************************
  3064. *
  3065. *   NAME
  3066. *    HeisToJD -- Returns the JD for a date. (V33)
  3067. *
  3068. *   SYNOPSIS
  3069. *    jd := HeisToJD(day,month,year);
  3070. *
  3071. *    PROCEDURE HeisToJD(day,month : SHORTCARD;
  3072. *        year : INTEGER) : LONGCARD;
  3073. *
  3074. *   FUNCTION
  3075. *    Returns the JD for a Heis date.
  3076. *
  3077. *   INPUTS
  3078. *    day      - day of the date to convert
  3079. *    month    - month of the date to convert
  3080. *    year     - year of the date to convert
  3081. *
  3082. *   RESULT
  3083. *    jd - This is the JD
  3084. *
  3085. *   EXAMPLE
  3086. *    ...
  3087. *    jd := HeisToJD(23,1,1994);
  3088. *    ...
  3089. *
  3090. *   NOTES
  3091. *    Its better to use this fkt only from -7 to 3268!
  3092. *
  3093. *   BUGS
  3094. *    unknown.
  3095. *
  3096. *   SEE ALSO
  3097. *    JulianToJD(),GregorianToJD(),HSYearToJD(),HYearToScaliger(),
  3098. *    HeisDayDiff()
  3099. *
  3100. *****************************************************************************
  3101. *
  3102. *
  3103. *)
  3104.  
  3105.  BEGIN
  3106.    RETURN(HSYearToJD(HYearToScaliger(year))+LONGCARD(HeisDayDiff(1,1,year,day,month,year)));
  3107.  END HeisToJD;
  3108.  
  3109.  (* ----------------------------------------------------------------------- *)
  3110.  
  3111.  PROCEDURE TimeToJD(hour,min,sec : SHORTCARD) : REAL;
  3112.  
  3113. (*
  3114. ******* Date/TimeToJD *******************************************************
  3115. *
  3116. *   NAME
  3117. *    TimeToJD -- Returns the JD for a time. (V33)
  3118. *
  3119. *   SYNOPSIS
  3120. *    jd := TimeToJD(hour,min,sec);
  3121. *
  3122. *    PROCEDURE TimeToJD(hour,min,sec : SHORTCARD) : REAL;
  3123. *
  3124. *   FUNCTION
  3125. *    Returns the JD for a specified time.
  3126. *
  3127. *   INPUTS
  3128. *    hour - hour of the time to convert
  3129. *    min  - minute of the time to convert
  3130. *    sec  - sec. of the time to convert
  3131. *
  3132. *   RESULT
  3133. *    jd - This is the JD time
  3134. *
  3135. *   EXAMPLE
  3136. *    ...
  3137. *    jd := TimeToJD(16,33,0);
  3138. *    ...
  3139. *
  3140. *   NOTES
  3141. *    none
  3142. *
  3143. *   BUGS
  3144. *    There is no check, if the specified time is a valid time!
  3145. *
  3146. *   SEE ALSO
  3147. *    JDToTime()
  3148. *
  3149. *****************************************************************************
  3150. *
  3151. *
  3152. *)
  3153.  
  3154.  BEGIN
  3155.    RETURN(REAL(LONGCARD(hour)*3600+CARDINAL(min)*60+sec) / 86400.0);
  3156.  END TimeToJD;
  3157.  
  3158.  
  3159.  PROCEDURE JDToTime(jd : REAL; VAR rhour,rmin,rsec : SHORTCARD);
  3160.  
  3161. (*
  3162. ******* Date/JDToTime *******************************************************
  3163. *
  3164. *   NAME
  3165. *    JDToTime -- Returns the real time for a JD time. (V33)
  3166. *
  3167. *   SYNOPSIS
  3168. *    JDToTime(jd,rhour,rmin,rsec);
  3169. *
  3170. *    PROCEDURE JDToTime(jd : REAL; VAR rhour,rmin,rsec : SHORTCARD);
  3171. *
  3172. *   FUNCTION
  3173. *    Returns the real time for a JD time.
  3174. *
  3175. *   INPUTS
  3176. *    jd - JD time
  3177. *
  3178. *   RESULT
  3179. *    rhour - 24 hour real time
  3180. *    rmin  - real minutes
  3181. *    rsec  - real seconds
  3182. *
  3183. *   EXAMPLE
  3184. *    ...
  3185. *    JDToTime(0.76543,rhour,rmin,rsec);
  3186. *    ...
  3187. *
  3188. *   NOTES
  3189. *    none.
  3190. *
  3191. *   BUGS
  3192. *    If jd is > 0 (including days) there will be occur arithmetic bugs!
  3193. *
  3194. *   SEE ALSO
  3195. *    TimeToJD()
  3196. *
  3197. *****************************************************************************
  3198. *
  3199. *
  3200. *)
  3201.  
  3202.  VAR
  3203.     sec    : LONGCARD;
  3204.  
  3205.  BEGIN
  3206.      IF jd > 0.0 THEN
  3207.        jd := jd - REAL(LONGCARD(jd));
  3208.      END;
  3209.      sec := LONGCARD(jd * 86400.0);
  3210.      rhour := sec DIV 3600;
  3211.      sec := sec - (sec DIV 3600) * 3600;
  3212.      rmin := sec DIV 60;
  3213.      sec := sec - (sec DIV 60) * 60;
  3214.      rsec := sec;
  3215.  END JDToTime;
  3216.  
  3217.  (* ----internal----------------------------------------------------------- *)
  3218.  
  3219.  PROCEDURE GregorianSZ(year : CARDINAL) : SHORTCARD;
  3220.  
  3221. (*
  3222. *****i* Date/GregorianSZ ****************************************************
  3223. *
  3224. *   NAME
  3225. *    GregorianSZ -- Returns the 'Sonnenzirkel' (V33)
  3226. *
  3227. *   SYNOPSIS
  3228. *    sz := GregorianSZ(year);
  3229. *
  3230. *    PROCEDURE GregorianSZ(year : CARDINAL) : SHORTCARD;
  3231. *
  3232. *   FUNCTION
  3233. *    Returns the 'Sonnenzirkel' of a year.
  3234. *
  3235. *   INPUTS
  3236. *    year     - For this year the 'Sonnenzirkel' is calculatet.
  3237. *
  3238. *   RESULT
  3239. *    sz - The 'Sonnenzirkel' for the speified year.
  3240. *
  3241. *   EXAMPLE
  3242. *    ...
  3243. *    sz := GregorianSZ(1994);
  3244. *    ...
  3245. *
  3246. *   NOTES
  3247. *    Use this only for 1582 to 4100!
  3248. *
  3249. *   BUGS
  3250. *    unknown.
  3251. *
  3252. *   SEE ALSO
  3253. *    GYearToScaliger()
  3254. *
  3255. *****************************************************************************
  3256. *
  3257. *
  3258. *)
  3259.  
  3260.  VAR
  3261.     gz    : SHORTCARD;
  3262.  
  3263.  BEGIN
  3264.    gz := GYearToScaliger(year) MOD 28;
  3265.    IF gz = 0 THEN
  3266.      gz := 28;
  3267.    END;
  3268.    RETURN(gz);
  3269.  END GregorianSZ;
  3270.  
  3271.  
  3272.  PROCEDURE GregorianGZ(year : CARDINAL) : SHORTCARD;
  3273.  
  3274. (*
  3275. *****i* Date/GregorianGZ ****************************************************
  3276. *
  3277. *   NAME
  3278. *    GregorianGZ -- Returns the 'Goldene Zahl' (golden number) (V33)
  3279. *
  3280. *   SYNOPSIS
  3281. *    gz := GregorianGZ(year);
  3282. *
  3283. *    PROCEDURE GregorianGZ(year : CARDINAL) : SHORTCARD;
  3284. *
  3285. *   FUNCTION
  3286. *    Returns the 'Goldene Zahl' of a year.
  3287. *
  3288. *   INPUTS
  3289. *    year     - For this year the 'Goldene Zahl' is calculatet.
  3290. *
  3291. *   RESULT
  3292. *    gz - The 'Goldene Zahl' for the speified year.
  3293. *
  3294. *   EXAMPLE
  3295. *    ...
  3296. *    gz := GregorianGZ(1994);
  3297. *    ...
  3298. *
  3299. *   NOTES
  3300. *    Use this only for 1582 to 4100!
  3301. *
  3302. *   BUGS
  3303. *    unknown.
  3304. *
  3305. *   SEE ALSO
  3306. *    GYearToScaliger()
  3307. *
  3308. *****************************************************************************
  3309. *
  3310. *
  3311. *)
  3312.  
  3313.  VAR
  3314.     syear    : CARDINAL;
  3315.  
  3316.  BEGIN
  3317.    syear := GYearToScaliger(year) MOD 19;
  3318.    IF syear = 0 THEN
  3319.      syear := 19;
  3320.    END;
  3321.    RETURN(syear);
  3322.  END GregorianGZ;
  3323.  
  3324.  
  3325.    PROCEDURE GEP(year : CARDINAL) : SHORTCARD;
  3326.  
  3327. (*
  3328. *****i* Date/GEP ************************************************************
  3329. *
  3330. *   NAME
  3331. *    GEP -- Internal function to help calculating the 'EP' (V33)
  3332. *
  3333. *   SYNOPSIS
  3334. *    hep := GEP(year);
  3335. *
  3336. *    PROCEDURE GEP(year : CARDINAL) : SHORTCARD;
  3337. *
  3338. *   FUNCTION
  3339. *    Internal function to help calculating the 'EP'
  3340. *
  3341. *   INPUTS
  3342. *    year - This is the year for which the help EP is to be
  3343. *        calculatetd
  3344. *
  3345. *   RESULT
  3346. *    hep - The help value for the EP calculation.
  3347. *
  3348. *   EXAMPLE
  3349. *    ...
  3350. *    hep := GEP(1994);
  3351. *    ...
  3352. *
  3353. *   NOTES
  3354. *    Use this only for 1582 to 4100!
  3355. *
  3356. *   BUGS
  3357. *    unknown.
  3358. *
  3359. *   SEE ALSO
  3360. *
  3361. *
  3362. *****************************************************************************
  3363. *
  3364. *
  3365. *)
  3366.  
  3367.    VAR
  3368.     century,decade    : SHORTCARD;
  3369.     ep        : INTEGER;
  3370.  
  3371.    BEGIN
  3372.      ep := 1; (* 1582 *)
  3373.      century := year DIV 100;
  3374.      decade := year - century * 100;
  3375.      IF year < 1701 THEN
  3376.        RETURN(1);
  3377.      ELSIF year < 1800 THEN
  3378.        RETURN(0);
  3379.      ELSE
  3380.        ep := ep - INTEGER(((century) MOD 4) + (((century-16) DIV 4) * 3));
  3381.        IF (decade = 0) AND ((century MOD 4) > 0) THEN
  3382.          INC(ep);
  3383.        END;
  3384.        ep := ep + INTEGER((century-18) DIV 3);
  3385.        IF (((century-18) MOD 3) > 0) OR (decade > 0) THEN
  3386.          INC(ep);
  3387.        END;
  3388.        IF ep > 29 THEN
  3389.          ep := ep MOD 30;
  3390.        END;
  3391.        IF ep < 0 THEN
  3392.          ep := ep + 30;
  3393.        END;
  3394.        RETURN(SHORTCARD(ep));
  3395.      END;
  3396.    END GEP;
  3397.  
  3398.  
  3399.  PROCEDURE GregorianEP(year : CARDINAL) : SHORTCARD;
  3400.  
  3401. (*
  3402. *****i* Date/GregorianEP ****************************************************
  3403. *
  3404. *   NAME
  3405. *    GregorianEP -- Returns the 'Epakte' (V33)
  3406. *
  3407. *   SYNOPSIS
  3408. *    ep := GregorianEP(year);
  3409. *
  3410. *    PROCEDURE GregorianEP(year : CARDINAL) : SHORTCARD;
  3411. *
  3412. *   FUNCTION
  3413. *    Returns the 'Epakte' of a year.
  3414. *
  3415. *   INPUTS
  3416. *    year     - For this year the 'Epakte' is calculatet.
  3417. *
  3418. *   RESULT
  3419. *    ep - The 'Epakte' for the speified year.
  3420. *
  3421. *   EXAMPLE
  3422. *    ...
  3423. *    ep := GregorianEP(1994);
  3424. *    ...
  3425. *
  3426. *   NOTES
  3427. *    Use this only for 1582 to 4100!
  3428. *
  3429. *   BUGS
  3430. *    unknown.
  3431. *
  3432. *   SEE ALSO
  3433. *    GregorianGZ(),GEP()
  3434. *
  3435. *****************************************************************************
  3436. *
  3437. *
  3438. *)
  3439.  
  3440.  VAR
  3441.     ep    : SHORTCARD;
  3442.  
  3443.  BEGIN
  3444.    IF year >= 1582 THEN
  3445.      ep := ((GregorianGZ(year)-1)*11 + GEP(year)) MOD 30;
  3446.      IF ep = 0 THEN
  3447.        ep := 30;
  3448.      END;
  3449.      RETURN(ep);
  3450.    ELSE
  3451.      RETURN(31);
  3452.    END;
  3453.  END GregorianEP;
  3454.  
  3455.  
  3456.  PROCEDURE GregorianJHStartSB(century : SHORTCARD) : SHORTCARD;
  3457.  
  3458. (*
  3459. *****i* Date/GregorianJHStartSB *********************************************
  3460. *
  3461. *   NAME
  3462. *    GregorianJHStartSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3463. *
  3464. *   SYNOPSIS
  3465. *    csb := GregorianJHStartSB(century);
  3466. *
  3467. *    PROCEDURE GregorianJHStartSB(century : SHORTCARD) : SHORTCARD;
  3468. *
  3469. *   FUNCTION
  3470. *    Returns start 'SB' for a century.
  3471. *
  3472. *   INPUTS
  3473. *    century - For this century the start 'SB' is calculatet.
  3474. *
  3475. *   RESULT
  3476. *    csb - The start 'SB' for the speified century.
  3477. *
  3478. *   EXAMPLE
  3479. *    ...
  3480. *    csb := GregorianJHStartSB(19);
  3481. *    ...
  3482. *
  3483. *   NOTES
  3484. *    Use this only for 15 to 31!
  3485. *
  3486. *   BUGS
  3487. *    unknown.
  3488. *
  3489. *   SEE ALSO
  3490. *
  3491. *
  3492. *****************************************************************************
  3493. *
  3494. *
  3495. *)
  3496.  
  3497.  VAR
  3498.     sb    : SHORTCARD;
  3499.  
  3500.  BEGIN
  3501.   IF century = 15 THEN
  3502.     RETURN(4);
  3503.   ELSE
  3504.     sb := GregorianJHStartSB(century-1);
  3505.     IF (century MOD 4) > 0 THEN
  3506.       INC(sb);
  3507.     END;
  3508.     sb := sb MOD 7;
  3509.     IF sb = 0 THEN
  3510.       sb := 7;
  3511.     END;
  3512.     RETURN(sb);
  3513.   END;
  3514.  END GregorianJHStartSB;
  3515.  
  3516.  
  3517.  PROCEDURE GregorianJHSB(year : CARDINAL) : SHORTCARD;
  3518.  
  3519. (*
  3520. *****i* Date/GregorianSB ****************************************************
  3521. *
  3522. *   NAME
  3523. *    GregorianJHSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3524. *
  3525. *   SYNOPSIS
  3526. *    sb := GregorianJHSB(year);
  3527. *
  3528. *    PROCEDURE GregorianJHSB(year : CARDINAL) : SHORTCARD;
  3529. *
  3530. *   FUNCTION
  3531. *    Returns the start 'SB' for a century year.
  3532. *
  3533. *   INPUTS
  3534. *    year - For this century year the start 'SB' is calculatet.
  3535. *
  3536. *   RESULT
  3537. *    sb - The start 'SB' for the specified year.
  3538. *
  3539. *   EXAMPLE
  3540. *    ...
  3541. *    sb := GregorianJHSB(1994);
  3542. *    ...
  3543. *
  3544. *   NOTES
  3545. *    Use this only for 1583 to 3199!
  3546. *
  3547. *   BUGS
  3548. *    unknown.
  3549. *
  3550. *   SEE ALSO
  3551. *    GregorianLeapYear(),GregorianJHStartSB()
  3552. *
  3553. *****************************************************************************
  3554. *
  3555. *
  3556. *)
  3557.  
  3558.  BEGIN
  3559.   IF ((year MOD 100) = 0) AND (~GregorianLeapYear(INTEGER(year))) THEN
  3560.     RETURN(SHORTCARD(((year DIV 100) MOD 4) *2 +1));
  3561.   ELSE
  3562.     RETURN(GregorianJHStartSB(year DIV 100));
  3563.   END;
  3564.  END GregorianJHSB;
  3565.  
  3566.  
  3567.  PROCEDURE GregorianSB(year : CARDINAL) : SHORTCARD;
  3568.  
  3569. (*
  3570. *****i* Date/GregorianSB ****************************************************
  3571. *
  3572. *   NAME
  3573. *    GregorianSB -- Returns the 'Sonntagsbuchstabe' (V33)
  3574. *
  3575. *   SYNOPSIS
  3576. *    sb := GregorianSB(year);
  3577. *
  3578. *    PROCEDURE GregorianSB(year : CARDINAL) : SHORTCARD;
  3579. *
  3580. *   FUNCTION
  3581. *    Returns the 'SB' for a year.
  3582. *
  3583. *   INPUTS
  3584. *    year - For this year the 'SB' is calculatet.
  3585. *
  3586. *   RESULT
  3587. *    sb - The 'SB' for the speified year.
  3588. *        This means the day the first sunday lies on :)
  3589. *
  3590. *   EXAMPLE
  3591. *    ...
  3592. *    sb := GregorianSB(1994);
  3593. *    ...
  3594. *
  3595. *   NOTES
  3596. *    Use this only for 1583 to 3199!
  3597. *
  3598. *   BUGS
  3599. *    unknown.
  3600. *
  3601. *   SEE ALSO
  3602. *    GregorianLeapYear(),GregorianSZ(),GregorianJHStartSB()
  3603. *
  3604. *****************************************************************************
  3605. *
  3606. *
  3607. *)
  3608.  
  3609.  VAR
  3610.     sz,csb,i    : SHORTCARD;
  3611.  
  3612.  BEGIN
  3613.    IF ((year MOD 100) = 0) AND (~GregorianLeapYear(INTEGER(year))) THEN
  3614.      RETURN(SHORTCARD(((year DIV 100) MOD 4) *2 +1));
  3615.    ELSE
  3616.      sz := GregorianSZ(year);
  3617.      csb := GregorianJHStartSB(year DIV 100);
  3618.      IF sz = 28 THEN
  3619.        RETURN(csb);
  3620.      ELSE
  3621.        FOR i := 27 TO sz BY -1 DO
  3622.          INC(csb);
  3623.          IF csb = 8 THEN
  3624.            csb := 1;
  3625.          END;
  3626.          IF ((i-1) MOD 4) = 0 THEN
  3627.            INC(csb);
  3628.            IF csb = 8 THEN
  3629.              csb := 1;
  3630.            END;
  3631.          END;
  3632.        END;
  3633.        RETURN(csb);
  3634.      END;
  3635.    END;
  3636.  END GregorianSB;
  3637.  
  3638.  (* ----------------------------------------------------------------------- *)
  3639.  
  3640.  PROCEDURE GregorianMoonAge(day,month : SHORTCARD; year : INTEGER) : SHORTCARD;
  3641.  
  3642. (*
  3643. ******* Date/GregorianMoonAge ***********************************************
  3644. *
  3645. *   NAME
  3646. *    GregorianMoonAge -- Returns the age of the moon (V33)
  3647. *
  3648. *   SYNOPSIS
  3649. *    ep := GregorianMoonAge(day,month,year);
  3650. *
  3651. *    PROCEDURE GregorianMoonAge(day,month : SHORTCARD;
  3652. *        year : CARDINAL) : SHORTCARD;
  3653. *
  3654. *   FUNCTION
  3655. *    Returns the age of the moon on a specified date.
  3656. *
  3657. *   INPUTS
  3658. *    day   - For this day the age is calculated.
  3659. *    month - For this month the age is calculated.
  3660. *    year  - For this year the age is calculated.
  3661. *
  3662. *   RESULT
  3663. *    ep - The age of the moon on the specified date.
  3664. *
  3665. *   EXAMPLE
  3666. *    ...
  3667. *    ep := GregorianMoonAge(18,9,1994);
  3668. *    ...
  3669. *
  3670. *   NOTES
  3671. *    Use this only for 1582 to 4100!
  3672. *    This is only a experimental version!
  3673. *
  3674. *   BUGS
  3675. *    unknown.
  3676. *
  3677. *   SEE ALSO
  3678. *    MoonMonthAge(),GregorianEP()
  3679. *
  3680. *****************************************************************************
  3681. *
  3682. *
  3683. *)
  3684.  
  3685.    PROCEDURE MoonMonthAge(month,ep : SHORTCARD) : SHORTCARD;
  3686.  
  3687. (*
  3688. *****i* Date/MoonMonthAge ***************************************************
  3689. *
  3690. *   NAME
  3691. *    MoonMonthAge -- Calculates the age of the moon on month start (V33)
  3692. *
  3693. *   SYNOPSIS
  3694. *    ep := MoonMonthAge(month,ep);
  3695. *
  3696. *    PROCEDURE MoonMonthAge(month,ep : SHORTCARD) : SHORTCARD;
  3697. *
  3698. *   FUNCTION
  3699. *    Returns the age of the moon on the start of a month.
  3700. *
  3701. *   INPUTS
  3702. *    month - Month for which the moonage is needed.
  3703. *    ep    - 'Epakte' of the newyears-day.
  3704. *
  3705. *   RESULT
  3706. *    ep - The moonage on the 1. of the specified month.
  3707. *
  3708. *   EXAMPLE
  3709. *    ...
  3710. *    ep := MoonMonthAge(2,17); (* 17 is for 1994 *)
  3711. *    ...
  3712. *
  3713. *   NOTES
  3714. *    This is only a experimental version!
  3715. *
  3716. *   BUGS
  3717. *    unknown.
  3718. *
  3719. *   SEE ALSO
  3720. *    GregorianMonthDays()
  3721. *
  3722. *****************************************************************************
  3723. *
  3724. *
  3725. *)
  3726.  
  3727.    BEGIN
  3728.      IF month = 1 THEN
  3729.        RETURN(ep);
  3730.      ELSE
  3731.        IF month MOD 2 = 0 THEN
  3732.          ep := (MoonMonthAge(month-1,ep) + GregorianMonthDays(month-1,year)) MOD 29;
  3733.        ELSE
  3734.          ep := (MoonMonthAge(month-1,ep) + GregorianMonthDays(month-1,year)) MOD 30;
  3735.        END;
  3736.        RETURN(ep);
  3737.      END;
  3738.    END MoonMonthAge;
  3739.  
  3740.  VAR
  3741.     ep    : SHORTCARD;
  3742.  
  3743.  BEGIN
  3744.    ep := GregorianEP(year);
  3745.    ep := MoonMonthAge(month,ep);
  3746.    ep := ep + day -1;
  3747.    IF month > 1 THEN
  3748.      IF month MOD 2 = 0 THEN
  3749.        ep := ep MOD 30;
  3750.        IF ep = 0 THEN
  3751.          ep := 30;
  3752.        END;
  3753.      ELSE
  3754.        ep := ep MOD 29;
  3755.        IF ep = 0 THEN
  3756.          ep := 29;
  3757.        END;
  3758.      END;
  3759.    ELSE
  3760.      IF ep > 29 THEN
  3761.        ep := ep MOD 29;
  3762.      END;
  3763.    END;
  3764.    RETURN(ep);
  3765.  END GregorianMoonAge;
  3766.  
  3767.  (* ----------------------------------------------------------------------- *)
  3768. (*
  3769.  PROCEDURE GregorianEasterOld(year : INTEGER; VAR dday,dmonth : SHORTCARD);
  3770.  
  3771. (*
  3772. *****i* Date/GregorianEaster ************************************************
  3773. *
  3774. *   NAME
  3775. *    GregorianEaster -- Returns the date of eastern in a year (V33)
  3776. *
  3777. *   SYNOPSIS
  3778. *    GregorianEaster(year,dday,dmonth);
  3779. *
  3780. *    PROCEDURE GregorianEaster(year : INTEGER;
  3781. *        VAR dday,dmonth : SHORTCARD);
  3782. *
  3783. *   FUNCTION
  3784. *    Returns the date of eastern for a specified year.
  3785. *
  3786. *   INPUTS
  3787. *    year  - eastern is calculated for this year
  3788. *
  3789. *   RESULT
  3790. *    dday   - day of easter-sunday
  3791. *    dmonth - month of easter-sunday
  3792. *
  3793. *   EXAMPLE
  3794. *    ...
  3795. *    GregorianEaster(1994,dday,dmonth);
  3796. *    ...
  3797. *
  3798. *   NOTES
  3799. *    Use this only for 1582 to 4100!
  3800. *    This is only a experimental version!
  3801. *
  3802. *   BUGS
  3803. *    In some years eastern lies one week behind!
  3804. *
  3805. *   SEE ALSO
  3806. *    GregorianMoonAge(),GregorianDaysAfterWeekday()
  3807. *
  3808. *****************************************************************************
  3809. *
  3810. *
  3811. *)
  3812.  
  3813.  VAR
  3814.     ep    : SHORTCARD;
  3815.  
  3816.  BEGIN
  3817.    dday := 21;
  3818.    dmonth := 3;
  3819.    ep := GregorianMoonAge(21,3,year);
  3820.    IF ep < 14 THEN
  3821.      dday := dday + (14-ep);
  3822.    ELSE
  3823.      dday := dday + (29-ep) + 13;
  3824.    END;
  3825.    IF dday > 31 THEN
  3826.      dday := dday - 31;
  3827.      INC(dmonth);
  3828.    END;
  3829.    dday := dday + GregorianDaysAfterWeekday(dday,dmonth,year,sunday);
  3830.    IF dday > 31 THEN
  3831.      dday := dday - 31;
  3832.      INC(dmonth);
  3833.    END;
  3834.  END GregorianEasterOld;
  3835. *)
  3836.  
  3837.  PROCEDURE GregorianEaster(year : INTEGER; VAR dday,dmonth : SHORTCARD);
  3838.  
  3839. (*
  3840. ******* Date/GregorianEaster ************************************************
  3841. *
  3842. *   NAME
  3843. *    GregorianEaster -- Returns the date of eastern in a year (V33)
  3844. *
  3845. *   SYNOPSIS
  3846. *    GregorianEaster(year,dday,dmonth);
  3847. *
  3848. *    PROCEDURE GregorianEaster(year : INTEGER;
  3849. *        VAR dday,dmonth : SHORTCARD);
  3850. *
  3851. *   FUNCTION
  3852. *    Returns the date of eastern for a specified year.
  3853. *
  3854. *   INPUTS
  3855. *    year  - eastern is calculated for this year
  3856. *
  3857. *   RESULT
  3858. *    dday   - day of easter-sunday
  3859. *    dmonth - month of easter-sunday
  3860. *
  3861. *   EXAMPLE
  3862. *    ...
  3863. *    GregorianEaster(1994,dday,dmonth);
  3864. *    ...
  3865. *
  3866. *   NOTES
  3867. *    Use this only for 1900 to 2099!
  3868. *    Tested for 1977-1994! But this formula is from Gauß - so it must be
  3869. *    correct :)
  3870. *
  3871. *   BUGS
  3872. *    None.
  3873. *
  3874. *   SEE ALSO
  3875. *    GEP(),GregorianJHSB()
  3876. *
  3877. *****************************************************************************
  3878. *
  3879. *
  3880. *)
  3881.  
  3882.  VAR
  3883.      a,d,e,f    : SHORTCARD;
  3884.      M,N    : SHORTINT;
  3885.  
  3886.  BEGIN
  3887.    M := SHORTINT(30 - GEP(year)) - 7;
  3888.    IF M < 0 THEN
  3889.      M := M + 30;
  3890.    END;
  3891.    N := GregorianJHSB(year)-2;
  3892.    IF N < 1 THEN
  3893.      N := N + 7;
  3894.    END;
  3895.    a := SHORTCARD(year MOD 19);
  3896.    d := SHORTCARD((19*CARDINAL(a)+SHORTCARD(M)) MOD 30);
  3897.    e := SHORTCARD((2*CARDINAL(year MOD 4)+4*CARDINAL(year MOD 7)+6*CARDINAL(d)+SHORTCARD(N)) MOD 7);
  3898.    f := d+e;
  3899.    IF f < 10 THEN (* märz *)
  3900.      dmonth := 3;
  3901.      dday := 22+f;
  3902.    ELSE (* april *)
  3903.      dmonth := 4;
  3904.      dday := f-9;
  3905.      IF dday=26 THEN
  3906.        dday := 19;
  3907.      ELSIF (dday=25) AND (d=28) AND (a>10) THEN
  3908.        dday := 18;
  3909.      END;
  3910.    END;
  3911.  END GregorianEaster;
  3912.  
  3913.  (* ----------------------------------------------------------------------- *)
  3914.  
  3915.  PROCEDURE TimeZoneFactor(degree : SHORTINT) : SHORTINT;
  3916.  
  3917. (*
  3918. ******* Date/TimeZoneFactor *************************************************
  3919. *
  3920. *   NAME
  3921. *    TimeZoneFactor -- Returns the value you have to add to GMT time (V33)
  3922. *
  3923. *   SYNOPSIS
  3924. *    addhours := TimeZoneFactor(degrees);
  3925. *
  3926. *    PROCEDURE TimeZoneFactor(degree : SHORTINT) : SHORTINT;
  3927. *
  3928. *   FUNCTION
  3929. *    This gives you the hours you have to add to GMT time,
  3930. *    specified on the fact, that a timezone is 15 degrees
  3931. *    and that GMT is centered on 0 degrees!
  3932. *
  3933. *   INPUTS
  3934. *    degrees - Position of timezone you live in (from -180 to +180)
  3935. *
  3936. *   RESULT
  3937. *    addhours - Time to add to GMT time to get your locale zone time
  3938. *        (-12 to +12)
  3939. *
  3940. *   EXAMPLE
  3941. *    ...
  3942. *    addhours := TimeZoneFactor(-8);
  3943. *    ...
  3944. *
  3945. *   NOTES
  3946. *    none
  3947. *
  3948. *   BUGS
  3949. *    No errorcheck, if you put in valid degrees (-180 to +180)
  3950. *    Only full degrees are supportet, keep sure that you
  3951. *    round in the right way for 0.x degree places
  3952. *    I am not sure about the correct +/- behaviour!!!
  3953. *
  3954. *   SEE ALSO
  3955. *
  3956. *
  3957. *****************************************************************************
  3958. *
  3959. *
  3960. *)
  3961.  
  3962.  BEGIN
  3963.    IF degree >= 0 THEN
  3964.      RETURN(SHORTINT(REAL(degree) / 15.0 + 0.5));
  3965.    ELSE
  3966.      RETURN(SHORTINT(REAL(degree) / 15.0 - 0.5));
  3967.    END;
  3968.  END TimeZoneFactor;
  3969.  
  3970.  
  3971.  PROCEDURE LMT(secs : LONGCARD; meridiandegree, posdegree : REAL) : LONGINT;
  3972.  
  3973. (*
  3974. ******* Date/LMT ************************************************************
  3975. *
  3976. *   NAME
  3977. *    LMT -- Calculates your local time in your timezone (V33)
  3978. *
  3979. *   SYNOPSIS
  3980. *    secs := LMT(secs,meridian,pos);
  3981. *
  3982. *    PROCEDURE LMT(secs : LONGCARD; meridiandegree,
  3983. *        posdegree : REAL) : LONGINT;
  3984. *
  3985. *   FUNCTION
  3986. *    Calculates your Local Mean Time of you place!
  3987. *
  3988. *   INPUTS
  3989. *    secs     - Seconds of the running day (hours*3600+min*60+sec)
  3990. *    meridian - Degrees of your timezone-meridian
  3991. *    pos      - Degrees of your place
  3992. *
  3993. *   RESULT
  3994. *    secs - Local seconds of the running day
  3995. *
  3996. *   EXAMPLE
  3997. *    ...
  3998. *    secs := LMT(76080,15.0,8.923055556);
  3999. *    ...
  4000. *
  4001. *   NOTES
  4002. *    none
  4003. *
  4004. *   BUGS
  4005. *    No errorcheck, if you put in valid degrees (-180 to +180)
  4006. *
  4007. *   SEE ALSO
  4008. *
  4009. *
  4010. *****************************************************************************
  4011. *
  4012. *
  4013. *)
  4014.  
  4015.  BEGIN
  4016.    RETURN(LONGINT(secs) + LONGINT((meridiandegree / 15.0 - posdegree / 15.0)*3600.0));
  4017.  END LMT;
  4018.  
  4019.  
  4020.  PROCEDURE TimeToSec(hour,min,sec : SHORTCARD) : LONGCARD;
  4021.  
  4022. (*
  4023. ******* Date/TimeToSec ******************************************************
  4024. *
  4025. *   NAME
  4026. *    TimeToSec -- Returns the time in seconds (V33)
  4027. *
  4028. *   SYNOPSIS
  4029. *    secs := TimeToSec(hour,min,sec);
  4030. *
  4031. *    PROCEDURE TimeToSec(hour,min,sec : SHORTCARD) : LONGCARD;
  4032. *
  4033. *   FUNCTION
  4034. *    Gives you back the time in seconds
  4035. *
  4036. *   INPUTS
  4037. *    hour - hours you want (0-23)
  4038. *    min  - minutes you want (0-59)
  4039. *    sec  - seconds you want (0-59)
  4040. *
  4041. *   RESULT
  4042. *    secs - Time in seconds
  4043. *
  4044. *   EXAMPLE
  4045. *    ...
  4046. *    secs := TimeToSec(21,15,00);
  4047. *    ...
  4048. *
  4049. *   NOTES
  4050. *    Don't forget to convert AM/PM time to 24h time!
  4051. *
  4052. *   BUGS
  4053. *    No errorcheck, if you use a valid time
  4054. *
  4055. *   SEE ALSO
  4056. *    SecToTime()
  4057. *
  4058. *****************************************************************************
  4059. *
  4060. *
  4061. *)
  4062.  
  4063.  BEGIN
  4064.    RETURN(LONGCARD(hour)*3600+LONGCARD(min)*60+sec);
  4065.  END TimeToSec;
  4066.  
  4067.  
  4068.  PROCEDURE SecToTime(secs : LONGCARD; VAR hour,min,sec : SHORTCARD);
  4069.  
  4070. (*
  4071. ******* Date/SecToTime ******************************************************
  4072. *
  4073. *   NAME
  4074. *    SecToTime -- Returns the time from seconds (V33)
  4075. *
  4076. *   SYNOPSIS
  4077. *    SecToTime(secs,hour,min,sec);
  4078. *
  4079. *    PROCEDURE SecToTime(secs : LONGCARD; VAR hour,min,sec : SHORTCARD);
  4080. *
  4081. *   FUNCTION
  4082. *    Gives you back the time from the specified seconds
  4083. *
  4084. *   INPUTS
  4085. *    secs - Time in seconds
  4086. *
  4087. *   RESULT
  4088. *    hour - hours (0-23)
  4089. *    min  - minutes (0-59)
  4090. *    sec  - seconds (0-59)
  4091. *
  4092. *   EXAMPLE
  4093. *    ...
  4094. *    SecToTime(76860,hour,min,sec);
  4095. *    ...
  4096. *
  4097. *   NOTES
  4098. *    Don't forget to convert 24h time to AM/PM time if needed!
  4099. *
  4100. *   BUGS
  4101. *    No errorcheck, if you use a valid time
  4102. *
  4103. *   SEE ALSO
  4104. *    TimeToSec()
  4105. *
  4106. *****************************************************************************
  4107. *
  4108. *
  4109. *)
  4110.  
  4111.  BEGIN
  4112.    hour := SHORTCARD(secs DIV 3600);
  4113.    secs := secs - LONGCARD(hour) * 3600;
  4114.    min := SHORTCARD(secs DIV 60);
  4115.    sec := SHORTCARD(secs - min * 60);
  4116.  END SecToTime;
  4117.  
  4118.  (* ----------------------------------------------------------------------- *)
  4119.  
  4120.  PROCEDURE JulianWeek(day,month : SHORTCARD; year : INTEGER) : SHORTCARD;
  4121.  
  4122. (*
  4123. ******* Date/JulianWeek *****************************************************
  4124. *
  4125. *   NAME
  4126. *    JulianWeek -- Gets the weeknumber of a specified date. (V33)
  4127. *
  4128. *   SYNOPSIS
  4129. *    weeknr := JulianWeek(day,month,year);
  4130. *
  4131. *    PROCEDURE JulianWeek(day,month : SHORTCARD;
  4132. *        year : INTEGER) : SHORTCARD;
  4133. *
  4134. *   FUNCTION
  4135. *    JulianWeek gets the weeknumber for a specified date.
  4136. *
  4137. *   INPUTS
  4138. *    day   - day of the date
  4139. *    month - month of the date
  4140. *    year  - year of the date
  4141. *
  4142. *   RESULT
  4143. *    week - This is the number of the week the specified date lies in.
  4144. *        If the first day in a new year is a freiday, saturday or
  4145. *        sunday, this would be the last week of the last year!
  4146. *        If the 29.12. is a monday, the 30.12. is a monday or a tuesday,
  4147. *        the 31.12. is a monday, tuesday or a wednesday this is the
  4148. *        first week of the next year!
  4149. *
  4150. *   EXAMPLE
  4151. *    ...
  4152. *    weeknr := JulianWeek(4,10,1582);
  4153. *    ...
  4154. *
  4155. *   NOTES
  4156. *    Its is better only to use this function for years from 0 to 1582!
  4157. *
  4158. *   BUGS
  4159. *    For years < 0 errors could occur.
  4160. *
  4161. *   SEE ALSO
  4162. *    GregorianWeek(),HeisWeek(),JulianWeekday(),JulianDaySmaller(),
  4163. *    JulianDayDiff()
  4164. *
  4165. *****************************************************************************
  4166. *
  4167. *
  4168. *)
  4169.  
  4170.  TYPE
  4171.     Wds    = SET OF Weekdays;
  4172.  
  4173.  VAR
  4174.     days        : LONGINT;
  4175.     firstweekday    : Weekdays;
  4176.  
  4177.  BEGIN
  4178.    firstweekday := JulianWeekday(1,1,year);
  4179.    days := (JulianDayDiff(1,1,year,day,month,year) + LONGINT(firstweekday) -1) DIV 7;
  4180.    IF firstweekday > thursday THEN
  4181.      IF days = 0 THEN
  4182.        days := JulianWeek(31,12,year-1);
  4183.      END;
  4184.      RETURN(SHORTCARD(days));
  4185.    ELSE
  4186.      IF ~JulianDaySmaller(day,month,year,29,12,year) THEN
  4187.        firstweekday := JulianWeekday(day,12,year);
  4188.        CASE day OF
  4189.          29 : IF firstweekday = monday THEN
  4190.                 days := 0;
  4191.               END;|
  4192.          30 : IF firstweekday IN Wds{monday,tuesday} THEN
  4193.                 days := 0;
  4194.               END;|
  4195.          31 : IF firstweekday IN Wds{monday,tuesday,wednesday} THEN
  4196.                 days := 0;
  4197.               END;
  4198.        ELSE
  4199.        END;
  4200.      END;
  4201.      RETURN(SHORTCARD(days +1));
  4202.    END;
  4203.  END JulianWeek;
  4204.  
  4205.  
  4206.  PROCEDURE GregorianWeek(day,month : SHORTCARD; year : INTEGER) : SHORTCARD;
  4207.  
  4208. (*
  4209. ******* Date/GregorianWeek **************************************************
  4210. *
  4211. *   NAME
  4212. *    GregorianWeek -- Gets the weeknumber of a specified date. (V33)
  4213. *
  4214. *   SYNOPSIS
  4215. *    weeknr := GregorianWeek(day,month,year);
  4216. *
  4217. *    PROCEDURE GregorianWeek(day,month : SHORTCARD;
  4218. *        year : INTEGER) : SHORTCARD;
  4219. *
  4220. *   FUNCTION
  4221. *    GregorianWeek gets the weeknumber for a specified date.
  4222. *
  4223. *   INPUTS
  4224. *    day   - day of the date
  4225. *    month - month of the date
  4226. *    year  - year of the date
  4227. *
  4228. *   RESULT
  4229. *    week - This is the number of the week the specified date lies in.
  4230. *        If the first day in a new year is a freiday, saturday or
  4231. *        sunday, this would be the last week of the last year!
  4232. *        If the 29.12. is a monday, the 30.12. is a monday or a tuesday,
  4233. *        the 31.12. is a monday, tuesday or a wednesday this is the
  4234. *        first week of the next year!
  4235. *
  4236. *   EXAMPLE
  4237. *    ...
  4238. *    weeknr := GregorianWeek(4,10,1582);
  4239. *    ...
  4240. *
  4241. *   NOTES
  4242. *    Its is better only to use this function for years from 0 to 3000!
  4243. *
  4244. *   BUGS
  4245. *    For years < 0 errors could occur.
  4246. *
  4247. *   SEE ALSO
  4248. *    JulianWeek(),HeisWeek(),GregorianDaySmaller(),GregorianWeekday(),
  4249. *    GregorianDayDiff()
  4250. *
  4251. *****************************************************************************
  4252. *
  4253. *
  4254. *)
  4255.  
  4256.  TYPE
  4257.     Wds    = SET OF Weekdays;
  4258.  
  4259.  VAR
  4260.     days        : LONGINT;
  4261.     firstweekday    : Weekdays;
  4262.  
  4263.  BEGIN
  4264.    firstweekday := GregorianWeekday(1,1,year);
  4265.    days := (GregorianDayDiff(1,1,year,day,month,year) + LONGINT(firstweekday) -1) DIV 7;
  4266.    IF firstweekday > thursday THEN
  4267.      IF days = 0 THEN
  4268.        days := GregorianWeek(31,12,year-1);
  4269.      END;
  4270.      RETURN(SHORTCARD(days));
  4271.    ELSE
  4272.      IF ~GregorianDaySmaller(day,month,year,29,12,year) THEN
  4273.        firstweekday := GregorianWeekday(day,12,year);
  4274.        CASE day OF
  4275.          29 : IF firstweekday = monday THEN
  4276.                 days := 0;
  4277.               END;|
  4278.          30 : IF firstweekday IN Wds{monday,tuesday} THEN
  4279.                 days := 0;
  4280.               END;|
  4281.          31 : IF firstweekday IN Wds{monday,tuesday,wednesday} THEN
  4282.                 days := 0;
  4283.               END;
  4284.        ELSE
  4285.        END;
  4286.      END;
  4287.      RETURN(SHORTCARD(days +1));
  4288.    END;
  4289.  END GregorianWeek;
  4290.  
  4291.  
  4292.  PROCEDURE HeisWeek(day,month : SHORTCARD; year : INTEGER) : SHORTCARD;
  4293.  
  4294. (*
  4295. ******* Date/HeisWeek *******************************************************
  4296. *
  4297. *   NAME
  4298. *    HeisWeek -- Gets the weeknumber of a specified date. (V33)
  4299. *
  4300. *   SYNOPSIS
  4301. *    weeknr := HeisWeek(day,month,year);
  4302. *
  4303. *    PROCEDURE HeisWeek(day,month : SHORTCARD;
  4304. *        year : INTEGER) : SHORTCARD;
  4305. *
  4306. *   FUNCTION
  4307. *    HeisWeek gets the weeknumber for a specified date.
  4308. *
  4309. *   INPUTS
  4310. *    day   - day of the date
  4311. *    month - month of the date
  4312. *    year  - year of the date
  4313. *
  4314. *   RESULT
  4315. *    week - This is the number of the week the specified date lies in.
  4316. *        If the first day in a new year is a freiday, saturday or
  4317. *        sunday, this would be the last week of the last year!
  4318. *        If the 29.12. is a monday, the 30.12. is a monday or a tuesday,
  4319. *        the 31.12. is a monday, tuesday or a wednesday this is the
  4320. *        first week of the next year!
  4321. *
  4322. *   EXAMPLE
  4323. *    ...
  4324. *    weeknr := HeisWeek(4,10,1582);
  4325. *    ...
  4326. *
  4327. *   NOTES
  4328. *    Its is better only to use this function for years from 0 to 8000!
  4329. *
  4330. *   BUGS
  4331. *    For years < 0 errors could occur.
  4332. *
  4333. *   SEE ALSO
  4334. *    JulianWeek(),GregorianWeek(),HeisDayDiff(),HeisDaySmaller(),
  4335. *    HeisWeekday()
  4336. *
  4337. *****************************************************************************
  4338. *
  4339. *
  4340. *)
  4341.  
  4342.  TYPE
  4343.     Wds    = SET OF Weekdays;
  4344.  
  4345.  VAR
  4346.     days        : LONGINT;
  4347.     firstweekday    : Weekdays;
  4348.  
  4349.  BEGIN
  4350.    firstweekday := HeisWeekday(1,1,year);
  4351.    days := (HeisDayDiff(1,1,year,day,month,year) + LONGINT(firstweekday) -1) DIV 7;
  4352.    IF firstweekday > thursday THEN
  4353.      IF days = 0 THEN
  4354.        days := HeisWeek(31,12,year-1);
  4355.      END;
  4356.      RETURN(SHORTCARD(days));
  4357.    ELSE
  4358.      IF ~HeisDaySmaller(day,month,year,29,12,year) THEN
  4359.        firstweekday := HeisWeekday(day,12,year);
  4360.        CASE day OF
  4361.          29 : IF firstweekday = monday THEN
  4362.                 days := 0;
  4363.               END;|
  4364.          30 : IF firstweekday IN Wds{monday,tuesday} THEN
  4365.                 days := 0;
  4366.               END;|
  4367.          31 : IF firstweekday IN Wds{monday,tuesday,wednesday} THEN
  4368.                 days := 0;
  4369.               END;
  4370.        ELSE
  4371.        END;
  4372.      END;
  4373.      RETURN(SHORTCARD(days +1));
  4374.    END;
  4375.  END HeisWeek;
  4376.  
  4377.  (* ----------------------------------------------------------------------- *)
  4378.  
  4379.  BEGIN
  4380.    (* Gregorian reform in Rom *)
  4381.    BeforeGregorianDay := 4;
  4382.    BeforeGregorianMonth := 10;
  4383.    BeforeGregorianYear := 1582;
  4384.    AfterGregorianDay := 15;
  4385.    AfterGregorianMonth := 10;
  4386.    AfterGregorianYear := 1582;
  4387.    StartHeisDay := 1;
  4388.    StartHeisMonth := 1;
  4389.    StartHeisYear := 3200;
  4390.    (* Dates of Gregorian reform in
  4391.       Deutschland, Niederlande, Schweiz, Dänemark:
  4392.         18.02.1700-01.03.1700
  4393.       Großbritannien
  4394.         02.09.1752-14.09.1752
  4395.       Schweden
  4396.         17.02.1753-01.03.1753
  4397.       Rußland
  4398.     ? (oktober Revolution)
  4399.       Griechenland
  4400.         ??.??.1923-??.??.1923 *)
  4401.    (* Bremen/Arbergen = 8° 55' 23" East, 53° 4' 8" North *)
  4402.  END Date.
  4403.