home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / dev / date-33.087.lha / Date-33.087 / src / Date.c next >
Text File  |  1994-04-13  |  116KB  |  4,657 lines

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