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

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