home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 3 / Meeting_Pearls_III.iso / Pearls / dev / Libraries / Date / src / Date.c < prev    next >
Encoding:
Text File  |  1995-07-31  |  192.3 KB  |  6,892 lines

  1. /* Date / Copyright 1994-95 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.158 (29.07.95)
  9. *
  10. *   HISTORY
  11. *    16.01.1994 -    Procedures: JulianLeapYear(), GregorianLeapYear() &
  12. *            HeisLeapYear() initiated.
  13. *    22.01.1994 -    Procedures: JulianMonthDays(), GregorianMonthDays(),
  14. *            HeisMonthDays(), JulianYearDays(),
  15. *            GregorianYearDays(), HeisYearDays(), JulianDayDiff(),
  16. *            GregorianDayDiff(), HeisDayDiff(),
  17. *            JulianDaySmaller(), GregorianDaySmaller(),
  18. *            HeisDaySmaller(), JulianWeekday(),
  19. *            GregorianWeekday(), HeisWeekday(),
  20. *            JulianDaysBeforeWeekday(),
  21. *            GregorianDaysBeforeWeekday(),
  22. *            HeisDaysBeforeWeekday(), JulianDaysAfterWeekday(),
  23. *            GregorianDaysAfterWeekday(), HeisDaysAfterWeekday(),
  24. *            JulianDiffDate(), FreeDate() initiated.
  25. *            Types: Weekdays, Date, DatePtr initiated.
  26. *            Vars of Gregorian reform initiated
  27. *            (for changing to different countries)
  28. *    23.01.1994 -    Procedures: JulianDiffDate() finished,
  29. *            GregorianDiffDate(), HeisDiffDate(),
  30. *            JYearToScaliger(), GYearToScaliger(),
  31. *            HYearToScaliger(), ScaligerYearToJ(),
  32. *            ScaligerYearToG(), ScaligerYearToH(), JSYearToJD(),
  33. *            GSYearToJD(), HSYearToJD(), JDtoMJD(), MJDtoJD(),
  34. *            JulianToJD(), GregorianToJD(), HeisToJD(),
  35. *            TimeToJD(), JDToTime(), FreeTime() initiated.
  36. *            Types: Time, TimePtr initiated.
  37. *    28.01.1994 -    Procedures: GregorianMoonAge(), MoonMonthAge(),
  38. *            GregorianEaster() initiated.
  39. *    30.01.1994 -    Procedures: JulianDiffDate(), GregorianDiffDate(),
  40. *            HeisDiffDate(), JDToTime(), GregorianEaster() edited
  41. *            (changing return value from ptr to VAL variables).
  42. *            Procedures: FreeDate(), FreeTime() deleted.
  43. *            Types: Date, DatePtr, Time, TimePtr deleted (not
  44. *            longer needed, because of the procedure changes).
  45. *            Procedures: GregorianMoonAge(), GregorianEaster()
  46. *            changed    year parameter from CARDINAL to INTEGER
  47. *            (this is more consistent to the rest of the library).
  48. *            Bugs removed: GregorianWeekday(), HeisWeekday()
  49. *            (before removing, the weekday for leapyears was
  50. *            wrong)
  51. *            Procedure: GregorianEaster() finished.
  52. *            Ported to Oberon-2
  53. *    31.01.1994 -    Compiled with Oberon-2 V3.11
  54. *    12.02.1994 -    Procedures: TimeZoneFactor(), LMT(), TimeToSec(),
  55. *            SecToTime() initiated.
  56. *            Version-String installed :)
  57. *            Starting translation to SAS C 6.51:
  58. *            Date.h translated
  59. *    13.02.1994 -    Continuation of C translation
  60. *    17.02.1994 -    New Oberon-2 Port, because Daniel Amor gave me a
  61. *            small hint about the SHORT command
  62. *            (I did not know about this!)
  63. *            Small bug in Autodocs removed
  64. *            making this text as Date/--history-- autodoc
  65. *            Continuation of C translation
  66. *    18.02.1994 -    Finished with C translation
  67. *    19.02.1994 -    C bugs removed (thanks to SAS for helping a
  68. *            C greenhorn like me!), some optimizations done also.
  69. *            Oberon-2 version compiled with V40.17 includes
  70. *    21.02.1994 -    Starting to write Modula-II testmodule
  71. *            Vars for the begining of Heis calculation initiated.
  72. *            Fixed small bugs in GregorianWeekday(),
  73. *            HeisWeekday(), TimeToSec(), SecToTime()
  74. *            Return-value of LMT() changed to LONGINT!
  75. *            Converting testmodule to Oberon-2
  76. *    22.02.1994 -    Converting testmodule to C
  77. *    23.02.1994 -    I noticed, that I forgot the 3 functions
  78. *            JulianWeek(), GregorianWeek(), HeisWeek()
  79. *    24.02.1994 -    Initiated the 3 forgotten functions
  80. *    26.02.1994 -    Initiating new GregorianEaster() with
  81. *            Gauß-algorithms    but ONLY for 1900-2099!
  82. *    27.02.1994 -    Bug fixed in JulianWeekday()
  83. *            Bugs fixed in JulianDayDiff(), GregorianDayDiff(),
  84. *            HeisDayDiff()
  85. *            JulianDayGreater(), GregorianDayGreater(),
  86. *            HeisDayGreater() Initiated.
  87. *    02.03.1994 -    Small bug fixed in HeisDayDiff()
  88. *            Bugs from 27.02. fixed in Modula-II and Oberon-2
  89. *            versions
  90. *            I found the way to extend GregorianEaster() !
  91. *            Small bug fixed in JulianWeek(), GregorianWeek(),
  92. *            HeisWeek() (~(M2) is not !(C))
  93. *    05.03.1994 -    Some internal bugs removed
  94. *            New internal procedures GregorianSB(),
  95. *            GregorianJHSB(), GregorianJHStartSB() !
  96. *            Extending GregorianEaster() :)
  97. *    11.03.1994 -    Things from 05.03. done in Modula-II and Oberon
  98. *    12.03.1994 -    If __SASC is defined autoinitialization instead of
  99. *            _DateInit() will be used!
  100. *    13.03.1994 -    After studying the SAS C Manual again I decided to
  101. *            check for __SASC_650 instead of __SASC because of
  102. *            the available priorities!
  103. *            Setting the priority of _DateInit() for
  104. *            autoinitialization to 600!
  105. *    15.03.1994 -    Making Date as library
  106. *    16.03.1994 -    Some work on the Autodocs was done,
  107. *            eliminating OldGregorianEaster() by comments
  108. *            (ANSI: STOP bad standards like that there are NO
  109. *             nested comments possible in C!!!).
  110. *    19.03.1994 -    Some work on the Autodocs was done in the M2 Code.
  111. *    20.03.1994 -    Some work on the Autodocs was done in the Oberon Code
  112. *    22.03.1994 -    In JDtoMJD(), MJDtoJD() an L was added to the
  113. *            constant.
  114. *            In GregorianWeekday(), HeisWeekday(),
  115. *            JulianDiffDate(), GregorianDiffDate(),
  116. *            HeisDiffDate(), JDToTime() I have inserted
  117. *            conversions (found with Borland C++ 4.0).
  118. *    24.03.1994 -    Making SunOS4.1.3, SunOS5.3(Solaris2.3) &
  119. *            RS6000 AIX3.2.? binaries with gcc.
  120. *            Eliminating nested commends by inserting a space
  121. *            between / and * (I hate this ANSI C standard
  122. *            feature for commends :(
  123. *    27.03.1994 -    Adding library register assignments to the autodocs.
  124. *    03.04.1994 -    Small fixes for the SAS C++ Compiler
  125. *            Small bug fixed in the M2 version of
  126. *            GregorianEaster()
  127. *    04.04.1994 -    Adding some 'static' keywords.
  128. *    10.04.1994 -    Changing from Shareware to Gift Ware ;-)
  129. *    02.08.1994 -    Small fixes in the Autodocs (thanks to Rita Reichl
  130. *            for correcting my bad english ;-)
  131. *    11.08.1994 -    Again small fixes in the Autodocs!
  132. *    13.11.1994 -    Small fix in JulianWeek(),GregorianWeek(),HeisWeek().
  133. *            Thanks to Jim Rickman for reporting the bug!
  134. *            Small changes in the Autodocs!
  135. *    30.11.1994 -    Fix the bug from 13.11. in M2 and Oberon code.
  136. *    04.12.1994 -    Small fixes in the C-Autodocs.
  137. *    12.12.1994 -    Adding WeekdayText(), MonthText() and internal
  138. *            max().
  139. *    13.12.1994 -    Optimizing WeekdayText() and MonthText()
  140. *    14.12.1994 -    Adding WeekdayShortText() and MonthShortText(),
  141. *            and fixing the french text.
  142. *    17.12.1994 -    Two small changes in the copyright conditions!
  143. *    18.12.1994 -    Fix for Amiga init library
  144. *    10.01.1995 -    Installing TurboText 2.0
  145. *    11.01.1995 -    Found a new (German) book!
  146. *    13.01.1995 -    Introducing release history
  147. *    14.01.1995 -    Introducing to do list
  148. *    15.01.1995 -    Procedures: JDToJulian(), JDToGregorian(),
  149. *            JDToHeis() as dummy, JulianEaster() initiated.
  150. *            Procedure: OldGregorianEaster() removed.
  151. *            Initiating an alternate GregorianEaster() and a
  152. *            dummy HeisEaster().
  153. *    16.01.1995 -    Procedure: GregorianMoonPhase initiated.
  154. *            I decided not longer to support Modula-II and Oberon
  155. *            version, until someone asks for it!
  156. *    17.01.1995 -    Internal procedure: GregorianMoonPhaseHelp.
  157. *            Adding a note to the background.
  158. *            Correcting small bug in autodocs.
  159. *    18.01.1995 -    Found a new (German) book!
  160. *    20.01.1995 -    Rita Reichl found David F. Skoll's Reminder3.0 -
  161. *            I was so impressed, that I could not continue my
  162. *            work for one day ;-)
  163. *    21.01.1995 -    I decided to distribute my TextEngine with the date
  164. *            library, when I have finished it.
  165. *    28.01.1995 -    Adding 'static' to GregorianMoonPhaseHelp.
  166. *            Fixing a very small bug.
  167. *    01.02.1995 -    Replacing JulianDaySmaller(), GregorianDaySmaller(),
  168. *            HeisDaySmaller(), JulianDayGreater(),
  169. *            GregorianDayGreater(), HeisDayGreater() with the new
  170. *            CompareDates()!
  171. *            Procedure: CompareTimes() initiated.
  172. *    04.02.1995 -    Adding some things to the autodocs.
  173. *    07.02.1995 -    Small fixes in the autodocs, and changing * to
  174. *            *const for JulianDiffDate(), GregorianDiffDate(),
  175. *            HeisDiffDate(),JDToTime(),SecToTime(),WeekdayText(),
  176. *            MonthText(),WeekdayShortText(),MonthShortText(),
  177. *            JulianEaster(),GregorianEaster(),HeisEaster(),
  178. *            JDToJulian(),JDToGregorian(),JDToHeis().
  179. *            Adding const to WeekdayText(),MonthText(),
  180. *            WeekdayShortText(),MonthShortText(), maximum().
  181. *            Adding C++ support to SecToTime(), JDToTime(),
  182. *            JDToJulian(), JDToGregorian(), JDToHeis(),
  183. *            JulianEaster(), GregorianEaster(), HeisEaster(),
  184. *            JulianDiffDate(), GregorianDiffDate(),HeisDiffDate(),
  185. *            GregorianMoonPhase()
  186. *            Changing the order of #ifdef headers.
  187. *            Fixing type conversion bugs (found with C++)
  188. *    17.02.1995 -    I good a hint about Jean-Michel Leon's 'K-lendars'
  189. *            nice thing ;-)
  190. *    18.02.1995 -    More languages for WeekdayText(), WeekdayShortText(),
  191. *            MonthText(), MonthShortText()
  192. *            Procedures DateText() ValidTime() initiated.
  193. *            Bug in WeekdayText(), WeekdayShortText(),
  194. *            MonthText(), MonthShortText() fixed
  195. *            Procedures: ValidJulianDate(), ValidGregorianDate(),
  196. *            ValidHeisDate() as dummys initiated.
  197. *    19.02.1995 -    Procedures: ValidJulianDate(), ValidGregorianDate(),
  198. *            ValidHeisDate() finished.
  199. *            Procedure SetCountry() initiated.
  200. *    24.02.1995 -    Rita Reichl corrects my bad English - again *THANX*
  201. *    26.02.1995 -    Adding Polish and Finnish support (not public)
  202. *    27.02.1995 -    Renaming CompareDates() to Compare2Dates() and
  203. *            CompareTimes() to Compare2Times() because there is an
  204. *            conflict with AmigaDOS!
  205. *    28.02.1995 -    To-Do list is not longer internal.
  206. *    07.03.1995 -    I got the three magic books :) thanx to Rita Reichl!
  207. *    09.03.1995
  208. *    12.03.1995 -    These two days I was at CeBit in Hannover!
  209. *            Whatever I observed and whatever material I acquired
  210. *            will change some things for commercial distribution
  211. *            (I was so uninformed and naive ;-)
  212. *    16.03.1995 -    Some work and corrections on the autodocs.
  213. *    20.03.1995 -    Compiled with SAS C 6.55
  214. *    21.03.1995 -    Fixing C++ abs() problem!
  215. *            (I don't know why SAS means that this is a problem!)
  216. *    23.03.1995 -    Fixing following things:
  217. *            Adding 'L' to the constant in JDToGregorian()
  218. *            Removing three conditions from ValidTime().
  219. *            maximum() is only needed for Amiga code!
  220. *            GregorianJHSB(), GregorianSB() is not longer needed.
  221. *            Thanx to Christian Schaefer for finding this
  222. *            things with Borland C++!
  223. *    24.03.1995 -    I read, that the Julian Calendar is stabel from
  224. *            8 on and not from -7, so I corrected the autodocs!
  225. *    31.03.1995 -    Some work on DateText().
  226. *            Reformating the DISCLAIMER to autodoc style.
  227. *    01.04.1995 -    Moving TimeToJD(), JDToTime(), TimeZoneFactor(),
  228. *            LMT(), TimeToSec(), SecToTime(), Compare2Times(),
  229. *            ValidTime() to Date_Time.c (this is no April fool ;-)
  230. *    06.04.1995 -    Minor work on the autodocs.
  231. *    07.04.1995 -    Adding prototype for _DateCleanup() to Date.h.
  232. *            GregorianSZ() is not longer needed.
  233. *            Thanks to Christian Schaefer for reporting this bugs!
  234. *    14.05.1995 -    New copyright notice!
  235. *    19.05.1995 -    Rita Reichl corrects my bad English.
  236. *    23.05.1995 -    Writing announcement.
  237. *    01.06.1995 -    Correcting announcement and including it in the
  238. *            autodocs.
  239. *    03.06.1995 -    Procedures: TimeDiff(), DiffTime() initiated.
  240. *            Fixing small bugs in datetest.c and implementing
  241. *            C++ support
  242. *    09.06.1995 -    Writing Installer script (Amiga only)
  243. *    14.06.1995 -    Small fixes in GregorianEaster(), GregorianEP(),
  244. *            GSYearToJD(), GregorianWeekday(), GregorianDayDiff(),
  245. *            HeisDayDiff()
  246. *    18.06.1995 -    Again small fixes in GregorianDayDiff(),
  247. *            HeisDayDiff()
  248. *    28.06.1995 -    Small Autodoc fixes
  249. *    08.07.1995 -    Fixing bug in DiffTime()
  250. *    14.07.1995 -    Workaround, for a SAS C++ problem.
  251. *            Thanks to James Cooper for the hint.
  252. *    18.07.1995 -    Fixing 'is long constant' warnings in Date_Time.h
  253. *            Fixing two missed enum's for the C++ workaround.
  254. *    28.07.1995 -    Shortening the year of the version-string to 95,
  255. *            because the Amiga 'version' command is buggy!
  256. *    29.07.1995 -    Expanding announcement for DateClass.
  257. *
  258. *****************************************************************************
  259. *
  260. *
  261. */
  262.  
  263. /*
  264. ******* Date/--release-- ****************************************************
  265. *
  266. *   NAME
  267. *    release -- This is the release history of the Date module
  268. *
  269. *   RELEASE
  270. *    13.04.1994 : 33.087 -    V1.0 First release on Aminet3 & SaarAG 707
  271. *    13.08.1994 : 33.088 -    V1.1 Second release on Aminet4, SaarAG 793,
  272. *                     Fred Fish & SimTel
  273. *    18.12.1994 : 33.093 -    V1.2 Third release on Aminet
  274. *    06.02.1995 : 33.100 -    V1.3 Fourth release on Aminet, Amiga-PD-1
  275. *    01.08.1995 : 33.158 -    V1.4 Fifth release on Aminet, SaarAG,
  276. *                     Fred Fish & SimTel
  277. *
  278. *****************************************************************************
  279. *
  280. *
  281. */
  282.  
  283. /*
  284. ******* Date/--todo-- *******************************************************
  285. *
  286. *   NAME
  287. *    todo -- This is the 'To-Do' list of the Date module
  288. *
  289. *   TODO
  290. *    DateText() plural strings
  291. *    Country strings for TextEngine
  292. *    (Local catalog (Amiga only))
  293. *    A function to compare date/time of different time zones!
  294. *    DATE/ECHO like shell command
  295. *    Country dependend for 1582
  296. *    Rising/setting of moon and sun
  297. *    Parser for datestrings
  298. *    EVAL like shell command
  299. *    Tcl interface
  300. *    Other calenders, like the Islamic and the Jewish
  301. *
  302. *****************************************************************************
  303. *
  304. *
  305. */
  306.  
  307. /*
  308. ******* Date/--announce-- ***************************************************
  309. *
  310. *   TITLE
  311. *    date.library
  312. *
  313. *   VERSION
  314. *    33.158
  315. *
  316. *   RELEASE DATE
  317. *    01.08.1995
  318. *
  319. *   AUTHOR
  320. *    Kai Hofmann (i07m@zfn.uni-bremen.de)
  321. *                (http://www.informatik.uni-bremen.de/~i07m)
  322. *
  323. *   DESCRIPTION
  324. *    A portable ANSI-C/C++ library that gives you low level functions for
  325. *    date calculations.
  326. *    Includes the following features:
  327. *
  328. *    - Support for six different date/time measurement systems:
  329. *      Julian, Gregorian, Heis, Julian Day, Modified Julian Day,
  330. *      Scaliger Year (other systems will follow).
  331. *    - Month/Weekday and other date/time string support for 12 languages.
  332. *    - Support for different countries (implementation not finished!).
  333. *    - Calculating leap years.
  334. *    - Functions to calculate the days of a month or a year or between
  335. *      two dates.
  336. *    - Functions to calculate the weeknumber and the weekday.
  337. *    - Check the validity of a date.
  338. *    - Calculating Easter.
  339. *    - Comparing dates.
  340. *    - Powerfull functions to handle differences between dates.
  341. *    - Transformations from one time measurement system to the others.
  342. *    - Calculating your local time zone out of your position on the earth.
  343. *    - Calculating the age of the moon and the moon phase.
  344. *    - Check the validity of a time.
  345. *    - Comparing times.
  346. *    - Transforming 24h time format into seconds and back.
  347. *    - Transforming 24h time format to Julian Day time format and back.
  348. *    - Powerfull textengine for creating date/time strings in different
  349. *      languages, that supports nearly all features of the date library.
  350. *    - A C++ class concept, which makes it very easy to use the complex
  351. *      functionality of the date library.
  352. *    - Autodoc describing all functions in the library.
  353. *    - Including ANSI-C/C++ sources and test example.
  354. *
  355. *   NEW FEATURES
  356. *    - Better code
  357. *    - Bug fixes
  358. *    - More C++ support
  359. *    - Fixing type conversion bugs
  360. *    - Better Autodocs
  361. *    - Supporting more languages
  362. *    - Functions for checking validity of dates/times
  363. *    - Julian calendar is stable since 8 and NOT since -7!
  364. *    - Textengine
  365. *    - DateClass (basic concept)
  366. *
  367. *   SPECIAL REQUIREMENTS
  368. *    ANSI-C or/and C++ Compiler.
  369. *
  370. *   AVAILABILITY
  371. *    ftp://wuarchive.wustl.edu/pub/aminet/dev/c/date.lha
  372. *    And all other Aminet sites.
  373. *
  374. *    ftp://OAK.Oakland.Edu/pub/SimTel/msdos/c/kh-date.zip
  375. *    And all other SimTel sites.
  376. *
  377. *    Actual beta versions (for all systems) are available from:
  378. *    ftp://ftp.uni-bremen.de/pub/amiga/date/
  379. *
  380. *   PRICE
  381. *    For NON-COMMERCIAL USE this is Giftware!
  382. *    (Non-commercial includes Giftware and Shareware!)
  383. *
  384. *    Permission for COMMERCIAL USE is only given by an extra available
  385. *    commercial license that must be validated!
  386. *    Contact me directly for this license, because it will be individually
  387. *    handed out per your needs!
  388. *
  389. *    But in both cases you have to follow the two guidelines below:
  390. *
  391. *    1) You *must* include the following notice in your product and in
  392. *       your documentation:
  393. *       "This software uses the date library that is copyrighted 1994-95
  394. *        by Kai Hofmann"
  395. *
  396. *    2) You "must" send me a full version of your product at no cost
  397. *       including free updates!
  398. *
  399. *   DISTRIBUTION
  400. *    You can copy and distribute this library as long as you do not take
  401. *    more than $5 for one disk or $40 for one CD!
  402. *
  403. *****************************************************************************
  404. *
  405. *
  406. */
  407.  
  408. /*
  409. ******* Date/--compiling-- **************************************************
  410. *
  411. *   NAME
  412. *    compiling -- Specials for compiling the date library.
  413. *
  414. *   COMPILING
  415. *    - You could compile this code as normal C or as C++
  416. *    - _AMIGA, __SASC_650, __MakeLib are Amiga only pp defines!
  417. *    - _ISO8859_Latin1 should be defined if your system supports this
  418. *      font encoding technology!
  419. *    - Date_Time.c will be included automatically!
  420. *
  421. *****************************************************************************
  422. *
  423. *
  424. */
  425.  
  426. /*
  427. ******* Date/--background-- *************************************************
  428. *
  429. *   NAME
  430. *    Date -- This module was designed in helping calc.calendar dates (V33)
  431. *
  432. *   FUNCTION
  433. *    This module has been designed to become a useful and portable library
  434. *    and to help developers calculate calendar dates!
  435. *
  436. *   NOTES
  437. *    A tropical year is 365.2422 days! / 365d, 5h, 48min, 46sec
  438. *    A moon month is 29.53059 days! / 29d, 12h, 44min, 2.9 sec
  439. *    A moon phase is 7.38265 days!
  440. *    The calculations are historical and NOT astronomical!
  441. *
  442. *    (German) Books which were consulted in creating this library:
  443. *        Kleine Naturwissenschaftliche Bibliothek, Band 23
  444. *        Ewige Kalender
  445. *        A.W. Butkewitsch & M.S. Selikson
  446. *        5. Auflage
  447. *        Teubner, Leipzig 1974
  448. *        ISBN 3-322-00393-0
  449. *
  450. *        Tag und Woche, Monat und Jahr: eine Kulturgeschichte des
  451. *        Kalenders
  452. *        Rudolf Wendorff
  453. *        Westdeutscher, Opladen 1993
  454. *        ISBN 3-531-12417-X
  455. *
  456. *        Kalender und Chronologie: Bekanntes & Unbekanntes aus der
  457. *        Kalenderwissenschaft
  458. *        Heinz Zemanek
  459. *        4. Auflage
  460. *        Oldenbourg, München 1987
  461. *        ISBN 3-486-20447-5
  462. *
  463. *        Meyers Handbuch
  464. *        über das Weltall
  465. *        Karl Schaifers & Gerhard Traving
  466. *        5. Auflage
  467. *        Bibliographisches Institut, Mannheim 1973
  468. *        ISBN 3-411-00940-3
  469. *
  470. *        Astronomische Algorithmen
  471. *        Jean Meeus
  472. *        2. Auflage
  473. *        Johann Ambrosius Barth, Berlin 1994
  474. *        ISBN 3-335-00400-0
  475. *
  476. *        Astronomie mit dem Personal Computer
  477. *        Oliver Montenbruck & Thomas Pfleger
  478. *        2. Auflage
  479. *        Springer, Berlin 1994
  480. *        ISBN 3-540-57701-7
  481. *
  482. *        Handbuch der mathematischen und technischen Chronologie
  483. *        Das Zeitrechnungswesen der Völker
  484. *        Band I
  485. *        F. K. Ginzel
  486. *        1. Auflage
  487. *        J. C. Hinrichs'sche Buchhandlung, Leipzig 1906
  488. *
  489. *        Handbuch der mathematischen und technischen Chronologie
  490. *        Das Zeitrechnungswesen der Völker
  491. *        Band II
  492. *        F. K. Ginzel
  493. *        1. Auflage
  494. *        J. C. Hinrichs'sche Buchhandlung, Leipzig 1911
  495. *
  496. *        Handbuch der mathematischen und technischen Chronologie
  497. *        Das Zeitrechnungswesen der Völker
  498. *        Band III
  499. *        F. K. Ginzel
  500. *        1. Auflage
  501. *        J. C. Hinrichs'sche Buchhandlung, Leipzig 1914
  502. *
  503. *    (English) Books which were consulted in creating this library:
  504. *        Mathematical Astronomy with a Pocket Calculator
  505. *        Aubrey Jones Fras
  506. *        Unknown (first) Edition
  507. *        David & Charles Newton Abbot, London 1978
  508. *        ISBN 0-7153-7675-6
  509. *
  510. *        Astronomical Algorithms
  511. *        Jean Meeus
  512. *        Unknown Edition (I use the German second edition ;-)
  513. *        Willmann-Bell, Inc., Ruchmond, Virginia (USA) 1991
  514. *        ISBN 0-943396-35-2
  515. *
  516. *   COPYRIGHT
  517. *    This software is copyrighted 1994-95 by Kai Hofmann.
  518. *    All rights reserved!
  519. *
  520. *    - Permission for COMMERCIAL USE is only given by an extra available
  521. *      commercial license that must be validated!
  522. *      Contact me directly for this license, because it will be
  523. *      individually handed out per your needs!
  524. *
  525. *    - Permission is hereby granted, without written agreement and without
  526. *      license, to USE this software and its documentation for any
  527. *      NON-COMMERCIAL purpose, provided that the above copyright notice
  528. *      and the following paragraph appear in all copies of this software
  529. *      (Non-commercial includes Giftware and Shareware!).
  530. *
  531. *      You *must* include the following notice in your product and in your
  532. *      documentation:
  533. *      "This software uses the date library that is copyrighted 1994-95 by
  534. *       Kai Hofmann"
  535. *
  536. *      You "must" send me a full version of your product at no cost
  537. *      including free updates!
  538. *      Extra money is welcome (For Bank Account see below - but *ONLY*
  539. *      send in DM to this Bank Account!).
  540. *
  541. *    - THERE IS *NO PERMISSION* GIVEN TO MODIFY THIS SOFTWARE!
  542. *
  543. *      If you need only parts of this software, you should not worry,
  544. *      because it's the job of the optimizer from your C compiler to
  545. *      include only the needed parts in your executable!
  546. *
  547. *   DISCLAIMER
  548. *    THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
  549. *    APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
  550. *    HOLDER AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
  551. *    WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
  552. *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  553. *    A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
  554. *    PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
  555. *    DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
  556. *    CORRECTION.
  557. *
  558. *    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
  559. *    WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY REDISTRIBUTE
  560. *    THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
  561. *    INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
  562. *    ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING
  563. *    BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
  564. *    LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
  565. *    TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
  566. *    PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  567. *
  568. *    THE AUTHOR HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
  569. *    UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  570. *
  571. *   DISTRIBUTION
  572. *    Permission is hereby granted, without written agreement and without
  573. *    license or royalty fees, to copy and distribute this software and its
  574. *    documentation for any purpose, provided that the above copyright
  575. *    notice and the following paragraphs appear in all copies of this
  576. *    software, to:
  577. *    - All who will distribute this software for free!
  578. *    - All free accessible INTERNET servers and PHONE boxes!
  579. *    - All Aminet sites
  580. *    - All SimTel sites
  581. *    - Fred Fish for his great Amiga-Software-Library
  582. *    - The German SAAR AG PD-Library
  583. *    - All others who do NOT take more than $5.- for one disk that
  584. *      includes this software!
  585. *    - ALL others who do NOT take more than $40.- for one CD that includes
  586. *      this software!
  587. *
  588. *   ADDITIONAL INFORMATIONS
  589. *    I have tried to make portable/useful and I hope bugfree software
  590. *    for eternity - but this seems to be impossible (sorry!) :)
  591. *    So I hope you will pay a fee for this.
  592. *
  593. *    Kindly send US - dollars to a friend of mine in the USA who will
  594. *    forward it to me in a timely manner.  Please send checks or money
  595. *    orders only.
  596. *    Contact me via email for more!
  597. *
  598. *   AUTHOR
  599. *    Kai Hofmann
  600. *    Arberger Heerstraße 92
  601. *    28307 Bremen
  602. *    Germany
  603. *
  604. *    Phone: (+49)-(0)421/480780
  605. *           (Remember that my parents don't speak english!)
  606. *    EMail: i07m@zfn.uni-bremen.de
  607. *           i07m@informatik.uni-bremen.de
  608. *    IRC  : PowerStat@#AmigaGer
  609. *    WWW  : http://www.informatik.uni-bremen.de/~i07m
  610. *
  611. *    Bank account : 1203 7503
  612. *    Account owner: Kai Hofmann
  613. *    Bank code    : 290 501 01
  614. *    Bank name    : Sparkasse in Bremen/Germany
  615. *
  616. *    THANKS
  617. *    Thank you's are going to the following people:
  618. *    Daniel Amor        - For his hint about the Oberon-2 SHORT
  619. *                  command
  620. *    Rita Reichl        - For correcting my bad english (very often)
  621. *                  and for the three magic books *kiss*
  622. *    Jim Rickman        - For reporting a bug
  623. *    Christian Schaefer    - For spending time on this lib with his
  624. *                  Borland C++ 4.5 compiler
  625. *    Heinz Zemanek        - For his great book
  626. *    Jacco van Weert &
  627. *    Frans Slothouber    - For the 'Robodoc' utility
  628. *    James Cooper and the
  629. *    other Amiga people at
  630. *    SAS Intitute        - For spending their unpaid free time with
  631. *                  continuation of the Amiga SAS C/C++
  632. *                  support :)
  633. *
  634. *****************************************************************************
  635. *
  636. *
  637. */
  638.  
  639.  
  640.  #include <stdlib.h> /* abs()   */
  641.  #include <math.h>   /* floor() */
  642.  #include <string.h> /* strcpy(), strlen() */
  643.  #ifndef __SASC_650
  644.    #undef __MakeLib
  645.  #endif
  646.  #ifdef _AMIGA
  647.    #define _ISO8859_Latin1
  648.    #include <proto/exec.h>
  649.    #include <proto/locale.h>
  650.  #endif
  651.  #include "Date.h"
  652.  
  653.  
  654.  #ifdef _AMIGA
  655.    #ifdef __SASC_650
  656.      extern struct Library *LocaleBase;
  657.    #else
  658.      static struct Library *LocaleBase = NULL;
  659.    #endif
  660.    static struct Locale  *locale   = NULL;
  661.    static unsigned short  wlen     = 0, abwlen = 0,
  662.                           mlen     = 0, abmlen = 0;
  663.    static ULONG           DAYS[]   = {DAY_1,DAY_2,DAY_3,DAY_4,DAY_5,DAY_6,DAY_7},
  664.                           MONS[]   = {MON_1,MON_2,MON_3,MON_4,MON_5,MON_6,MON_7,MON_8,MON_9,MON_10,MON_11,MON_12},
  665.                           ABDAYS[] = {ABDAY_1,ABDAY_2,ABDAY_3,ABDAY_4,ABDAY_5,ABDAY_6,ABDAY_7},
  666.                           ABMONS[] = {ABMON_1,ABMON_2,ABMON_3,ABMON_4,ABMON_5,ABMON_6,ABMON_7,ABMON_8,ABMON_9,ABMON_10,ABMON_11,ABMON_12};
  667.    #ifdef __MakeLib
  668.      #include <exec/libraries.h>
  669.  
  670.      void __regargs __chkabort(void)
  671.       {}
  672.  
  673.      void __regargs _CXBRK(void)
  674.       {}
  675.    #endif
  676.  #endif
  677.  
  678.  
  679.  static Countries Country = unknown;
  680.  
  681.  static unsigned short    BeforeGregorianDay = 4,
  682.             BeforeGregorianMonth = 10,
  683.             AfterGregorianDay = 15,
  684.             AfterGregorianMonth = 10,
  685.             StartHeisDay = 1,
  686.             StartHeisMonth = 1;
  687.  static int        BeforeGregorianYear = 1582,
  688.             AfterGregorianYear = 1582,
  689.             StartHeisYear = 3200;
  690.  
  691.  /* ----------------------------------------------------------------------- */
  692.  
  693.  #ifndef __MakeLib
  694.    bool JulianLeapYear(const int year)
  695.  #else
  696.    bool __saveds __asm JulianLeapYear(register __d0 const int year)
  697.  #endif
  698.  
  699. /*
  700. ******* Date/JulianLeapYear *************************************************
  701. *
  702. *   NAME
  703. *    JulianLeapYear -- Checks if a year is a leap year. (V33)
  704. *
  705. *   SYNOPSIS
  706. *    leapyear = JulianLeapYear(year);
  707. *       d0               d0
  708. *
  709. *    bool JulianLeapYear(const int year);
  710. *
  711. *   FUNCTION
  712. *    JulianLeapYear checks if a year is a leap year in the Julian calendar
  713. *    For years after Chr. it checks if the year is devideable by 4.
  714. *    For years before Chr. a leap year must have a modulo 4 value of 1
  715. *
  716. *   INPUTS
  717. *    year - The year which should be checked (from -32768 to 32767)
  718. *        I think only values from 8 to 32767 are valid, because of
  719. *        the variant that was done by Augustus!
  720. *
  721. *   RESULT
  722. *    leapyear - TRUE if the year is a leap year, otherwise false.
  723. *
  724. *   EXAMPLE
  725. *    ...
  726. *    if (JulianLeapYear(1994))
  727. *      printf("leap year!\n");
  728. *    else
  729. *      printf("no leap year!\n");
  730. *    ...
  731. *
  732. *   NOTES
  733. *    A year is 365.25 days long!
  734. *    Use this function only for values from 8 to 1582!
  735. *
  736. *   BUGS
  737. *    No known bugs.
  738. *
  739. *   SEE ALSO
  740. *    GregorianLeapYear(),HeisLeapYear()
  741. *
  742. *****************************************************************************
  743. *
  744. *
  745. */
  746.  
  747.   {
  748.    if (year <= 0)
  749.      return((bool)((-year) % 4 == 1));
  750.    else
  751.      return((bool)(year % 4 == 0));
  752.   }
  753.  
  754.  
  755.  #ifndef __MakeLib
  756.    bool GregorianLeapYear(const int year)
  757.  #else
  758.    bool __saveds __asm GregorianLeapYear(register __d0 const int year)
  759.  #endif
  760.  
  761. /*
  762. ******* Date/GregorianLeapYear **********************************************
  763. *
  764. *   NAME
  765. *    GregorianLeapYear -- Checks if a year is a leap year. (V33)
  766. *
  767. *   SYNOPSIS
  768. *    leapyear = GregorianLeapYear(year);
  769. *       d0                  d0
  770. *
  771. *    bool GregorianLeapYear(const int year);
  772. *
  773. *   FUNCTION
  774. *    GregorianLeapYear checks if a year is a leap year.
  775. *    For years after 1582 all years devideable by 4 are leap years,
  776. *    without years devideable by 100, but years devideable by 400
  777. *    are leap years again!
  778. *    For years before 1582 see JulianLeapYear().
  779. *
  780. *   INPUTS
  781. *    year - The year which should be checked (from -32768 to 32767)
  782. *        I think only values from 8 to 3200 are valid, because of
  783. *        the variant that was done by Augustus!
  784. *
  785. *   RESULT
  786. *    leapyear - TRUE if the year is a leap year, otherwise false.
  787. *
  788. *   EXAMPLE
  789. *    ...
  790. *    if (GregorianLeapYear(1994))
  791. *      printf("leap year!\n");
  792. *    else
  793. *      printf("no leap year!\n");
  794. *    ...
  795. *
  796. *   NOTES
  797. *    A year is 365.2425 days long!
  798. *    Use this function only for values from 8 to 3199!
  799. *
  800. *   BUGS
  801. *    No known bugs.
  802. *
  803. *   SEE ALSO
  804. *    JulianLeapYear(),HeisLeapYear()
  805. *
  806. *****************************************************************************
  807. *
  808. *
  809. */
  810.  
  811.   {
  812.    if (year < BeforeGregorianYear)
  813.      {/* Year of the Gregorian reform */
  814.       return(JulianLeapYear(year));
  815.      }
  816.    else
  817.      {/* AfterGregorianYear reform */
  818.       return((bool)((year % 4 == 0) && ((year % 100 > 0) || (year % 400 == 0))));
  819.      }
  820.   }
  821.  
  822.  
  823.  #ifndef __MakeLib
  824.    bool HeisLeapYear(const int year)
  825.  #else
  826.    bool __saveds __asm HeisLeapYear(register __d0 const int year)
  827.  #endif
  828.  
  829. /*
  830. ******* Date/HeisLeapYear ***************************************************
  831. *
  832. *   NAME
  833. *    HeisLeapYear -- Checks if a year is a leap year. (V33)
  834. *
  835. *   SYNOPSIS
  836. *    leapyear = HeisLeapYear(year);
  837. *       d0             d0
  838. *
  839. *    bool HeisLeapYear(const int year);
  840. *
  841. *   FUNCTION
  842. *    HeisLeapYear checks if a year is a leap year.
  843. *    For years after 1582 see GregorianLeapYear(),
  844. *    The correction from N. Heis says, that all years devideable by
  845. *    3200 are no longer leap years!
  846. *    For years before 1582 see JulianLeapYear().
  847. *
  848. *   INPUTS
  849. *    year - The year which should be checked (from -32768 to 32767)
  850. *        I think only values from 8 to 32767 are valid, because of
  851. *        the variant that was done by Augustus!
  852. *
  853. *   RESULT
  854. *    leapyear - TRUE if the year is a leap year, otherwise false.
  855. *
  856. *   EXAMPLE
  857. *    ...
  858. *    if (HeisLeapYear(1994))
  859. *      printf("leap year!\n");
  860. *    else
  861. *      printf("no leap year!\n");
  862. *    ...
  863. *
  864. *   NOTES
  865. *    A year is now 365.2421875 days!
  866. *    Use this function only for values from 8 to 8000!
  867. *
  868. *   BUGS
  869. *    No known bugs.
  870. *
  871. *   SEE ALSO
  872. *    JulianLeapYear(),GregorianLeapYear()
  873. *
  874. *****************************************************************************
  875. *
  876. *
  877. */
  878.  
  879.   {
  880.    if (year < BeforeGregorianYear)
  881.      {/* Year of the Gregorian reform */
  882.       return(JulianLeapYear(year));
  883.      }
  884.    else
  885.      {/* year >= AfterGregorianYear */
  886.       if (year % 3200 == 0)
  887.         {/* Correction from N. Heis */
  888.          return(false);
  889.         }
  890.       else
  891.         {/* (no leap year all 3200 years) */
  892.          return(GregorianLeapYear(year));
  893.         }
  894.      }
  895.   }
  896.  
  897.  /* ----------------------------------------------------------------------- */
  898.  
  899.  #ifndef __MakeLib
  900.    unsigned short JulianMonthDays(const unsigned short month, const int year)
  901.  #else
  902.    unsigned short __saveds __asm JulianMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  903.  #endif
  904.  
  905. /*
  906. ******* Date/JulianMonthDays ************************************************
  907. *
  908. *   NAME
  909. *    JulianMonthDays -- Returns the number of days of a month. (V33)
  910. *
  911. *   SYNOPSIS
  912. *    days = JulianMonthDays(month,year);
  913. *     d0            d0    d1
  914. *
  915. *    unsigned short JulianMonthDays(const unsigned short month,
  916. *        const int year);
  917. *
  918. *   FUNCTION
  919. *    JulianMonthDays gives returns the number of days a month in
  920. *    a specified year has.
  921. *
  922. *   INPUTS
  923. *    month - The month from which you want to get the number of days.
  924. *    year  - The year in which the month is.
  925. *
  926. *   RESULT
  927. *    days - The number of days the month uses, or 0 if you use
  928. *        an incorrect month.
  929. *
  930. *   EXAMPLE
  931. *    ...
  932. *    days = JulianMonthDays(1,1994);
  933. *    printf("Days of January 1994 : %d\n",days);
  934. *    ...
  935. *
  936. *   NOTES
  937. *    It is better only to use this function for years from 8 to 09.1582!
  938. *
  939. *   BUGS
  940. *    No known bugs.
  941. *
  942. *   SEE ALSO
  943. *    JulianLeapYear(),GregorianMonthDays(),HeisMonthDays()
  944. *
  945. *****************************************************************************
  946. *
  947. *
  948. */
  949.  
  950.   {
  951.    switch (month)
  952.      {case  1 :
  953.       case  3 :
  954.       case  5 :
  955.       case  7 :
  956.       case  8 :
  957.       case 10 :
  958.       case 12 : return(31);
  959.       case  4 :
  960.       case  6 :
  961.       case  9 :
  962.       case 11 : return(30);
  963.       case  2 : if (JulianLeapYear(year))
  964.                   return(29);
  965.                 else
  966.                   if (!JulianLeapYear(year))
  967.                     return(28);
  968.       default : return(0);
  969.      }
  970.   }
  971.  
  972.  
  973.  #ifndef __MakeLib
  974.    unsigned short GregorianMonthDays(const unsigned short month, const int year)
  975.  #else
  976.    unsigned short __saveds __asm GregorianMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  977.  #endif
  978.  
  979. /*
  980. ******* Date/GregorianMonthDays *********************************************
  981. *
  982. *   NAME
  983. *    GregorianMonthDays -- Returns the number of days of a month. (V33)
  984. *
  985. *   SYNOPSIS
  986. *    days = GregorianMonthDays(month,year);
  987. *     d0               d0    d1
  988. *
  989. *    unsigned short GregorianMonthDays(const unsigned short month,
  990. *        const int year);
  991. *
  992. *   FUNCTION
  993. *    GregorianMonthDays returns the number of days a month in
  994. *    a specified year has.
  995. *    For the year 1582 and the month 10 there are only 21 days,
  996. *    because of the Gregorian-reform 10 days are deleted from
  997. *    the month (for more - look out for books about this!)
  998. *
  999. *   INPUTS
  1000. *    month - The month from which you want to get the number of days.
  1001. *    year  - The year in which the month is.
  1002. *
  1003. *   RESULT
  1004. *    days - The number of days the month uses, or 0 if you use
  1005. *        an incorrect month.
  1006. *
  1007. *   EXAMPLE
  1008. *    ...
  1009. *    days = GregorianMonthDays(1,1994);
  1010. *    printf("Days of January 1994 : %d\n",days);
  1011. *    ...
  1012. *
  1013. *   NOTES
  1014. *    Use this function only for years from 8 to 3199!
  1015. *
  1016. *   BUGS
  1017. *    none.
  1018. *
  1019. *   SEE ALSO
  1020. *    GregorianLeapYear(),JulianMonthDays(),HeisMonthDays()
  1021. *
  1022. *****************************************************************************
  1023. *
  1024. *
  1025. */
  1026.  
  1027.   {
  1028.    if ((year == AfterGregorianYear) && (month == AfterGregorianMonth))
  1029.      {/* 10 days canceled by Gregor XIII
  1030.                 in countries who chnaged later are more days */
  1031.       return((unsigned short)(31-((AfterGregorianDay-BeforeGregorianDay)-1)));
  1032.      }
  1033.    else
  1034.      if ((month == 2) && GregorianLeapYear(year))
  1035.        return(29);
  1036.      else
  1037.        if ((month == 2) && (!GregorianLeapYear(year)))
  1038.          return(28);
  1039.        else
  1040.          {/* use Julian function for other calcs. */
  1041.           return(JulianMonthDays(month,year));
  1042.          }
  1043.   }
  1044.  
  1045.  
  1046.  #ifndef __MakeLib
  1047.    unsigned short HeisMonthDays(const unsigned short month, const int year)
  1048.  #else
  1049.    unsigned short __saveds __asm HeisMonthDays(register __d0 const unsigned short month, register __d1 const int year)
  1050.  #endif
  1051.  
  1052. /*
  1053. ******* Date/HeisMonthDays **************************************************
  1054. *
  1055. *   NAME
  1056. *    HeisMonthDays -- Returns the number of days of a month. (V33)
  1057. *
  1058. *   SYNOPSIS
  1059. *    days = HeisMonthDays(month,year);
  1060. *     d0              d0    d1
  1061. *
  1062. *    unsigned short HeisMonthDays(const unsigned short month,
  1063. *        const int year);
  1064. *
  1065. *   FUNCTION
  1066. *    HeisMonthDays returns the number of days a month in
  1067. *    a specified year has.
  1068. *    For the year 1582 and the month 10 there are only 21 days,
  1069. *    because of the Gregorian-reform 10 days are deleted from
  1070. *    the month (for more - look out for books about this!)
  1071. *
  1072. *   INPUTS
  1073. *    month - The month from which you want to get the number of days.
  1074. *    year  - The year in which the month is.
  1075. *
  1076. *   RESULT
  1077. *    days - The number of days the month uses, or 0 if you use
  1078. *        an incorrect month.
  1079. *
  1080. *   EXAMPLE
  1081. *    ...
  1082. *    days = HeisMonthDays(1,1994);
  1083. *    printf("Days of January 1994 : %d\n",days);
  1084. *    ...
  1085. *
  1086. *   NOTES
  1087. *    Use this function only for years from 8 to 8000!
  1088. *
  1089. *   BUGS
  1090. *    See GregorianMonthDays!
  1091. *
  1092. *   SEE ALSO
  1093. *    HeisLeapYear(),JulianMonthDays(),GregorianMonthDays()
  1094. *
  1095. *****************************************************************************
  1096. *
  1097. *
  1098. */
  1099.  
  1100.   {
  1101.    if ((month == 2) && HeisLeapYear(year))
  1102.      return(29);
  1103.    else
  1104.      if ((month == 2) && (!HeisLeapYear(year)))
  1105.        return(28);
  1106.      else
  1107.        {/* use Gregorian function for other calcs */
  1108.         return(GregorianMonthDays(month,year));
  1109.        }
  1110.   }
  1111.  
  1112.  /* ----------------------------------------------------------------------- */
  1113.  
  1114.  #ifndef __MakeLib
  1115.    unsigned int JulianYearDays(const int year)
  1116.  #else
  1117.    unsigned int __saveds __asm JulianYearDays(register __d0 const int year)
  1118.  #endif
  1119.  
  1120. /*
  1121. ******* Date/JulianYearDays *************************************************
  1122. *
  1123. *   NAME
  1124. *    JulianYearDays -- Gives back the number of days in a year. (V33)
  1125. *
  1126. *   SYNOPSIS
  1127. *    days = JulianYearDays(year);
  1128. *     d0               d0
  1129. *
  1130. *    unsigned int JulianYearDays(const int year);
  1131. *
  1132. *   FUNCTION
  1133. *    JulianYearDays gives you back the number of days in
  1134. *    a specified year.
  1135. *
  1136. *   INPUTS
  1137. *    year  - The year in which to count the days.
  1138. *
  1139. *   RESULT
  1140. *    days - The number of days the year uses.
  1141. *
  1142. *   EXAMPLE
  1143. *    ...
  1144. *    days = JulianYearDays(1994);
  1145. *    printf("Days of 1994 : %d\n",days);
  1146. *    ...
  1147. *
  1148. *   NOTES
  1149. *    It is better only to use this function for years from 8 to 1581!
  1150. *
  1151. *   BUGS
  1152. *    No known bugs.
  1153. *
  1154. *   SEE ALSO
  1155. *    JulianMonthDays(),GregorianYearDays(),HeisYearDays()
  1156. *
  1157. *****************************************************************************
  1158. *
  1159. *
  1160. */
  1161.  
  1162.  {
  1163.   unsigned short month;
  1164.   unsigned int days=0;
  1165.  
  1166.   for (month=1;month<=12;month++)
  1167.     {/* add the days of all 12 month */
  1168.      days += JulianMonthDays(month,year);
  1169.     }
  1170.   return(days);
  1171.  }
  1172.  
  1173.  
  1174.  #ifndef __MakeLib
  1175.    unsigned int GregorianYearDays(const int year)
  1176.  #else
  1177.    unsigned int __saveds __asm GregorianYearDays(register __d0 const int year)
  1178.  #endif
  1179.  
  1180. /*
  1181. ******* Date/GregorianYearDays **********************************************
  1182. *
  1183. *   NAME
  1184. *    GregorianYearDays -- Gives back the number of days in a year. (V33)
  1185. *
  1186. *   SYNOPSIS
  1187. *    days = GregorianYearDays(year);
  1188. *     d0              d0
  1189. *
  1190. *    unsigned int GregorianYearDays(const int year);
  1191. *
  1192. *   FUNCTION
  1193. *    GregorianYearDays gives you back the number of days in
  1194. *    a specified year.
  1195. *
  1196. *   INPUTS
  1197. *    year  - The year in which to count the days.
  1198. *
  1199. *   RESULT
  1200. *    days - The number of days the year uses.
  1201. *
  1202. *   EXAMPLE
  1203. *    ...
  1204. *    days = GregorianYearDays(1994);
  1205. *    printf("Days of 1994 : %d\n",days);
  1206. *    ...
  1207. *
  1208. *   NOTES
  1209. *    It is better only to use this function for years from 8 to 3199!
  1210. *
  1211. *   BUGS
  1212. *    No known bugs.
  1213. *
  1214. *   SEE ALSO
  1215. *    GregorianMonthDays(),JulianYearDays(),HeisYearDays()
  1216. *
  1217. *****************************************************************************
  1218. *
  1219. *
  1220. */
  1221.  
  1222.  {
  1223.   unsigned short month;
  1224.   unsigned int days=0;
  1225.  
  1226.   for (month=1;month<=12;month++)
  1227.     {/* add the days of all 12 month */
  1228.      days += GregorianMonthDays(month,year);
  1229.     }
  1230.   return(days);
  1231.  }
  1232.  
  1233.  
  1234.  #ifndef __MakeLib
  1235.    unsigned int HeisYearDays(const int year)
  1236.  #else
  1237.    unsigned int __saveds __asm HeisYearDays(register __d0 const int year)
  1238.  #endif
  1239.  
  1240. /*
  1241. ******* Date/HeisYearDays ***************************************************
  1242. *
  1243. *   NAME
  1244. *    HeisYearDays -- Gives back the number of days in a year. (V33)
  1245. *
  1246. *   SYNOPSIS
  1247. *    days = HeisYearDays(year);
  1248. *     d0             d0
  1249. *
  1250. *    unsigned int HeisYearDays(const int year);
  1251. *
  1252. *   FUNCTION
  1253. *    HeisYearDays gives you back the number of days in
  1254. *    a specified year.
  1255. *
  1256. *   INPUTS
  1257. *    year  - The year in which to count the days.
  1258. *
  1259. *   RESULT
  1260. *    days - The number of days the year uses.
  1261. *
  1262. *   EXAMPLE
  1263. *    ...
  1264. *    days = HeisYearDays(1994);
  1265. *    printf("Days of 1994 : %d\n",days);
  1266. *    ...
  1267. *
  1268. *   NOTES
  1269. *    It is better only to use this function for years from 8 to 8000!
  1270. *
  1271. *   BUGS
  1272. *    No known bugs.
  1273. *
  1274. *   SEE ALSO
  1275. *    HeisMonthDays(),JulianYearDays(),GregorianYearDays()
  1276. *
  1277. *****************************************************************************
  1278. *
  1279. *
  1280. */
  1281.  
  1282.  {unsigned short month;
  1283.   unsigned int days=0;
  1284.  
  1285.   for (month=1;month<=12;month++)
  1286.     {/* add the days of all 12 month */
  1287.      days += HeisMonthDays(month,year);
  1288.     }
  1289.   return(days);
  1290.  }
  1291.  
  1292.  /* ----------------------------------------------------------------------- */
  1293.  
  1294.  #ifndef __MakeLib
  1295.    short Compare2Dates(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1296.  #else
  1297.    short __saveds __asm Compare2Dates(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)
  1298.  #endif
  1299.  
  1300. /*
  1301. ******* Date/Compare2Dates **************************************************
  1302. *
  1303. *   NAME
  1304. *    Compare2Dates -- Compares date1 with date2. (V33.100)
  1305. *
  1306. *   SYNOPSIS
  1307. *    compare = Compare2Dates(day1,month1,year1,day2,month2,year2);
  1308. *      d0             d0    d1    d2    d3    d4    d5
  1309. *
  1310. *    short Compare2Dates(const unsigned short day1,
  1311. *        const unsigned short month1, const int year1,
  1312. *        const unsigned short day2, const unsigned short month2,
  1313. *        const int year2);
  1314. *
  1315. *   FUNCTION
  1316. *    Compare2Dates compares date1 with date2.
  1317. *
  1318. *   INPUTS
  1319. *    day1   - day of the first date
  1320. *    month1 - month of the first date
  1321. *    year1  - year of the first date
  1322. *    day2   - day of the second date
  1323. *    month2 - month of the second month
  1324. *    year2  - year of the second date
  1325. *
  1326. *   RESULT
  1327. *    compare - -1 : date1 < date2
  1328. *           0 : date1 = date2
  1329. *           1 : date1 > date2
  1330. *
  1331. *   EXAMPLE
  1332. *    ...
  1333. *    if (Compare2Dates(18,9,1970,22,1,1994) == -1)
  1334. *      printf("<\n");
  1335. *    else
  1336. *      printf(">=\n");
  1337. *    ...
  1338. *
  1339. *   NOTES
  1340. *    It is better only to use this function for years from 8 to 8000!
  1341. *    There is no need for different versions for Julian, Gregorian and
  1342. *    Heis dates!
  1343. *
  1344. *   BUGS
  1345. *    There is no check if the dates are valid!
  1346. *
  1347. *   SEE ALSO
  1348. *    Compare2Times()
  1349. *
  1350. *****************************************************************************
  1351. *
  1352. *
  1353. */
  1354.  
  1355.  {
  1356.   if (year1 < year2)
  1357.     return(-1);
  1358.   else if (year1 > year2)
  1359.     return(1);
  1360.   else if (month1 < month2)
  1361.     return(-1);
  1362.   else if (month1 > month2)
  1363.     return(1);
  1364.   else if (day1 < day2)
  1365.     return(-1);
  1366.   else if (day1 > day2)
  1367.     return(1);
  1368.   else
  1369.     return(0);
  1370.  }
  1371.  
  1372.  /* ----------------------------------------------------------------------- */
  1373.  
  1374.  #ifndef __MakeLib
  1375.    bool JulianDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1376.  #else
  1377.    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)
  1378.  #endif
  1379.  
  1380. /*
  1381. *****i* Date/JulianDaySmaller ***********************************************
  1382. *
  1383. *   NAME
  1384. *    JulianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1385. *
  1386. *   SYNOPSIS
  1387. *    smaller = JulianDaySmaller(day1,month1,year1,day2,month2,year2);
  1388. *      d0                d0    d1    d2    d3    d4    d5
  1389. *
  1390. *    bool JulianDaySmaller(const unsigned short day1,
  1391. *        const unsigned short month1, const int year1,
  1392. *        const unsigned short day2, const unsigned short month2,
  1393. *        const int year2);
  1394. *
  1395. *   FUNCTION
  1396. *    JulianDaySmaller test if date1 is smaller than date2.
  1397. *
  1398. *   INPUTS
  1399. *    day1   - day of the first date
  1400. *    month1 - month of the first date
  1401. *    year1  - year of the first date
  1402. *    day2   - day of the second date
  1403. *    month2 - month of the second month
  1404. *    year2  - year of the second date
  1405. *
  1406. *   RESULT
  1407. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1408. *
  1409. *   EXAMPLE
  1410. *    ...
  1411. *    if (JulianDaySmaller(18,9,1970,22,1,1994))
  1412. *      printf("<\n");
  1413. *    else
  1414. *      printf(">=\n");
  1415. *    ...
  1416. *
  1417. *   NOTES
  1418. *    It is better only to use this function for years from 8 to 1582!
  1419. *    This function is not longer needed - use CompareDates() !
  1420. *
  1421. *   BUGS
  1422. *    No known bugs.
  1423. *
  1424. *   SEE ALSO
  1425. *    GregorianDaySmaller(),HeisDaySmaller(),CompareDates()
  1426. *
  1427. *****************************************************************************
  1428. *
  1429. *
  1430. */
  1431.  
  1432.  {
  1433.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == -1));
  1434.  }
  1435.  
  1436.  
  1437.  #ifndef __MakeLib
  1438.    bool GregorianDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1439.  #else
  1440.    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)
  1441.  #endif
  1442.  
  1443. /*
  1444. *****i* Date/GregorianDaySmaller ********************************************
  1445. *
  1446. *   NAME
  1447. *    GregorianDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1448. *
  1449. *   SYNOPSIS
  1450. *    smaller = GregorianDaySmaller(day1,month1,year1,day2,month2,year2);
  1451. *      d0                   d0    d1    d2    d3    d4    d5
  1452. *
  1453. *    bool GregorianDaySmaller(const unsigned short day1,
  1454. *        const unsigned short month1, const int year1,
  1455. *        const unsigned short day2, const unsigned short month2,
  1456. *        const int year2);
  1457. *
  1458. *   FUNCTION
  1459. *    GregorianDaySmaller test if date1 is smaller than date2.
  1460. *
  1461. *   INPUTS
  1462. *    day1   - day of the first date
  1463. *    month1 - month of the first date
  1464. *    year1  - year of the first date
  1465. *    day2   - day of the second date
  1466. *    month2 - month of the second month
  1467. *    year2  - year of the second date
  1468. *
  1469. *   RESULT
  1470. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1471. *
  1472. *   EXAMPLE
  1473. *    ...
  1474. *    if (GregorianDaySmaller(18,9,1970,22,1,1994))
  1475. *      printf("<\n");
  1476. *    else
  1477. *      printf(">=\n");
  1478. *    ...
  1479. *
  1480. *   NOTES
  1481. *    It is better only to use this function for years from 8 to 3200!
  1482. *    This function is not longer needed - use CompareDates() !
  1483. *
  1484. *   BUGS
  1485. *    No known bugs.
  1486. *
  1487. *   SEE ALSO
  1488. *    JulianDaySmaller(),HeisDaySmaller(),CompareDates()
  1489. *
  1490. *****************************************************************************
  1491. *
  1492. *
  1493. */
  1494.  
  1495.  {
  1496.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == -1));
  1497.  }
  1498.  
  1499.  
  1500.  #ifndef __MakeLib
  1501.    bool HeisDaySmaller(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1502.  #else
  1503.    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)
  1504.  #endif
  1505.  
  1506. /*
  1507. *****i* Date/HeisDaySmaller *************************************************
  1508. *
  1509. *   NAME
  1510. *    HeisDaySmaller -- Checks if date1 is smaller than date2. (V33)
  1511. *
  1512. *   SYNOPSIS
  1513. *    smaller = HeisDaySmaller(day1,month1,year1,day2,month2,year2);
  1514. *      d0              d0    d1    d2    d3    d4    d5
  1515. *
  1516. *    bool HeisDaySmaller(const unsigned short day1,
  1517. *        const unsigned short month1, const int year1,
  1518. *        const unsigned short day2, const unsigned short month2,
  1519. *        const int year2);
  1520. *
  1521. *   FUNCTION
  1522. *    HeisDaySmaller test if date1 is smaller than date2.
  1523. *
  1524. *   INPUTS
  1525. *    day1   - day of the first date
  1526. *    month1 - month of the first date
  1527. *    year1  - year of the first date
  1528. *    day2   - day of the second date
  1529. *    month2 - month of the second month
  1530. *    year2  - year of the second date
  1531. *
  1532. *   RESULT
  1533. *    smaller - This is TRUE is date1 < date2 otherwise it's FALSE.
  1534. *
  1535. *   EXAMPLE
  1536. *    ...
  1537. *    if (HeisDaySmaller(18,9,1970,22,1,1994))
  1538. *      printf("<\n");
  1539. *    else
  1540. *      printf(">=\n");
  1541. *    ...
  1542. *
  1543. *   NOTES
  1544. *    It is better only to use this function for years from 8 to 8000!
  1545. *    This function is not longer needed - use CompareDates() !
  1546. *
  1547. *   BUGS
  1548. *    No known bugs.
  1549. *
  1550. *   SEE ALSO
  1551. *    JulianDaySmaller(),GregorianDaySmaller(),CompareDates()
  1552. *
  1553. *****************************************************************************
  1554. *
  1555. *
  1556. */
  1557.  
  1558.  {
  1559.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == -1));
  1560.  }
  1561.  
  1562.  /* ----------------------------------------------------------------------- */
  1563.  
  1564.  #ifndef __MakeLib
  1565.    bool JulianDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1566.  #else
  1567.    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)
  1568.  #endif
  1569.  
  1570. /*
  1571. *****i* Date/JulianDayGreater ***********************************************
  1572. *
  1573. *   NAME
  1574. *    JulianDayGreater -- Checks if date1 is greater than date2. (V33)
  1575. *
  1576. *   SYNOPSIS
  1577. *    greater = JulianDayGreater(day1,month1,year1,day2,month2,year2);
  1578. *      d0                d0    d1    d2    d3    d4    d5
  1579. *
  1580. *    bool JulianDayGreater(const unsigned short day1,
  1581. *        const unsigned short month1, const int year1,
  1582. *        const unsigned short day2, const unsigned short month2,
  1583. *        const int year2);
  1584. *
  1585. *   FUNCTION
  1586. *    JulianDayGreater test if date1 is greater than date2.
  1587. *
  1588. *   INPUTS
  1589. *    day1   - day of the first date
  1590. *    month1 - month of the first date
  1591. *    year1  - year of the first date
  1592. *    day2   - day of the second date
  1593. *    month2 - month of the second month
  1594. *    year2  - year of the second date
  1595. *
  1596. *   RESULT
  1597. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1598. *
  1599. *   EXAMPLE
  1600. *    ...
  1601. *    if (JulianDayGreater(18,9,1970,22,1,1994))
  1602. *      printf(">\n");
  1603. *    else
  1604. *      printf("<=\n");
  1605. *    ...
  1606. *
  1607. *   NOTES
  1608. *    It is better only to use this function for years from 8 to 1582!
  1609. *    This function is not longer needed - use CompareDates() !
  1610. *
  1611. *   BUGS
  1612. *    No known bugs.
  1613. *
  1614. *   SEE ALSO
  1615. *    GregorianDayGreater(),HeisDayGreater(),CompareDates()
  1616. *
  1617. *****************************************************************************
  1618. *
  1619. *
  1620. */
  1621.  
  1622.  {
  1623.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == 1));
  1624.  }
  1625.  
  1626.  
  1627.  #ifndef __MakeLib
  1628.    bool GregorianDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1629.  #else
  1630.    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)
  1631.  #endif
  1632.  
  1633. /*
  1634. *****i* Date/GregorianDayGreater ********************************************
  1635. *
  1636. *   NAME
  1637. *    GregorianDayGreater -- Checks if date1 is greater than date2. (V33)
  1638. *
  1639. *   SYNOPSIS
  1640. *    greater = GregorianDayGreater(day1,month1,year1,day2,month2,year2);
  1641. *      d0                   d0    d1    d2    d3    d4    d5
  1642. *
  1643. *    bool GregorianDayGreater(const unsigned short day1,
  1644. *        const unsigned short month1, const int year1,
  1645. *        const unsigned short day2, const unsigned short month2,
  1646. *        const int year2);
  1647. *
  1648. *   FUNCTION
  1649. *    GregorianDayGreater test if date1 is greater than date2.
  1650. *
  1651. *   INPUTS
  1652. *    day1   - day of the first date
  1653. *    month1 - month of the first date
  1654. *    year1  - year of the first date
  1655. *    day2   - day of the second date
  1656. *    month2 - month of the second month
  1657. *    year2  - year of the second date
  1658. *
  1659. *   RESULT
  1660. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1661. *
  1662. *   EXAMPLE
  1663. *    ...
  1664. *    if (GregorianDayGreater(18,9,1970,22,1,1994))
  1665. *      printf("<\n");
  1666. *    else
  1667. *      printf(">=\n");
  1668. *    ...
  1669. *
  1670. *   NOTES
  1671. *    It is better only to use this function for years from 8 to 3200!
  1672. *    This function is not longer needed - use CompareDates() !
  1673. *
  1674. *   BUGS
  1675. *    No known bugs.
  1676. *
  1677. *   SEE ALSO
  1678. *    JulianDayGreater(),HeisDayGreater(),CompareDates()
  1679. *
  1680. *****************************************************************************
  1681. *
  1682. *
  1683. */
  1684.  
  1685.  {
  1686.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == 1));
  1687.  }
  1688.  
  1689.  
  1690.  #ifndef __MakeLib
  1691.    bool HeisDayGreater(const unsigned short day1, const unsigned short month1, const int year1, const unsigned short day2, const unsigned short month2, const int year2)
  1692.  #else
  1693.    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)
  1694.  #endif
  1695.  
  1696. /*
  1697. *****i* Date/HeisDayGreater *************************************************
  1698. *
  1699. *   NAME
  1700. *    HeisDayGreater -- Checks if date1 is greater than date2. (V33)
  1701. *
  1702. *   SYNOPSIS
  1703. *    greater = HeisDayGreater(day1,month1,year1,day2,month2,year2);
  1704. *      d0              d0    d1    d2    d3    d4    d5
  1705. *
  1706. *    bool HeisDayGreater(const unsigned short day1,
  1707. *        const unsigned short month1, const int year1,
  1708. *        const unsigned short day2, const unsigned short month2,
  1709. *        const int year2);
  1710. *
  1711. *   FUNCTION
  1712. *    HeisDayGreater test if date1 is greater than date2.
  1713. *
  1714. *   INPUTS
  1715. *    day1   - day of the first date
  1716. *    month1 - month of the first date
  1717. *    year1  - year of the first date
  1718. *    day2   - day of the second date
  1719. *    month2 - month of the second month
  1720. *    year2  - year of the second date
  1721. *
  1722. *   RESULT
  1723. *    greater - This is TRUE is date1 > date2 otherwise it's FALSE.
  1724. *
  1725. *   EXAMPLE
  1726. *    ...
  1727. *    if (HeisDayGreater(18,9,1970,22,1,1994))
  1728. *      printf(">\n");
  1729. *    else
  1730. *      printf("<=\n");
  1731. *    ...
  1732. *
  1733. *   NOTES
  1734. *    It is better only to use this function for years from 8 to 8000!
  1735. *    This function is not longer needed - use CompareDates() !
  1736. *
  1737. *   BUGS
  1738. *    No known bugs.
  1739. *
  1740. *   SEE ALSO
  1741. *    JulianDayGreater(),GregorianDayGreater(),CompareDates()
  1742. *
  1743. *****************************************************************************
  1744. *
  1745. *
  1746. */
  1747.  
  1748.  {
  1749.   return((bool)(Compare2Dates(day1,month1,year1,day2,month2,year2) == 1));
  1750.  }
  1751.  
  1752.  /* ----------------------------------------------------------------------- */
  1753.  
  1754.  #ifndef __MakeLib
  1755.    long JulianDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1756.  #else
  1757.    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)
  1758.  #endif
  1759.  
  1760. /*
  1761. ******* Date/JulianDayDiff **************************************************
  1762. *
  1763. *   NAME
  1764. *    JulianDayDiff -- Calculates the days between 2 dates. (V33)
  1765. *
  1766. *   SYNOPSIS
  1767. *    days = JulianDayDiff(day1,month1,year1,day2,month2,year2);
  1768. *     d0              d0    d1    d2    d3    d4    d5
  1769. *
  1770. *    long JulianDayDiff(const unsigned short day1, unsigned short month1,
  1771. *        int year1, const unsigned short day2, unsigned short month2,
  1772. *        int year2);
  1773. *
  1774. *   FUNCTION
  1775. *    JulianDayDiff gives you back the number of days between
  1776. *    two specified dates.
  1777. *
  1778. *   INPUTS
  1779. *    day1   - day of the first date
  1780. *    month1 - month of the first date
  1781. *    year1  - year of the first date
  1782. *    day2   - day of the second date
  1783. *    month2 - month of the second month
  1784. *    year2  - year of the second date
  1785. *
  1786. *   RESULT
  1787. *    days - The number of days between the two dates
  1788. *        (positive if date1 <= date2).
  1789. *
  1790. *   EXAMPLE
  1791. *    ...
  1792. *    days = JulianDayDiff(18,9,1970,22,1,1994);
  1793. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1794. *    ...
  1795. *
  1796. *   NOTES
  1797. *    It is better only to use this function for years from 8 to 1582!
  1798. *
  1799. *   BUGS
  1800. *    No known bugs.
  1801. *
  1802. *   SEE ALSO
  1803. *    JulianLeapYear(),JulianMonthDays(),JulianYearDays(),
  1804. *    GregorianDayDiff(),HeisDayDiff()
  1805. *
  1806. *****************************************************************************
  1807. *
  1808. *
  1809. */
  1810.  
  1811.  {
  1812.   unsigned long t1=day1,t2=day2; /* set days left in the actual month */
  1813.  
  1814.   while (month1 > 1)
  1815.     {/* calc days left by the gone month of the year1 */
  1816.      month1--;
  1817.      t1 += JulianMonthDays(month1,year1);
  1818.     }
  1819.   while (month2 > 1)
  1820.     {/* calc days left by the gone month of the year2 */
  1821.      month2--;
  1822.      t2 += JulianMonthDays(month2,year2);
  1823.     }
  1824.   while (year1 > year2)
  1825.     {/* calc days of diff years */
  1826.      year1--;
  1827.      t1 += JulianYearDays(year1);
  1828.     }
  1829.   while (year1 < year2)
  1830.     {/* calc days of diff years */
  1831.      year2--;
  1832.      t2 += JulianYearDays(year2);
  1833.     }
  1834.   return((long)t2-(long)t1);
  1835.  }
  1836.  
  1837.  
  1838.  #ifndef __MakeLib
  1839.    long GregorianDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1840.  #else
  1841.    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)
  1842.  #endif
  1843.  
  1844. /*
  1845. ******* Date/GregorianDayDiff ***********************************************
  1846. *
  1847. *   NAME
  1848. *    GregorianDayDiff -- Calculates the days between 2 dates. (V33)
  1849. *
  1850. *   SYNOPSIS
  1851. *    days = GregorianDayDiff(day1,month1,year1,day2,month2,year2);
  1852. *     d0                 d0    d1    d2    d3    d4    d5
  1853. *
  1854. *    long GregorianDayDiff(const unsigned short day1,
  1855. *        unsigned short month1, int year1, const unsigned short day2,
  1856. *        unsigned short month2, int year2);
  1857. *
  1858. *   FUNCTION
  1859. *    GregorianDayDiff gives you back the number of days between
  1860. *    two specified dates.
  1861. *
  1862. *   INPUTS
  1863. *    day1   - day of the first date
  1864. *    month1 - month of the first date
  1865. *    year1  - year of the first date
  1866. *    day2   - day of the second date
  1867. *    month2 - month of the second month
  1868. *    year2  - year of the second date
  1869. *
  1870. *   RESULT
  1871. *    days - The number of days between the two dates
  1872. *        (positive if date1 <= date2).
  1873. *
  1874. *   EXAMPLE
  1875. *    ...
  1876. *    days = GregorianDayDiff(18,9,1970,22,1,1994);
  1877. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1878. *    ...
  1879. *
  1880. *   NOTES
  1881. *    It is better only to use this function for years from 8 to 02.3200!
  1882. *
  1883. *   BUGS
  1884. *    If you use one of the dates 5.10.1582 to 14.10.1582 you will get an
  1885. *    incorrect output because these days don't exist!
  1886. *
  1887. *   SEE ALSO
  1888. *    GregorianLeapYear(),GregorianMonthDays(),GregorianYearDays(),
  1889. *    JulianDayDiff(),HeisDayDiff()
  1890. *
  1891. *****************************************************************************
  1892. *
  1893. *
  1894. */
  1895.  
  1896.  {
  1897.   long t1=day1,t2=day2; /* set days left in the actual month */
  1898.  
  1899.   if ((year1 == BeforeGregorianYear) && (month1 == BeforeGregorianMonth))
  1900.    {
  1901.     if ((day1 <= BeforeGregorianDay) && GregorianDaySmaller(day1,month1,year1,day2,month2,year2) && GregorianDaySmaller(day2,month2,year2,1,AfterGregorianMonth+1,AfterGregorianYear) && GregorianDayGreater(day2,month2,year2,AfterGregorianDay-1,AfterGregorianMonth,AfterGregorianYear))
  1902.       t2 -= 10;
  1903.     if (day1 >= AfterGregorianDay)
  1904.      {
  1905.       if (GregorianDaySmaller(day1,month1,year1,day2,month2,year2) && GregorianDayGreater(day2,month2,year2,31,AfterGregorianMonth,AfterGregorianYear))
  1906.         t2 += 10;
  1907.       if (GregorianDayGreater(day1,month1,year1,day2,month2,year2) && GregorianDaySmaller(day2,month2,year2,BeforeGregorianDay+1,BeforeGregorianMonth,BeforeGregorianYear))
  1908.         t1 -= 10;
  1909.      }
  1910.    }
  1911.   if ((year2 == AfterGregorianYear) && (month2 == AfterGregorianMonth) && (day2 >= AfterGregorianDay))
  1912.    {
  1913.     if (GregorianDaySmaller(day2,month2,year2,day1,month1,year1) && GregorianDayGreater(day1,month1,year1,31,AfterGregorianMonth,AfterGregorianYear))
  1914.       t1 += 10;
  1915.     if (GregorianDayGreater(day2,month2,year2,day1,month1,year1) && GregorianDaySmaller(day1,month1,year1,1,BeforeGregorianMonth,BeforeGregorianYear))
  1916.       t2 -= 10;
  1917.    }
  1918.   while (month1 > 1)
  1919.     {/* calc days left by the gone month of the year1 */
  1920.      month1--;
  1921.      t1 += GregorianMonthDays(month1,year1);
  1922.     }
  1923.   while (month2 > 1)
  1924.     {/* calc days left by the gone month of the year2 */
  1925.      month2--;
  1926.      t2 += GregorianMonthDays(month2,year2);
  1927.     }
  1928.   while (year1 > year2)
  1929.     {/* calc days of diff years */
  1930.      year1--;
  1931.      t1 += GregorianYearDays(year1);
  1932.     }
  1933.   while (year1 < year2)
  1934.     {/* calc days of diff years */
  1935.      year2--;
  1936.      t2 += GregorianYearDays(year2);
  1937.     }
  1938.   return(t2-t1);
  1939.  }
  1940.  
  1941.  
  1942.  #ifndef __MakeLib
  1943.    long HeisDayDiff(const unsigned short day1, unsigned short month1, int year1, const unsigned short day2, unsigned short month2, int year2)
  1944.  #else
  1945.    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)
  1946.  #endif
  1947.  
  1948. /*
  1949. ******* Date/HeisDayDiff ****************************************************
  1950. *
  1951. *   NAME
  1952. *    HeisDayDiff -- Calculates the days between 2 dates. (V33)
  1953. *
  1954. *   SYNOPSIS
  1955. *    days = HeisDayDiff(day1,month1,year1,day2,month2,year2);
  1956. *     d0            d0    d1    d2    d3    d4    d5
  1957. *
  1958. *    long HeisDayDiff(const unsigned short day1, unsigned short month1,
  1959. *        int year1, const unsigned short day2, unsigned short month2,
  1960. *        int year2);
  1961. *
  1962. *   FUNCTION
  1963. *    HeisDayDiff gives you back the number of days between
  1964. *    two specified dates.
  1965. *
  1966. *   INPUTS
  1967. *    day1   - day of the first date
  1968. *    month1 - month of the first date
  1969. *    year1  - year of the first date
  1970. *    day2   - day of the second date
  1971. *    month2 - month of the second month
  1972. *    year2  - year of the second date
  1973. *
  1974. *   RESULT
  1975. *    days - The number of days between the two dates
  1976. *        (positive if date1 <= date2).
  1977. *
  1978. *   EXAMPLE
  1979. *    ...
  1980. *    days = HeisDayDiff(18,9,1970,22,1,1994);
  1981. *    printf("Age of Kai Hofmann in days : %d\n",days);
  1982. *    ...
  1983. *
  1984. *   NOTES
  1985. *    It is better only to use this function for years from 8 to 8000!
  1986. *
  1987. *   BUGS
  1988. *    If you use on of the dates 5.10.1582 to 14.10.1582 you will get an
  1989. *    incorrect output because these days don't exist!
  1990. *
  1991. *   SEE ALSO
  1992. *    HeisLeapYear(),HeisMonthDays(),HeisYearDays(),
  1993. *    JulianDayDiff(),GregorianDayDiff()
  1994. *
  1995. *****************************************************************************
  1996. *
  1997. *
  1998. */
  1999.  
  2000.  {
  2001.   long t1=day1,t2=day2; /* set days left in the actual month */
  2002.  
  2003.   if ((year1 == BeforeGregorianYear) && (month1 == BeforeGregorianMonth))
  2004.    {
  2005.     if ((day1 <= BeforeGregorianDay) && HeisDaySmaller(day1,month1,year1,day2,month2,year2) && HeisDaySmaller(day2,month2,year2,1,AfterGregorianMonth+1,AfterGregorianYear) && HeisDayGreater(day2,month2,year2,AfterGregorianDay-1,AfterGregorianMonth,AfterGregorianYear))
  2006.       t2 -= 10;
  2007.     if (day1 >= AfterGregorianDay)
  2008.      {
  2009.       if (HeisDaySmaller(day1,month1,year1,day2,month2,year2) && HeisDayGreater(day2,month2,year2,31,AfterGregorianMonth,AfterGregorianYear))
  2010.         t2 += 10;
  2011.       if (HeisDayGreater(day1,month1,year1,day2,month2,year2) && HeisDaySmaller(day2,month2,year2,BeforeGregorianDay+1,BeforeGregorianMonth,BeforeGregorianYear))
  2012.         t1 -= 10;
  2013.      }
  2014.    }
  2015.   if ((year2 == AfterGregorianYear) && (month2 == AfterGregorianMonth) && (day2 >= AfterGregorianDay))
  2016.    {
  2017.     if (HeisDaySmaller(day2,month2,year2,day1,month1,year1) && HeisDayGreater(day1,month1,year1,31,AfterGregorianMonth,AfterGregorianYear))
  2018.       t1 += 10;
  2019.     if (HeisDayGreater(day2,month2,year2,day1,month1,year1) && HeisDaySmaller(day1,month1,year1,1,BeforeGregorianMonth,BeforeGregorianYear))
  2020.       t2 -= 10;
  2021.    }
  2022.   while (month1 > 1)
  2023.     {/* calc days left by the gone month of the year1 */
  2024.      month1--;
  2025.      t1 += HeisMonthDays(month1,year1);
  2026.     }
  2027.   while (month2 > 1)
  2028.     {/* calc days left by the gone month of the year2 */
  2029.      month2--;
  2030.      t2 += HeisMonthDays(month2,year2);
  2031.     }
  2032.   while (year1 > year2)
  2033.     {/* calc days of diff years */
  2034.      year1--;
  2035.      t1 += HeisYearDays(year1);
  2036.     }
  2037.   while (year1 < year2)
  2038.     {/* calc days of diff years */
  2039.      year2--;
  2040.      t2 += HeisYearDays(year2);
  2041.     }
  2042.   return(t2-t1);
  2043.  }
  2044.  
  2045.  /* ----------------------------------------------------------------------- */
  2046.  
  2047.  #ifndef __MakeLib
  2048.    Weekdays JulianWeekday(const unsigned short day, unsigned short month, int year)
  2049.  #else
  2050.    Weekdays __saveds __asm JulianWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  2051.  #endif
  2052.  
  2053. /*
  2054. ******* Date/JulianWeekday **************************************************
  2055. *
  2056. *   NAME
  2057. *    JulianWeekday -- Gets the weekday of a specified date. (V33)
  2058. *
  2059. *   SYNOPSIS
  2060. *    weekday = JulianWeekday(day,month,year);
  2061. *      d0             d0   d1   d2
  2062. *
  2063. *    Weekdays JulianWeekday(const unsigned short day,
  2064. *        unsigned short month, int year);
  2065. *
  2066. *   FUNCTION
  2067. *    JulianWeekday gets the weekday for a specified date.
  2068. *
  2069. *   INPUTS
  2070. *    day   - day of the date
  2071. *    month - month of the date
  2072. *    year  - year of the date
  2073. *
  2074. *   RESULT
  2075. *    weekday - This result is of type:
  2076. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  2077. *        Saturday,Sunday);
  2078. *        dayerr will show you, that an error occurs!
  2079. *
  2080. *   EXAMPLE
  2081. *    ...
  2082. *    weekday = JulianWeekday(4,10,1582);
  2083. *    if (weekday == dayerr)
  2084. *      {
  2085. *       ...
  2086. *      }
  2087. *    ...
  2088. *
  2089. *   NOTES
  2090. *    It is better only to use this function for years from 1 to 02.1582!
  2091. *    In this version no dayerr will occur!
  2092. *
  2093. *   BUGS
  2094. *    For years <= 0 errors could occur, or systemcrashs(?).
  2095. *
  2096. *   SEE ALSO
  2097. *    GregorianWeekday(),HeisWeekday()
  2098. *
  2099. *****************************************************************************
  2100. *
  2101. *
  2102. */
  2103.  
  2104.  {
  2105.   unsigned short decade,wday;
  2106.  
  2107.   /* January and february dates must be 13 and 14 of the year before! */
  2108.   switch (month)
  2109.     {
  2110.      case 1 :
  2111.      case 2 : month += 12;
  2112.               year--;
  2113.     }
  2114.   decade = (unsigned short)(year - ((year / 100) * 100));
  2115.   /* Formula from Ch. Zeller in 1877 */
  2116.   wday = (unsigned short)((day + (((month+1) * 26) / 10) + decade +
  2117.             (decade / 4) + 5 - (unsigned short)(year / 100)) % 7);
  2118.   /* Convert (1-su 2-mo 3-tu 4-we 5-th 6-fr 7/0-sa) to normal days */
  2119.   if (wday == 0)
  2120.     wday = 6;
  2121.   else
  2122.     {
  2123.      wday--;
  2124.      if (wday == 0)
  2125.        wday = 7;
  2126.     }
  2127.   return((Weekdays)wday);
  2128.  }
  2129.  
  2130.  
  2131.  #ifndef __MakeLib
  2132.    Weekdays GregorianWeekday(const unsigned short day, unsigned short month, int year)
  2133.  #else
  2134.    Weekdays __saveds __asm GregorianWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  2135.  #endif
  2136.  
  2137. /*
  2138. ******* Date/GregorianWeekday ***********************************************
  2139. *
  2140. *   NAME
  2141. *    GregorianWeekday -- Gets the weekday of a specified date. (V33)
  2142. *
  2143. *   SYNOPSIS
  2144. *    weekday = GregorianWeekday(day,month,year);
  2145. *      d0                d0   d1   d2
  2146. *
  2147. *    Weekdays GregorianWeekday(const unsigned short day,
  2148. *        unsigned short month, int year);
  2149. *
  2150. *   FUNCTION
  2151. *    GregorianWeekday gets the weekday for a specified date.
  2152. *
  2153. *   INPUTS
  2154. *    day   - day of the date
  2155. *    month - month of the date
  2156. *    year  - year of the date
  2157. *
  2158. *   RESULT
  2159. *    weekday - This result is of type:
  2160. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  2161. *        Saturday,Sunday);
  2162. *        dayerr will show you, that an error occurs!
  2163. *
  2164. *   EXAMPLE
  2165. *    ...
  2166. *    weekday = GregorianWeekday(22,1,1994);
  2167. *    if (weekday == dayerr)
  2168. *      {
  2169. *       ...
  2170. *      }
  2171. *    ...
  2172. *
  2173. *   NOTES
  2174. *    It is better only to use this function for years from 8 to 3200!
  2175. *    In this version dayerr will only occur for the lost days :)
  2176. *
  2177. *   BUGS
  2178. *    It's not possible to use years < 0 (for more see JulianWeekday()).
  2179. *
  2180. *   SEE ALSO
  2181. *    JulianWeekday(),HeisWeekday()
  2182. *
  2183. *****************************************************************************
  2184. *
  2185. *
  2186. */
  2187.  
  2188.  {
  2189.   Weekdays weekday;
  2190.   unsigned int wd;
  2191.  
  2192.   if (GregorianDaySmaller(day,month,year,BeforeGregorianDay+1,BeforeGregorianMonth,BeforeGregorianYear))
  2193.     return(JulianWeekday(day,month,year));
  2194.   else
  2195.     {
  2196.      if (GregorianDaySmaller(day,month,year,AfterGregorianDay,AfterGregorianMonth,AfterGregorianYear))
  2197.        return(dayerr);
  2198.      else
  2199.       {
  2200.        if (year == AfterGregorianYear)
  2201.          return((Weekdays)((unsigned short)((GregorianDayDiff(AfterGregorianDay,AfterGregorianMonth,AfterGregorianYear,day,month,year)+4)%7)+1));
  2202.        else
  2203.         {/* Formula from J. I. Perelman 1909 */
  2204.          wd = year + (year / 4) - (year / 100) + (year / 400)
  2205.                 + (int)GregorianDayDiff(1,1,year,day,month,year);
  2206.          if (GregorianLeapYear(year))
  2207.            wd--;
  2208.          weekday = (Weekdays)(wd % 7);
  2209.          if (weekday == dayerr)
  2210.            weekday = Sunday;
  2211.          return(weekday);
  2212.         }
  2213.       }
  2214.     }
  2215.  }
  2216.  
  2217.  
  2218.  #ifndef __MakeLib
  2219.    Weekdays HeisWeekday(const unsigned short day, unsigned short month, int year)
  2220.  #else
  2221.    Weekdays __saveds __asm HeisWeekday(register __d0 const unsigned short day, register __d1 unsigned short month, register __d2 int year)
  2222.  #endif
  2223.  
  2224. /*
  2225. ******* Date/HeisWeekday ****************************************************
  2226. *
  2227. *   NAME
  2228. *    HeisWeekday -- Gets the weekday of a specified date. (V33)
  2229. *
  2230. *   SYNOPSIS
  2231. *    weekday = HeisWeekday(day,month,year);
  2232. *      d0               d0   d1   d2
  2233. *
  2234. *    Weekdays HeisWeekday(const unsigned short day, unsigned short month,
  2235. *        int year);
  2236. *
  2237. *   FUNCTION
  2238. *    HeisWeekday gets the weekday for a specified date.
  2239. *
  2240. *   INPUTS
  2241. *    day   - day of the date
  2242. *    month - month of the date
  2243. *    year  - year of the date
  2244. *
  2245. *   RESULT
  2246. *    weekday - This result is of type:
  2247. *        Weekdays = (dayerr,Monday,Tuesday,Wednesday,Thursday,Friday,
  2248. *        Saturday,Sunday);
  2249. *        dayerr will show you, that an error occurs!
  2250. *
  2251. *   EXAMPLE
  2252. *    ...
  2253. *    weekday = HeisWeekday(22,1,1994);
  2254. *    if (weekday == dayerr)
  2255. *      {
  2256. *       ...
  2257. *      }
  2258. *    ...
  2259. *
  2260. *   NOTES
  2261. *    It is better only to use this function for years from 8 to 8000!
  2262. *    In this version dayerr will only occur for the lost days :)
  2263. *
  2264. *   BUGS
  2265. *    It is not possible to use year < 0 (see JulianWeekday() for more).
  2266. *
  2267. *   SEE ALSO
  2268. *    JulianWeekday(),GregorianWeekday()
  2269. *
  2270. *****************************************************************************
  2271. *
  2272. *
  2273. */
  2274.  
  2275.  {
  2276.   Weekdays weekday;
  2277.   unsigned int wd;
  2278.  
  2279.   if (HeisDaySmaller(day,month,year,StartHeisDay,StartHeisMonth,StartHeisYear))
  2280.     return(GregorianWeekday(day,month,year));
  2281.   else
  2282.     {/* Formula from J. I. Perelman 1909 - extended for N.Heis in 01.1994
  2283.     by Kai Hofmann */
  2284.      wd = year + (year / 4) - (year / 100) + (year / 400)
  2285.         - (year / 3200) + (int)HeisDayDiff(1,1,year,day,month,year);
  2286.      if (HeisLeapYear(year))
  2287.        wd--;
  2288.      weekday = (Weekdays)(wd % 7);
  2289.      if (weekday == dayerr)
  2290.        weekday = Sunday;
  2291.      return(weekday);
  2292.     }
  2293.  }
  2294.  
  2295.  /* ----------------------------------------------------------------------- */
  2296.  
  2297.  #ifndef __MakeLib
  2298.    unsigned short JulianDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2299.  #else
  2300.    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)
  2301.  #endif
  2302.  
  2303. /*
  2304. ******* Date/JulianDaysBeforeWeekday ****************************************
  2305. *
  2306. *   NAME
  2307. *    JulianDaysBeforeWeekday -- Returns the diff to the wday before. (V33)
  2308. *
  2309. *   SYNOPSIS
  2310. *    days = JulianDaysBeforeWeekday(day,month,year,weekday);
  2311. *     d0                d0  d1    d2    d3
  2312. *
  2313. *    unsigned short JulianDaysBeforeWeekday(const unsigned short day,
  2314. *        const unsigned short month, const int year,
  2315. *        const Weekdays weekday);
  2316. *
  2317. *   FUNCTION
  2318. *    Returns the days to the weekday before the specified date.
  2319. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2320. *    you get back 2!
  2321. *    If you specify the 22.1.1994 and Saturday you get back 0
  2322. *    (the same day)!
  2323. *
  2324. *   INPUTS
  2325. *    day     - day of the date
  2326. *    month   - month of the date
  2327. *    year    - year of the date
  2328. *    weekday - weekday to search for building difference
  2329. *
  2330. *   RESULT
  2331. *    days - The days gets you back to the searched weekday (0-6)
  2332. *        If you get back an 8 an error occurs!
  2333. *
  2334. *   EXAMPLE
  2335. *    ...
  2336. *    days = JulianDaysBeforeWeekday(22,1,1994,Thursday);
  2337. *    ...
  2338. *
  2339. *   NOTES
  2340. *    It is better to use this function only from 8 to 02.1582!
  2341. *
  2342. *   BUGS
  2343. *    See JulianWeekday()!
  2344. *
  2345. *   SEE ALSO
  2346. *    JulianWeekday(),GregorianDaysBeforeWeekday(),HeisDaysBeforeWeekday()
  2347. *
  2348. *****************************************************************************
  2349. *
  2350. *
  2351. */
  2352.  
  2353.  {
  2354.   Weekdays wday;
  2355.  
  2356.   if (weekday == dayerr)
  2357.     return(8);
  2358.   else
  2359.     {
  2360.      wday = JulianWeekday(day,month,year);
  2361.      if (wday >= weekday)
  2362.        return((unsigned short)(wday-weekday));
  2363.      else
  2364.        {/* wday < weekday */
  2365.         return((unsigned short)(7-weekday+wday));
  2366.        }
  2367.     }
  2368.  }
  2369.  
  2370.  
  2371.  #ifndef __MakeLib
  2372.    unsigned short GregorianDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2373.  #else
  2374.    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)
  2375.  #endif
  2376.  
  2377. /*
  2378. ******* Date/GregorianDaysBeforeWeekday *************************************
  2379. *
  2380. *   NAME
  2381. *    GregorianDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  2382. *
  2383. *   SYNOPSIS
  2384. *    days = GregorianDaysBeforeWeekday(day,month,year,weekday);
  2385. *     d0                   d0  d1    d2    d3
  2386. *
  2387. *    unsigned short GregorianDaysBeforeWeekday(const unsigned short day,
  2388. *        const unsigned short month, const int year,
  2389. *        const Weekdays weekday);
  2390. *
  2391. *   FUNCTION
  2392. *    Returns the days to the weekday before the specified date.
  2393. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2394. *    you get back 2!
  2395. *    If you specify the 22.1.1994 and Saturday you get back 0
  2396. *    (the same day)!
  2397. *
  2398. *   INPUTS
  2399. *    day     - day of the date
  2400. *    month   - month of the date
  2401. *    year    - year of the date
  2402. *    weekday - weekday to search for building difference
  2403. *
  2404. *   RESULT
  2405. *    days - The days gets you back to the searched weekday (1-7)
  2406. *        If you get back an 8 an error occurs!
  2407. *
  2408. *   EXAMPLE
  2409. *    ...
  2410. *    days = GregorianDaysBeforeWeekday(22,1,1994,Thursday);
  2411. *    ...
  2412. *
  2413. *   NOTES
  2414. *    It is better to use this function only from 8 to 3200!
  2415. *
  2416. *   BUGS
  2417. *    See GregorianWeekday()!
  2418. *
  2419. *   SEE ALSO
  2420. *    GregorianWeekday(),JulianDaysBeforeWeekday(),HeisDaysBeforeWeekday()
  2421. *
  2422. *****************************************************************************
  2423. *
  2424. *
  2425. */
  2426.  
  2427.  {
  2428.   Weekdays wday;
  2429.  
  2430.   if (weekday == dayerr)
  2431.     return(8);
  2432.   else
  2433.     {
  2434.      wday = GregorianWeekday(day,month,year);
  2435.      if (wday >= weekday)
  2436.        return((unsigned short)(wday-weekday));
  2437.      else
  2438.        {/* wday < weekday */
  2439.         return((unsigned short)(7-weekday+wday));
  2440.        }
  2441.     }
  2442.  }
  2443.  
  2444.  
  2445.  #ifndef __MakeLib
  2446.    unsigned short HeisDaysBeforeWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2447.  #else
  2448.    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)
  2449.  #endif
  2450.  
  2451. /*
  2452. ******* Date/HeisDaysBeforeWeekday ******************************************
  2453. *
  2454. *   NAME
  2455. *    HeisDaysBeforeWeekday -- Returns the diff to wday before. (V33)
  2456. *
  2457. *   SYNOPSIS
  2458. *    days = HeisDaysBeforeWeekday(day,month,year,weekday);
  2459. *     d0                  d0  d1    d2    d3
  2460. *
  2461. *    unsigned short HeisDaysBeforeWeekday(const unsigned short day,
  2462. *        const unsigned short month, const int year,
  2463. *        const Weekdays weekday);
  2464. *
  2465. *   FUNCTION
  2466. *    Returns the days to the weekday before the specified date.
  2467. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2468. *    you get back 2!
  2469. *    If you specify the 22.1.1994 and Saturday you get back 0
  2470. *    (the same day)!
  2471. *
  2472. *   INPUTS
  2473. *    day     - day of the date
  2474. *    month   - month of the date
  2475. *    year    - year of the date
  2476. *    weekday - weekday to search for building difference
  2477. *
  2478. *   RESULT
  2479. *    days - The days gets you back to the searched weekday (1-7)
  2480. *        If you get back an 8 an error occurs!
  2481. *
  2482. *   EXAMPLE
  2483. *    ...
  2484. *    days = HeisDaysBeforeWeekday(22,1,1994,Thursday);
  2485. *    ...
  2486. *
  2487. *   NOTES
  2488. *    It is better to use this function only from 8 to 8000!
  2489. *
  2490. *   BUGS
  2491. *    See HeisWeekday()!
  2492. *
  2493. *   SEE ALSO
  2494. *    HeisWeekday(),JulianDaysBeforeWeekday(),GregorianDaysBeforeWeekday()
  2495. *
  2496. *****************************************************************************
  2497. *
  2498. *
  2499. */
  2500.  
  2501.  {
  2502.   Weekdays wday;
  2503.  
  2504.   if (weekday == dayerr)
  2505.     return(8);
  2506.   else
  2507.     {
  2508.      wday = HeisWeekday(day,month,year);
  2509.      if (wday >= weekday)
  2510.        return((unsigned short)(wday-weekday));
  2511.      else
  2512.        {/* wday < weekday */
  2513.         return((unsigned short)(7-weekday+wday));
  2514.        }
  2515.     }
  2516.  }
  2517.  
  2518.  /* ----------------------------------------------------------------------- */
  2519.  
  2520.  #ifndef __MakeLib
  2521.    unsigned short JulianDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2522.  #else
  2523.    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)
  2524.  #endif
  2525.  
  2526. /*
  2527. ******* Date/JulianDaysAfterWeekday *****************************************
  2528. *
  2529. *   NAME
  2530. *    JulianDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  2531. *
  2532. *   SYNOPSIS
  2533. *    days = JulianDaysAfterWeekday(day,month,year,weekday);
  2534. *     d0                   d0   d1   d2     d3
  2535. *
  2536. *    unsigned short JulianDaysAfterWeekday(const unsigned short day,
  2537. *        const unsigned short month, const int year,
  2538. *        const Weekdays weekday);
  2539. *
  2540. *   FUNCTION
  2541. *    Returns the days to the weekday after the specified date.
  2542. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2543. *    you get back 5!
  2544. *    If you specify the 22.1.1994 and Saturday you get back 0
  2545. *    (the same day)!
  2546. *
  2547. *   INPUTS
  2548. *    day     - day of the date
  2549. *    month   - month of the date
  2550. *    year    - year of the date
  2551. *    weekday - weekday to search for building difference
  2552. *
  2553. *   RESULT
  2554. *    days - The days after to the searched weekday.
  2555. *
  2556. *   EXAMPLE
  2557. *    ...
  2558. *    days = JulianDaysAfterWeekday(22,1,1994,Thursday);
  2559. *    ...
  2560. *
  2561. *   NOTES
  2562. *    It is better to use this function only from 8 to 1582!
  2563. *
  2564. *   BUGS
  2565. *    See JulianWeekday()!
  2566. *
  2567. *   SEE ALSO
  2568. *    JulianWeekday(),GregorianDaysAfterWeekday(),HeisDaysAfterWeekday()
  2569. *
  2570. *****************************************************************************
  2571. *
  2572. *
  2573. */
  2574.  
  2575.  {
  2576.   Weekdays wday;
  2577.  
  2578.   if (weekday == dayerr)
  2579.     return(8);
  2580.   else
  2581.     {
  2582.      wday = JulianWeekday(day,month,year);
  2583.      if (wday <= weekday)
  2584.        return((unsigned short)(weekday-wday));
  2585.      else
  2586.        {/* wday > weekday */
  2587.         return((unsigned short)(7-wday+weekday));
  2588.        }
  2589.     }
  2590.  }
  2591.  
  2592.  
  2593.  #ifndef __MakeLib
  2594.    unsigned short GregorianDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2595.  #else
  2596.    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)
  2597.  #endif
  2598.  
  2599. /*
  2600. ******* Date/GregorianDaysAfterWeekday **************************************
  2601. *
  2602. *   NAME
  2603. *    GregorianDaysAfterWeekday -- Returns the diff to wday after. (V33)
  2604. *
  2605. *   SYNOPSIS
  2606. *    days = GregorianDaysAfterWeekday(day,month,year,weekday);
  2607. *     d0                      d0   d1   d2     d3
  2608. *
  2609. *    unsigned short GregorianDaysAfterWeekday(const unsigned short day,
  2610. *        const unsigned short month, const int year,
  2611. *        const Weekdays weekday);
  2612. *
  2613. *   FUNCTION
  2614. *    Returns the days to the weekday after the specified date.
  2615. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2616. *    you get back 5!
  2617. *    If you specify the 22.1.1994 and Saturday you get back 0
  2618. *    (the same day)!
  2619. *
  2620. *   INPUTS
  2621. *    day     - day of the date
  2622. *    month   - month of the date
  2623. *    year    - year of the date
  2624. *    weekday - weekday to search for building difference
  2625. *
  2626. *   RESULT
  2627. *    days - The days after to the searched weekday.
  2628. *
  2629. *   EXAMPLE
  2630. *    ...
  2631. *    days = GregorianDaysAfterWeekday(22,1,1994,Thursday);
  2632. *    ...
  2633. *
  2634. *   NOTES
  2635. *    It is better to use this function only from 8 to 3200!
  2636. *
  2637. *   BUGS
  2638. *    See GregorianWeekday()!
  2639. *
  2640. *   SEE ALSO
  2641. *    GregorianWeekday(),JulianDaysAfterWeekday(),HeisDaysAfterWeekday()
  2642. *
  2643. *****************************************************************************
  2644. *
  2645. *
  2646. */
  2647.  
  2648.  {
  2649.   Weekdays wday;
  2650.  
  2651.   if (weekday == dayerr)
  2652.     return(8);
  2653.   else
  2654.     {
  2655.      wday = GregorianWeekday(day,month,year);
  2656.      if (wday <= weekday)
  2657.        return((unsigned short)(weekday-wday));
  2658.      else
  2659.        {/* wday > weekday */
  2660.         return((unsigned short)(7-wday+weekday));
  2661.        }
  2662.     }
  2663.  }
  2664.  
  2665.  
  2666.  #ifndef __MakeLib
  2667.    unsigned short HeisDaysAfterWeekday(const unsigned short day, const unsigned short month, const int year, const Weekdays weekday)
  2668.  #else
  2669.    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)
  2670.  #endif
  2671.  
  2672. /*
  2673. ******* Date/HeisDaysAfterWeekday *******************************************
  2674. *
  2675. *   NAME
  2676. *    HeisDaysAfterWeekday -- Returns the diff to the wday after. (V33)
  2677. *
  2678. *   SYNOPSIS
  2679. *    days = HeisDaysAfterWeekday(day,month,year,weekday);
  2680. *     d0                 d0   d1   d2     d3
  2681. *
  2682. *    unsigned short HeisDaysAfterWeekday(const unsigned short day,
  2683. *        const unsigned short month, const int year,
  2684. *        const Weekdays weekday);
  2685. *
  2686. *   FUNCTION
  2687. *    Returns the days to the weekday after the specified date.
  2688. *    If you specify the 22.1.1994 (Saturday) and Thursday
  2689. *    you get back 5!
  2690. *    If you specify the 22.1.1994 and Saturday you get back 0
  2691. *    (the same day)!
  2692. *
  2693. *   INPUTS
  2694. *    day     - day of the date
  2695. *    month   - month of the date
  2696. *    year    - year of the date
  2697. *    weekday - weekday to search for building difference
  2698. *
  2699. *   RESULT
  2700. *    days - The days after to the searched weekday.
  2701. *
  2702. *   EXAMPLE
  2703. *    ...
  2704. *    days = HeisDaysAfterWeekday(22,1,1994,Thursday);
  2705. *    ...
  2706. *
  2707. *   NOTES
  2708. *    It is better to use this function only from 8 to 8000!
  2709. *
  2710. *   BUGS
  2711. *    See HeisWeekday()!
  2712. *
  2713. *   SEE ALSO
  2714. *    HeisWeekday(),JulianDaysAfterWeekday(),GregorianDaysAfterWeekday()
  2715. *
  2716. *****************************************************************************
  2717. *
  2718. *
  2719. */
  2720.  
  2721.  {
  2722.   Weekdays wday;
  2723.  
  2724.   if (weekday == dayerr)
  2725.     return(8);
  2726.   else
  2727.     {
  2728.      wday = HeisWeekday(day,month,year);
  2729.      if (wday <= weekday)
  2730.        return((unsigned short)(weekday-wday));
  2731.      else
  2732.        {/* wday > weekday */
  2733.         return((unsigned short)(7-wday+weekday));
  2734.        }
  2735.     }
  2736.  }
  2737.  
  2738.  /* ----------------------------------------------------------------------- */
  2739.  
  2740.  #ifndef __MakeLib
  2741.    #ifndef __cplusplus
  2742.      void JulianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *const dday, unsigned short *const dmonth, int *const dyear)
  2743.    #else
  2744.      void JulianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short &dday, unsigned short &dmonth, int &dyear)
  2745.    #endif
  2746.  #else
  2747.    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 *const dday, register __a1 unsigned short *const dmonth, register __a2 int *const dyear)
  2748.  #endif
  2749.  
  2750. /*
  2751. ******* Date/JulianDiffDate *************************************************
  2752. *
  2753. *   NAME
  2754. *    JulianDiffDate -- Returns the date for a diff to another date. (V33)
  2755. *
  2756. *   SYNOPSIS
  2757. *    JulianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2758. *            d0   d1   d2     d3     a0    a1    a2
  2759. *
  2760. *    void JulianDiffDate(const unsigned short day,
  2761. *        const unsigned short month, const int year, int days,
  2762. *        unsigned short *const dday, unsigned short *const dmonth,
  2763. *        int *const dyear);
  2764. *
  2765. *    void JulianDiffDate(const unsigned short day,
  2766. *        const unsigned short month, const int year, int days,
  2767. *        unsigned short &dday, unsigned short &dmonth, int &dyear);
  2768. *
  2769. *   FUNCTION
  2770. *    Returns the date which lies diffdays before/after the specified date.
  2771. *
  2772. *   INPUTS
  2773. *    day      - day of the date
  2774. *    month    - month of the date
  2775. *    year     - year of the date
  2776. *    diffdays - difference to the date in days
  2777. *
  2778. *   RESULT
  2779. *    dday   - Destination day
  2780. *    dmonth - Destination month
  2781. *    dyear  - Destination year
  2782. *
  2783. *   EXAMPLE
  2784. *    ...
  2785. *    JulianDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  2786. *    ...
  2787. *
  2788. *   NOTES
  2789. *    It is better to use this function only from 8 to 1582!
  2790. *
  2791. *   BUGS
  2792. *    unknown.
  2793. *
  2794. *   SEE ALSO
  2795. *    JulianDayDiff(),JulianMonthDays(),GregorianDiffDate(),HeisDiffDate()
  2796. *
  2797. *****************************************************************************
  2798. *
  2799. *
  2800. */
  2801.  
  2802.  {
  2803.   int ddays;
  2804.  
  2805.   #ifndef __cplusplus
  2806.     *dday = day;
  2807.     *dmonth = month;
  2808.     *dyear = year;
  2809.     if (days >= 0)
  2810.       {/* add */
  2811.        ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2812.        while (days >= ddays)
  2813.          {/* years */
  2814.           *dday = 1;
  2815.           *dmonth = 1;
  2816.           (*dyear)++;
  2817.           days -= ddays;
  2818.           ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2819.          }
  2820.        ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2821.        while (days >= ddays)
  2822.          {/* months */
  2823.           *dday = 1;
  2824.           (*dmonth)++;
  2825.           days -= ddays;
  2826.           ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2827.          }
  2828.        if (days > 0)
  2829.          {/* days */
  2830.           *dday += (unsigned short)days;
  2831.          }
  2832.       }
  2833.     else
  2834.       {/* sub */
  2835.        ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2836.        while (days <= ddays)
  2837.          {/* years */
  2838.           *dday = 31;
  2839.           *dmonth = 12;
  2840.           (*dyear)--;
  2841.           days -= ddays;
  2842.           ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  2843.          }
  2844.        ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,JulianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2845.        while (days <= ddays)
  2846.          {/* months */
  2847.           *dday = JulianMonthDays((*dmonth)-1,*dyear);
  2848.           (*dmonth)--;
  2849.           days -= ddays;
  2850.           ddays = (int)JulianDayDiff(*dday,*dmonth,*dyear,JulianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  2851.          }
  2852.        if (days < 0)
  2853.            *dday -= (unsigned short)abs(days);
  2854.       }
  2855.   #else
  2856.     dday = day;
  2857.     dmonth = month;
  2858.     dyear = year;
  2859.     if (days >= 0)
  2860.       {/* add */
  2861.        ddays = (int)JulianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2862.        while (days >= ddays)
  2863.          {/* years */
  2864.           dday = 1;
  2865.           dmonth = 1;
  2866.           dyear++;
  2867.           days -= ddays;
  2868.           ddays = (int)JulianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  2869.          }
  2870.        ddays = (int)JulianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2871.        while (days >= ddays)
  2872.          {/* months */
  2873.           dday = 1;
  2874.           dmonth++;
  2875.           days -= ddays;
  2876.           ddays = (int)JulianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  2877.          }
  2878.        if (days > 0)
  2879.          {/* days */
  2880.           dday += (unsigned short)days;
  2881.          }
  2882.       }
  2883.     else
  2884.       {/* sub */
  2885.        ddays = (int)JulianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2886.        while (days <= ddays)
  2887.          {/* years */
  2888.           dday = 31;
  2889.           dmonth = 12;
  2890.           dyear--;
  2891.           days -= ddays;
  2892.           ddays = (int)JulianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  2893.          }
  2894.        ddays = (int)JulianDayDiff(dday,dmonth,dyear,JulianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2895.        while (days <= ddays)
  2896.          {/* months */
  2897.           dday = JulianMonthDays(dmonth-1,dyear);
  2898.           dmonth--;
  2899.           days -= ddays;
  2900.           ddays = (int)JulianDayDiff(dday,dmonth,dyear,JulianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  2901.          }
  2902.        if (days < 0)
  2903.          dday -= (unsigned short)(days < 0 ? -days : days);
  2904.       }
  2905.   #endif
  2906.  }
  2907.  
  2908.  
  2909.  #ifndef __MakeLib
  2910.    #ifndef __cplusplus
  2911.      void GregorianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *const dday, unsigned short *const dmonth, int *const dyear)
  2912.    #else
  2913.      void GregorianDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short &dday, unsigned short &dmonth, int &dyear)
  2914.    #endif
  2915.  #else
  2916.    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 *const dday, register __a1 unsigned short *const dmonth, register __a2 int *const dyear)
  2917.  #endif
  2918.  
  2919. /*
  2920. ******* Date/GregorianDiffDate **********************************************
  2921. *
  2922. *   NAME
  2923. *    GregorianDiffDate -- Returns the diff date to another date. (V33)
  2924. *
  2925. *   SYNOPSIS
  2926. *    GregorianDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  2927. *               d0   d1   d2     d3     a0    a1    a2
  2928. *
  2929. *    void GregorianDiffDate(const unsigned short day,
  2930. *        const unsigned short month, const int year, int days,
  2931. *        unsigned short *const dday, unsigned short *const dmonth,
  2932. *        int *const dyear);
  2933. *
  2934. *    void GregorianDiffDate(const unsigned short day,
  2935. *        const unsigned short month, const int year, int days,
  2936. *        unsigned short &dday, unsigned short &dmonth, int &dyear);
  2937. *
  2938. *   FUNCTION
  2939. *    Returns the date which lies diffdays before/after the specified date.
  2940. *
  2941. *   INPUTS
  2942. *    day      - day of the date
  2943. *    month    - month of the date
  2944. *    year     - year of the date
  2945. *    diffdays - difference to the date in days
  2946. *
  2947. *   RESULT
  2948. *    dday   - Destination day
  2949. *    dmonth - Destination month
  2950. *    dyear  - Destination year
  2951. *
  2952. *   EXAMPLE
  2953. *    ...
  2954. *    GregorianDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  2955. *    ...
  2956. *
  2957. *   NOTES
  2958. *    It is better to use this function only from 8 to 3200!
  2959. *
  2960. *   BUGS
  2961. *    unknown.
  2962. *
  2963. *   SEE ALSO
  2964. *    GregorianDayDiff(),GregorianMonthDays(),JulianDiffDate(),
  2965. *    HeisDiffDate()
  2966. *
  2967. *****************************************************************************
  2968. *
  2969. *
  2970. */
  2971.  
  2972.  {
  2973.   int ddays;
  2974.  
  2975.   #ifndef __cplusplus
  2976.     *dday = day;
  2977.     *dmonth = month;
  2978.     *dyear = year;
  2979.     if (days >= 0)
  2980.       {/* add */
  2981.        ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2982.        while (days >= ddays)
  2983.          {/* years */
  2984.           *dday = 1;
  2985.           *dmonth = 1;
  2986.           (*dyear)++;
  2987.           days -= ddays;
  2988.           ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  2989.          }
  2990.        ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2991.        while (days >= ddays)
  2992.          {/* months */
  2993.           *dday = 1;
  2994.           (*dmonth)++;
  2995.           days -= ddays;
  2996.           ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  2997.          }
  2998.        if (days > 0)
  2999.          {/* days */
  3000.           *dday += (unsigned short)days;
  3001.          }
  3002.       }
  3003.     else
  3004.       {/* sub */
  3005.        ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  3006.        while (days <= ddays)
  3007.          {/* years */
  3008.           *dday = 31;
  3009.           *dmonth = 12;
  3010.           (*dyear)--;
  3011.           days -= ddays;
  3012.           ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  3013.          }
  3014.        ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,GregorianMonthDays((*dmonth)-1,*dyear),(*dmonth-1),*dyear);
  3015.        while (days <= ddays)
  3016.          {/* months */
  3017.           *dday = GregorianMonthDays((*dmonth-1),*dyear);
  3018.           (*dmonth)--;
  3019.           days -= ddays;
  3020.           ddays = (int)GregorianDayDiff(*dday,*dmonth,*dyear,GregorianMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  3021.          }
  3022.        if (days < 0)
  3023.          *dday -= (unsigned short)abs(days);
  3024.       }
  3025.   #else
  3026.     dday = day;
  3027.     dmonth = month;
  3028.     dyear = year;
  3029.     if (days >= 0)
  3030.       {/* add */
  3031.        ddays = (int)GregorianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  3032.        while (days >= ddays)
  3033.          {/* years */
  3034.           dday = 1;
  3035.           dmonth = 1;
  3036.           dyear++;
  3037.           days -= ddays;
  3038.           ddays = (int)GregorianDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  3039.          }
  3040.        ddays = (int)GregorianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  3041.        while (days >= ddays)
  3042.          {/* months */
  3043.           dday = 1;
  3044.           dmonth++;
  3045.           days -= ddays;
  3046.           ddays = (int)GregorianDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  3047.          }
  3048.        if (days > 0)
  3049.          {/* days */
  3050.           dday += (unsigned short)days;
  3051.          }
  3052.       }
  3053.     else
  3054.       {/* sub */
  3055.        ddays = (int)GregorianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  3056.        while (days <= ddays)
  3057.          {/* years */
  3058.           dday = 31;
  3059.           dmonth = 12;
  3060.           dyear--;
  3061.           days -= ddays;
  3062.           ddays = (int)GregorianDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  3063.          }
  3064.        ddays = (int)GregorianDayDiff(dday,dmonth,dyear,GregorianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  3065.        while (days <= ddays)
  3066.          {/* months */
  3067.           dday = GregorianMonthDays(dmonth-1,dyear);
  3068.           dmonth--;
  3069.           days -= ddays;
  3070.           ddays = (int)GregorianDayDiff(dday,dmonth,dyear,GregorianMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  3071.          }
  3072.        if (days < 0)
  3073.          dday -= (unsigned short)(days < 0 ? -days : days);
  3074.       }
  3075.   #endif
  3076.  }
  3077.  
  3078.  
  3079.  #ifndef __MakeLib
  3080.    #ifndef __cplusplus
  3081.      void HeisDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short *const dday, unsigned short *const dmonth, int *const dyear)
  3082.    #else
  3083.      void HeisDiffDate(const unsigned short day, const unsigned short month, const int year, int days, unsigned short &dday, unsigned short &dmonth, int &dyear)
  3084.    #endif
  3085.  #else
  3086.    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)
  3087.  #endif
  3088.  
  3089. /*
  3090. ******* Date/HeisDiffDate ***************************************************
  3091. *
  3092. *   NAME
  3093. *    HeisDiffDate -- Returns the date for a diff to another date. (V33)
  3094. *
  3095. *   SYNOPSIS
  3096. *    HeisDiffDate(day,month,year,diffdays,dday,dmonth,dyear);
  3097. *              d0   d1   d2     d3     a0    a1    a2
  3098. *
  3099. *    void HeisDiffDate(const unsigned short day,
  3100. *        const unsigned short month, const int year, int days,
  3101. *        unsigned short *const dday, unsigned short *const dmonth,
  3102. *        int *const dyear);
  3103. *
  3104. *    void HeisDiffDate(const unsigned short day,
  3105. *        const unsigned short month, const int year, int days,
  3106. *        unsigned short &dday, unsigned short &dmonth, int &dyear);
  3107. *
  3108. *   FUNCTION
  3109. *    Returns the date which lies diffdays before/after the specified date.
  3110. *
  3111. *   INPUTS
  3112. *    day      - day of the date
  3113. *    month    - month of the date
  3114. *    year     - year of the date
  3115. *    diffdays - difference to the date in days
  3116. *
  3117. *   RESULT
  3118. *    dday   - Destination day
  3119. *    dmonth - Destination month
  3120. *    dyear  - Destination year
  3121. *
  3122. *   EXAMPLE
  3123. *    ...
  3124. *    HeisDiffDate(23,1,1994,7,&dday,&dmonth,&dyear);
  3125. *    ...
  3126. *
  3127. *   NOTES
  3128. *    It is better to use this function only from 8 to 8000!
  3129. *
  3130. *   BUGS
  3131. *    unknown.
  3132. *
  3133. *   SEE ALSO
  3134. *    HeisDayDiff(),HeisMonthDays(),JulianDiffDate(),GregorianDiffDate()
  3135. *
  3136. *****************************************************************************
  3137. *
  3138. *
  3139. */
  3140.  
  3141.  {
  3142.   int ddays;
  3143.  
  3144.   #ifndef __cplusplus
  3145.     *dday = day;
  3146.     *dmonth = month;
  3147.     *dyear = year;
  3148.     if (days >= 0)
  3149.       {/* add */
  3150.        ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  3151.        while (days >= ddays)
  3152.          {/* years */
  3153.           *dday = 1;
  3154.           *dmonth = 1;
  3155.           (*dyear)++;
  3156.           days -= ddays;
  3157.           ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,1,(*dyear)+1);
  3158.          }
  3159.        ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,(*dmonth+1),*dyear);
  3160.        while (days >= ddays)
  3161.          {/* months */
  3162.           *dday = 1;
  3163.           (*dmonth)++;
  3164.           days -= ddays;
  3165.           ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,1,(*dmonth)+1,*dyear);
  3166.          }
  3167.        if (days > 0)
  3168.          {/* days */
  3169.           *dday += (unsigned short)days;
  3170.          }
  3171.       }
  3172.     else
  3173.       {/* sub */
  3174.        ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  3175.        while (days <= ddays)
  3176.          {/* years */
  3177.           *dday = 31;
  3178.           *dmonth = 12;
  3179.           (*dyear)--;
  3180.           days -= ddays;
  3181.           ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,31,12,(*dyear)-1);
  3182.          }
  3183.        ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,HeisMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  3184.        while (days <= ddays)
  3185.          {/* months */
  3186.           *dday = HeisMonthDays((*dmonth)-1,*dyear);
  3187.           (*dmonth)--;
  3188.           days -= ddays;
  3189.           ddays = (int)HeisDayDiff(*dday,*dmonth,*dyear,HeisMonthDays((*dmonth)-1,*dyear),(*dmonth)-1,*dyear);
  3190.          }
  3191.        if (days < 0)
  3192.          *dday -= (unsigned short)abs(days);
  3193.       }
  3194.   #else
  3195.     dday = day;
  3196.     dmonth = month;
  3197.     dyear = year;
  3198.     if (days >= 0)
  3199.       {/* add */
  3200.        ddays = (int)HeisDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  3201.        while (days >= ddays)
  3202.          {/* years */
  3203.           dday = 1;
  3204.           dmonth = 1;
  3205.           dyear++;
  3206.           days -= ddays;
  3207.           ddays = (int)HeisDayDiff(dday,dmonth,dyear,1,1,dyear+1);
  3208.          }
  3209.        ddays = (int)HeisDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  3210.        while (days >= ddays)
  3211.          {/* months */
  3212.           dday = 1;
  3213.           dmonth++;
  3214.           days -= ddays;
  3215.           ddays = (int)HeisDayDiff(dday,dmonth,dyear,1,dmonth+1,dyear);
  3216.          }
  3217.        if (days > 0)
  3218.          {/* days */
  3219.           dday += (unsigned short)days;
  3220.          }
  3221.       }
  3222.     else
  3223.       {/* sub */
  3224.        ddays = (int)HeisDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  3225.        while (days <= ddays)
  3226.          {/* years */
  3227.           dday = 31;
  3228.           dmonth = 12;
  3229.           dyear--;
  3230.           days -= ddays;
  3231.           ddays = (int)HeisDayDiff(dday,dmonth,dyear,31,12,dyear-1);
  3232.          }
  3233.        ddays = (int)HeisDayDiff(dday,dmonth,dyear,HeisMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  3234.        while (days <= ddays)
  3235.          {/* months */
  3236.           dday = HeisMonthDays(dmonth-1,dyear);
  3237.           dmonth--;
  3238.           days -= ddays;
  3239.           ddays = (int)HeisDayDiff(dday,dmonth,dyear,HeisMonthDays(dmonth-1,dyear),dmonth-1,dyear);
  3240.          }
  3241.        if (days < 0)
  3242.          dday -= (unsigned short)(days < 0 ? -days : days);
  3243.       }
  3244.   #endif
  3245.  }
  3246.  
  3247.  /* ----------------------------------------------------------------------- */
  3248.  
  3249.  #ifndef __MakeLib
  3250.    unsigned int JYearToScaliger(const int year)
  3251.  #else
  3252.    unsigned int __saveds __asm JYearToScaliger(register __d0 const int year)
  3253.  #endif
  3254.  
  3255. /*
  3256. ******* Date/JYearToScaliger ************************************************
  3257. *
  3258. *   NAME
  3259. *    JYearToScaliger -- Returns the year as Scaliger year. (V33)
  3260. *
  3261. *   SYNOPSIS
  3262. *    syear = JYearToScaliger(year);
  3263. *     d0             d0
  3264. *
  3265. *    unsigned int JYearToScaliger(const int year);
  3266. *
  3267. *   FUNCTION
  3268. *    Returns the Scaliger year.
  3269. *
  3270. *   INPUTS
  3271. *    year     - Julian year
  3272. *
  3273. *   RESULT
  3274. *    syear - The Scaliger year
  3275. *
  3276. *   EXAMPLE
  3277. *    ...
  3278. *    syear = JYearToScaliger(1582);
  3279. *    ...
  3280. *
  3281. *   NOTES
  3282. *    It is better to use this function only from 8 to 1582!
  3283. *
  3284. *   BUGS
  3285. *    unknown.
  3286. *
  3287. *   SEE ALSO
  3288. *    GYearToScaliger(),HYearToScaliger()
  3289. *
  3290. *****************************************************************************
  3291. *
  3292. *
  3293. */
  3294.  
  3295.  {
  3296.   if ((year < 0) && (year > -4714))
  3297.     return((unsigned int)(4714+year));
  3298.   else
  3299.     if ((year > 0) && (year < 3268))
  3300.       return((unsigned int)(4713+year));
  3301.     else
  3302.       return(0);
  3303.  }
  3304.  
  3305.  
  3306.  #ifndef __MakeLib
  3307.    unsigned int GYearToScaliger(const int year)
  3308.  #else
  3309.    unsigned int __saveds __asm GYearToScaliger(register __d0 const int year)
  3310.  #endif
  3311.  
  3312. /*
  3313. ******* Date/GYearToScaliger ************************************************
  3314. *
  3315. *   NAME
  3316. *    GYearToScaliger -- Returns the year as Scaliger year. (V33)
  3317. *
  3318. *   SYNOPSIS
  3319. *    syear = GYearToScaliger(year);
  3320. *     d0             d0
  3321. *
  3322. *    unsigned int GYearToScaliger(const int year);
  3323. *
  3324. *   FUNCTION
  3325. *    Returns the Scaliger year.
  3326. *
  3327. *   INPUTS
  3328. *    year     - Gregorian year
  3329. *
  3330. *   RESULT
  3331. *    syear - The Scaliger year
  3332. *
  3333. *   EXAMPLE
  3334. *    ...
  3335. *    syear = GYearToScaliger(1994);
  3336. *    ...
  3337. *
  3338. *   NOTES
  3339. *    It is better to use this function only from 8 to 3200!
  3340. *
  3341. *   BUGS
  3342. *    unknown.
  3343. *
  3344. *   SEE ALSO
  3345. *    JYearToScaliger(),HYearToScaliger()
  3346. *
  3347. *****************************************************************************
  3348. *
  3349. *
  3350. */
  3351.  
  3352.  {/* if other calcs are better use here! */
  3353.   return(JYearToScaliger(year));
  3354.  }
  3355.  
  3356.  
  3357.  #ifndef __MakeLib
  3358.    unsigned int HYearToScaliger(const int year)
  3359.  #else
  3360.    unsigned int __saveds __asm HYearToScaliger(register __d0 const int year)
  3361.  #endif
  3362.  
  3363. /*
  3364. ******* Date/HYearToScaliger ************************************************
  3365. *
  3366. *   NAME
  3367. *    HYearToScaliger -- Returns the year as Scaliger year. (V33)
  3368. *
  3369. *   SYNOPSIS
  3370. *    syear = HYearToScaliger(year);
  3371. *     d0             d0
  3372. *
  3373. *    unsigned int HYearToScaliger(const int year);
  3374. *
  3375. *   FUNCTION
  3376. *    Returns the Scaliger year.
  3377. *
  3378. *   INPUTS
  3379. *    year     - Heis year
  3380. *
  3381. *   RESULT
  3382. *    syear - The Scaliger year
  3383. *
  3384. *   EXAMPLE
  3385. *    ...
  3386. *    syear = HYearToScaliger(1994);
  3387. *    ...
  3388. *
  3389. *   NOTES
  3390. *    It is better to use this function only from 8 to 8000!
  3391. *
  3392. *   BUGS
  3393. *    The Scaliger period is defined to 3268!!!.
  3394. *
  3395. *   SEE ALSO
  3396. *    JYearToScaliger(),GYearToScaliger()
  3397. *
  3398. *****************************************************************************
  3399. *
  3400. *
  3401. */
  3402.  
  3403.  {/* for compatiblities if GYearToScaliger will be changed */
  3404.   return(GYearToScaliger(year));
  3405.  }
  3406.  
  3407.  /* ----------------------------------------------------------------------- */
  3408.  
  3409.  #ifndef __MakeLib
  3410.    int ScaligerYearToJ(const unsigned int syear)
  3411.  #else
  3412.    int __saveds __asm ScaligerYearToJ(register __d0 const unsigned int syear)
  3413.  #endif
  3414.  
  3415. /*
  3416. ******* Date/ScaligerYearToJ ************************************************
  3417. *
  3418. *   NAME
  3419. *    ScaligerYearToJ -- Returns the Scaliger year as Julian year. (V33)
  3420. *
  3421. *   SYNOPSIS
  3422. *    year = ScaligerYearToJ(syear);
  3423. *     d0            d0
  3424. *
  3425. *    int ScaligerYearToJ(const unsigned int syear);
  3426. *
  3427. *   FUNCTION
  3428. *    Returns the Julian year of a Scaliger year.
  3429. *
  3430. *   INPUTS
  3431. *    syear     - Scaliger year
  3432. *
  3433. *   RESULT
  3434. *    year - The Julian year
  3435. *
  3436. *   EXAMPLE
  3437. *    ...
  3438. *    year = ScaligerYearToJ(4800);
  3439. *    ...
  3440. *
  3441. *   NOTES
  3442. *    It is better to use this function only from 4707 to 6295!
  3443. *
  3444. *   BUGS
  3445. *    unknown.
  3446. *
  3447. *   SEE ALSO
  3448. *    ScaligerYearToG(),ScaligerYearToH()
  3449. *
  3450. *****************************************************************************
  3451. *
  3452. *
  3453. */
  3454.  
  3455.  {
  3456.   if (syear < 4714)
  3457.     return((int)(4714+syear));
  3458.   else
  3459.     return((int)(syear-4713));
  3460.  }
  3461.  
  3462.  
  3463.  #ifndef __MakeLib
  3464.    int ScaligerYearToG(const unsigned int syear)
  3465.  #else
  3466.    int __saveds __asm ScaligerYearToG(register __d0 const unsigned int syear)
  3467.  #endif
  3468.  
  3469. /*
  3470. ******* Date/ScaligerYearToG ************************************************
  3471. *
  3472. *   NAME
  3473. *    ScaligerYearToG -- Returns the Scaliger year as Gregorian year. (V33)
  3474. *
  3475. *   SYNOPSIS
  3476. *    year = ScaligerYearToG(syear);
  3477. *     d0            d0
  3478. *
  3479. *    int ScaligerYearToG(const unsigned int syear);
  3480. *
  3481. *   FUNCTION
  3482. *    Returns the Gregorian year of a Scaliger year.
  3483. *
  3484. *   INPUTS
  3485. *    syear     - Scaliger year
  3486. *
  3487. *   RESULT
  3488. *    year - The Gregorian year
  3489. *
  3490. *   EXAMPLE
  3491. *    ...
  3492. *    year = ScaligerYearToG(6400);
  3493. *    ...
  3494. *
  3495. *   NOTES
  3496. *    It is better to use this function only from 4707 to 7981!
  3497. *
  3498. *   BUGS
  3499. *    unknown.
  3500. *
  3501. *   SEE ALSO
  3502. *    ScaligerYearToJ(),ScaligerYearToH()
  3503. *
  3504. *****************************************************************************
  3505. *
  3506. *
  3507. */
  3508.  
  3509.  {
  3510.   return(ScaligerYearToJ(syear));
  3511.  }
  3512.  
  3513.  
  3514.  #ifndef __MakeLib
  3515.    int ScaligerYearToH(const unsigned int syear)
  3516.  #else
  3517.    int __saveds __asm ScaligerYearToH(register __d0 const unsigned int syear)
  3518.  #endif
  3519.  
  3520. /*
  3521. ******* Date/ScaligerYearToH ************************************************
  3522. *
  3523. *   NAME
  3524. *    ScaligerYearToH -- Returns the Scaliger year as Heis year. (V33)
  3525. *
  3526. *   SYNOPSIS
  3527. *    year = ScaligerYearToH(syear);
  3528. *     d0            d0
  3529. *
  3530. *    int ScaligerYearToH(const unsigned int syear);
  3531. *
  3532. *   FUNCTION
  3533. *    Returns the Heis year of a Scaliger year.
  3534. *
  3535. *   INPUTS
  3536. *    syear     - Scaliger year
  3537. *
  3538. *   RESULT
  3539. *    year - The Heis year
  3540. *
  3541. *   EXAMPLE
  3542. *    ...
  3543. *    year = ScaligerYearToH(7000);
  3544. *    ...
  3545. *
  3546. *   NOTES
  3547. *    It is better to use this function only from 4707 to 7981!
  3548. *
  3549. *   BUGS
  3550. *    unknown.
  3551. *
  3552. *   SEE ALSO
  3553. *    ScaligerYearToJ(),ScaligerYearToG()
  3554. *
  3555. *****************************************************************************
  3556. *
  3557. *
  3558. */
  3559.  
  3560.  {/* for compatibilitie if ScaligerYearToG is changed! */
  3561.   return(ScaligerYearToG(syear));
  3562.  }
  3563.  
  3564.  /* ----------------------------------------------------------------------- */
  3565.  
  3566.  #ifndef __MakeLib
  3567.    unsigned long JSYearToJD(const unsigned int syear)
  3568.  #else
  3569.    unsigned long __saveds __asm JSYearToJD(register __d0 const unsigned int syear)
  3570.  #endif
  3571.  
  3572. /*
  3573. ******* Date/JSYearToJD *****************************************************
  3574. *
  3575. *   NAME
  3576. *    JSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3577. *
  3578. *   SYNOPSIS
  3579. *    jd = JSYearToJD(syear);
  3580. *    d0         d0
  3581. *
  3582. *    unsigned long JSYearToJD(const unsigned int syear);
  3583. *
  3584. *   FUNCTION
  3585. *    Returns the Julianday of a Scaliger year.
  3586. *
  3587. *   INPUTS
  3588. *    syear     - Scaliger year
  3589. *
  3590. *   RESULT
  3591. *    jd - The Julianday
  3592. *
  3593. *   EXAMPLE
  3594. *    ...
  3595. *    jd = JSYearToJD(4800);
  3596. *    ...
  3597. *
  3598. *   NOTES
  3599. *    It is better to use this function only from 4707 to 6295!
  3600. *
  3601. *   BUGS
  3602. *    unknown.
  3603. *
  3604. *   SEE ALSO
  3605. *    GSYearToJD(),HSYearToJD()
  3606. *
  3607. *****************************************************************************
  3608. *
  3609. *
  3610. */
  3611.  
  3612.  {
  3613.   return(((unsigned long)syear-1)*365+((unsigned long)syear+2) / 4);
  3614.  }
  3615.  
  3616.  
  3617.  #ifndef __MakeLib
  3618.    unsigned long GSYearToJD(const unsigned int syear)
  3619.  #else
  3620.    unsigned long __saveds __asm GSYearToJD(register __d0 const unsigned int syear)
  3621.  #endif
  3622.  
  3623. /*
  3624. ******* Date/GSYearToJD *****************************************************
  3625. *
  3626. *   NAME
  3627. *    GSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3628. *
  3629. *   SYNOPSIS
  3630. *    jd = GSYearToJD(syear);
  3631. *    d0         d0
  3632. *
  3633. *    unsigned long GSYearToJD(const unsigned int syear);
  3634. *
  3635. *   FUNCTION
  3636. *    Returns the Julianday of a Scaliger year.
  3637. *
  3638. *   INPUTS
  3639. *    syear     - Scaliger year
  3640. *
  3641. *   RESULT
  3642. *    jd - The Julianday
  3643. *
  3644. *   EXAMPLE
  3645. *    ...
  3646. *    jd = GSYearToJD(4800);
  3647. *    ...
  3648. *
  3649. *   NOTES
  3650. *    It is better to use this function only from 4707 to 7981!
  3651. *
  3652. *   BUGS
  3653. *    unknown.
  3654. *
  3655. *   SEE ALSO
  3656. *    JSYearToJD(),HSYearToJD()
  3657. *
  3658. *****************************************************************************
  3659. *
  3660. *
  3661. */
  3662.  
  3663.  {
  3664.   if (syear < 6296)
  3665.     {/* 1583 */
  3666.      return(JSYearToJD(syear));
  3667.     }
  3668.   else
  3669.     return(JSYearToJD(6296)-10+(unsigned long)(GregorianDayDiff(1,1,AfterGregorianYear+1,1,1,ScaligerYearToG(syear))));
  3670.  }
  3671.  
  3672.  
  3673.  #ifndef __MakeLib
  3674.    unsigned long HSYearToJD(const unsigned int syear)
  3675.  #else
  3676.    unsigned long __saveds __asm HSYearToJD(register __d0 const unsigned int syear)
  3677.  #endif
  3678.  
  3679. /*
  3680. ******* Date/HSYearToJD *****************************************************
  3681. *
  3682. *   NAME
  3683. *    HSYearToJD -- Calcs the JD from a Scaliger year. (V33)
  3684. *
  3685. *   SYNOPSIS
  3686. *    jd = HSYearToJD(syear);
  3687. *    d0         d0
  3688. *
  3689. *    unsigned long HSYearToJD(const unsigned int syear);
  3690. *
  3691. *   FUNCTION
  3692. *    Returns the Julianday of a Scaliger year.
  3693. *
  3694. *   INPUTS
  3695. *    syear     - Scaliger year
  3696. *
  3697. *   RESULT
  3698. *    jd - The Julianday
  3699. *
  3700. *   EXAMPLE
  3701. *    ...
  3702. *    jd = HSYearToJD(6700);
  3703. *    ...
  3704. *
  3705. *   NOTES
  3706. *    It is better to use this function only from 4707 to 7981!
  3707. *    In this version only GSYearToJD() is called, because the
  3708. *    Scaliger period is only valid to 3268
  3709. *
  3710. *   BUGS
  3711. *    unknown.
  3712. *
  3713. *   SEE ALSO
  3714. *    JSYearToJD(),GSYearToJD()
  3715. *
  3716. *****************************************************************************
  3717. *
  3718. *
  3719. */
  3720.  
  3721.  {/* for compatibilitie if GSYearToJD is changed! */
  3722.   return(GSYearToJD(syear));
  3723.  }
  3724.  
  3725.  /* ----------------------------------------------------------------------- */
  3726.  
  3727.  #ifndef __MakeLib
  3728.    unsigned long JDtoMJD(const unsigned long jd)
  3729.  #else
  3730.    unsigned long __saveds __asm JDtoMJD(register __d0 const unsigned long jd)
  3731.  #endif
  3732.  
  3733. /*
  3734. ******* Date/JDtoMJD ********************************************************
  3735. *
  3736. *   NAME
  3737. *    JDtoMJD -- Switches from JD to MJD. (V33)
  3738. *
  3739. *   SYNOPSIS
  3740. *    mjd = JDtoMJD(jd);
  3741. *    d0          d0
  3742. *
  3743. *    unsigned long JDtoMJD(const unsigned long jd);
  3744. *
  3745. *   FUNCTION
  3746. *    Returns the Modified Julianday of a Julianday.
  3747. *
  3748. *   INPUTS
  3749. *    jd - Julianday
  3750. *
  3751. *   RESULT
  3752. *    mjd - The Modified Julianday
  3753. *
  3754. *   EXAMPLE
  3755. *    ...
  3756. *    mjd = JDtoMJD(2449354);
  3757. *    ...
  3758. *
  3759. *   NOTES
  3760. *    none
  3761. *
  3762. *   BUGS
  3763. *    Only use this function for jd > 2400001, because mjd is only
  3764. *    defined for this, otherwise system will crash!
  3765. *
  3766. *   SEE ALSO
  3767. *    MJDtoJD()
  3768. *
  3769. *****************************************************************************
  3770. *
  3771. *
  3772. */
  3773.  
  3774.  {
  3775.   return(jd-2400001L);
  3776.  }
  3777.  
  3778.  
  3779.  #ifndef __MakeLib
  3780.    unsigned long MJDtoJD(const unsigned long mjd)
  3781.  #else
  3782.    unsigned long __saveds __asm MJDtoJD(register __d0 const unsigned long mjd)
  3783.  #endif
  3784.  
  3785. /*
  3786. ******* Date/MJDtoJD ********************************************************
  3787. *
  3788. *   NAME
  3789. *    MJDtoJD -- Switches from MJD to JD. (V33)
  3790. *
  3791. *   SYNOPSIS
  3792. *    jd = MJDtoJD(mjd);
  3793. *    d0         d0
  3794. *
  3795. *    unsigned long MJDtoJD(const unsigned long mjd);
  3796. *
  3797. *   FUNCTION
  3798. *    Returns the Julianday of a Modified Julianday.
  3799. *
  3800. *   INPUTS
  3801. *    mjd - Modified Julianday
  3802. *
  3803. *   RESULT
  3804. *    jd - The Julianday
  3805. *
  3806. *   EXAMPLE
  3807. *    ...
  3808. *    jd = MJDtoJD(49353);
  3809. *    ...
  3810. *
  3811. *   NOTES
  3812. *    none
  3813. *
  3814. *   BUGS
  3815. *    unknown.
  3816. *
  3817. *   SEE ALSO
  3818. *    JDtoMJD()
  3819. *
  3820. *****************************************************************************
  3821. *
  3822. *
  3823. */
  3824.  
  3825.  {
  3826.   return(mjd+2400001L);
  3827.  }
  3828.  
  3829.  /* ----------------------------------------------------------------------- */
  3830.  
  3831.  #ifndef __MakeLib
  3832.    unsigned long JulianToJD(const unsigned short day, const unsigned short month, const int year)
  3833.  #else
  3834.    unsigned long __saveds __asm JulianToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3835.  #endif
  3836.  
  3837. /*
  3838. ******* Date/JulianToJD *****************************************************
  3839. *
  3840. *   NAME
  3841. *    JulianToJD -- Returns the JD for a date. (V33)
  3842. *
  3843. *   SYNOPSIS
  3844. *    jd = JulianToJD(day,month,year);
  3845. *    d0        d0   d1    d2
  3846. *
  3847. *    unsigned long JulianToJD(const unsigned short day,
  3848. *        const unsigned short month, const int year);
  3849. *
  3850. *   FUNCTION
  3851. *    Returns the JD for a Julian date.
  3852. *
  3853. *   INPUTS
  3854. *    day      - day of the date to convert
  3855. *    month    - month of the date to convert
  3856. *    year     - year of the date to convert
  3857. *
  3858. *   RESULT
  3859. *    jd - This is the JD
  3860. *
  3861. *   EXAMPLE
  3862. *    ...
  3863. *    jd = JulianToJD(23,1,1994);
  3864. *    ...
  3865. *
  3866. *   NOTES
  3867. *    It is better to use this function only from 8 to 1582!
  3868. *
  3869. *   BUGS
  3870. *    unknown.
  3871. *
  3872. *   SEE ALSO
  3873. *    JSYearToJD(),JYearToScaliger(),JulianDayDiff(),GregorianToJD(),
  3874. *    HeisToJD()
  3875. *
  3876. *****************************************************************************
  3877. *
  3878. *
  3879. */
  3880.  
  3881.  {
  3882.   return(JSYearToJD(JYearToScaliger(year))+(unsigned long)(JulianDayDiff(1,1,year,day,month,year)));
  3883.  }
  3884.  
  3885.  
  3886.  #ifndef __MakeLib
  3887.    unsigned long GregorianToJD(const unsigned short day, const unsigned short month, const int year)
  3888.  #else
  3889.    unsigned long __saveds __asm GregorianToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3890.  #endif
  3891.  
  3892. /*
  3893. ******* Date/GregorianToJD **************************************************
  3894. *
  3895. *   NAME
  3896. *    GregorianToJD -- Returns the JD for a date. (V33)
  3897. *
  3898. *   SYNOPSIS
  3899. *    jd = GregorianToJD(day,month,year);
  3900. *    d0           d0   d1    d2
  3901. *
  3902. *    unsigned long GregorianToJD(const unsigned short day,
  3903. *        const unsigned short month, const int year);
  3904. *
  3905. *   FUNCTION
  3906. *    Returns the JD for a Gregorian date.
  3907. *
  3908. *   INPUTS
  3909. *    day      - day of the date to convert
  3910. *    month    - month of the date to convert
  3911. *    year     - year of the date to convert
  3912. *
  3913. *   RESULT
  3914. *    jd - This is the JD
  3915. *
  3916. *   EXAMPLE
  3917. *    ...
  3918. *    jd = GregorianToJD(23,1,1994);
  3919. *    ...
  3920. *
  3921. *   NOTES
  3922. *    It is better to use this function only from 8 to 3200!
  3923. *
  3924. *   BUGS
  3925. *    unknown.
  3926. *
  3927. *   SEE ALSO
  3928. *    GSYearToJD(),GYearToScaliger(),GregorianDayDiff(),JulianToJD(),
  3929. *    HeisToJD()
  3930. *
  3931. *****************************************************************************
  3932. *
  3933. *
  3934. */
  3935.  
  3936.  {
  3937.   return(GSYearToJD(GYearToScaliger(year))+(unsigned long)(GregorianDayDiff(1,1,year,day,month,year)));
  3938.  }
  3939.  
  3940.  
  3941.  #ifndef __MakeLib
  3942.    unsigned long HeisToJD(const unsigned short day, const unsigned short month, const int year)
  3943.  #else
  3944.    unsigned long __saveds __asm HeisToJD(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  3945.  #endif
  3946.  
  3947. /*
  3948. ******* Date/HeisToJD *******************************************************
  3949. *
  3950. *   NAME
  3951. *    HeisToJD -- Returns the JD for a date. (V33)
  3952. *
  3953. *   SYNOPSIS
  3954. *    jd = HeisToJD(day,month,year);
  3955. *    d0          d0   d1    d2
  3956. *
  3957. *    unsigned long HeisToJD(const unsigned short day,
  3958. *        const unsigned short month, const int year);
  3959. *
  3960. *   FUNCTION
  3961. *    Returns the JD for a Heis date.
  3962. *
  3963. *   INPUTS
  3964. *    day      - day of the date to convert
  3965. *    month    - month of the date to convert
  3966. *    year     - year of the date to convert
  3967. *
  3968. *   RESULT
  3969. *    jd - This is the JD
  3970. *
  3971. *   EXAMPLE
  3972. *    ...
  3973. *    jd = HeisToJD(23,1,1994);
  3974. *    ...
  3975. *
  3976. *   NOTES
  3977. *    It is better to use this function only from 8 to 3268!
  3978. *
  3979. *   BUGS
  3980. *    unknown.
  3981. *
  3982. *   SEE ALSO
  3983. *    HSYearToJD(),HYearToScaliger(),HeisDayDiff(),JulianToJD(),HeisToJD()
  3984. *
  3985. *****************************************************************************
  3986. *
  3987. *
  3988. */
  3989.  
  3990.  {
  3991.   return(HSYearToJD(HYearToScaliger(year))+(unsigned long)(HeisDayDiff(1,1,year,day,month,year)));
  3992.  }
  3993.  
  3994.  /* ----internal----------------------------------------------------------- */
  3995. /*
  3996.  static unsigned short GregorianSZ(const unsigned int year)
  3997.  
  3998. / *
  3999. *****i* Date/GregorianSZ ****************************************************
  4000. *
  4001. *   NAME
  4002. *    GregorianSZ -- Returns the 'Sonnenzirkel' (V33)
  4003. *
  4004. *   SYNOPSIS
  4005. *    sz = GregorianSZ(year);
  4006. *
  4007. *    unsigned short GregorianSZ(const unsigned int year);
  4008. *
  4009. *   FUNCTION
  4010. *    Returns the 'Sonnenzirkel' of a year.
  4011. *
  4012. *   INPUTS
  4013. *    year     - For this year the 'Sonnenzirkel' is calculated.
  4014. *
  4015. *   RESULT
  4016. *    sz - The 'Sonnenzirkel' for the specified year.
  4017. *
  4018. *   EXAMPLE
  4019. *    ...
  4020. *    sz = GregorianSZ(1994);
  4021. *    ...
  4022. *
  4023. *   NOTES
  4024. *    Use this only for 1582 to 4100!
  4025. *
  4026. *   BUGS
  4027. *    unknown.
  4028. *
  4029. *   SEE ALSO
  4030. *    GYearToScaliger()
  4031. *
  4032. *****************************************************************************
  4033. *
  4034. *
  4035. * /
  4036.  
  4037.  {
  4038.   unsigned short gz;
  4039.   gz = (unsigned short)(GYearToScaliger(year) % 28);
  4040.   if (gz==0)
  4041.     gz = 28;
  4042.   return(gz);
  4043.  }
  4044. */
  4045.  
  4046.  static unsigned short GregorianGZ(const unsigned int year)
  4047.  
  4048. /*
  4049. *****i* Date/GregorianGZ ****************************************************
  4050. *
  4051. *   NAME
  4052. *    GregorianGZ -- Returns the 'Goldene Zahl' (golden number) (V33)
  4053. *
  4054. *   SYNOPSIS
  4055. *    gz = GregorianGZ(year);
  4056. *
  4057. *    unsigned short GregorianGZ(const unsigned int year);
  4058. *
  4059. *   FUNCTION
  4060. *    Returns the 'Goldene Zahl' of a year.
  4061. *
  4062. *   INPUTS
  4063. *    year     - For this year the 'Goldene Zahl' is calculated.
  4064. *
  4065. *   RESULT
  4066. *    gz - The 'Goldene Zahl' for the specified year.
  4067. *
  4068. *   EXAMPLE
  4069. *    ...
  4070. *    gz = GregorianGZ(1994);
  4071. *    ...
  4072. *
  4073. *   NOTES
  4074. *    Use this only for 1582 to 4100!
  4075. *
  4076. *   BUGS
  4077. *    unknown.
  4078. *
  4079. *   SEE ALSO
  4080. *    GYearToScaliger()
  4081. *
  4082. *****************************************************************************
  4083. *
  4084. *
  4085. */
  4086.  
  4087.  {
  4088.   unsigned int syear;
  4089.  
  4090.   syear = GYearToScaliger(year) % 19;
  4091.   if (syear == 0)
  4092.     syear = 19;
  4093.   return((unsigned short)syear);
  4094.  }
  4095.  
  4096.  
  4097.  static unsigned short GEP(const unsigned int year)
  4098.  
  4099. /*
  4100. *****i* Date/GEP ************************************************************
  4101. *
  4102. *   NAME
  4103. *    GEP -- Internal function to help calculate the 'EP' (V33)
  4104. *
  4105. *   SYNOPSIS
  4106. *    hep = GEP(year);
  4107. *
  4108. *    unsigned short GEP(const unsigned int year);
  4109. *
  4110. *   FUNCTION
  4111. *    Internal function to help calculate the 'EP'
  4112. *
  4113. *   INPUTS
  4114. *    year - This is the year for which the help EP is to be
  4115. *        calculated
  4116. *
  4117. *   RESULT
  4118. *    hep - The help value for the EP calculation.
  4119. *
  4120. *   EXAMPLE
  4121. *    ...
  4122. *    hep = GEP(1994);
  4123. *    ...
  4124. *
  4125. *   NOTES
  4126. *    Use this only for 1582 to 4200!
  4127. *
  4128. *   BUGS
  4129. *    unknown.
  4130. *
  4131. *   SEE ALSO
  4132. *
  4133. *
  4134. *****************************************************************************
  4135. *
  4136. *
  4137. */
  4138.  
  4139.    {
  4140.     unsigned short    century,decade;
  4141.     int            ep;
  4142.  
  4143.     ep = 1; /* 1582 */
  4144.     century = (unsigned short)(year / 100);
  4145.     decade = (unsigned short)(year - century * 100);
  4146.     if (year < 1701)
  4147.       return(1);
  4148.     else
  4149.       if (year < 1800)
  4150.         return(0);
  4151.       else
  4152.         {
  4153.          ep -= (int)(((century) % 4) + (((century-16) / 4) * 3));
  4154.          if ((decade == 0) && ((century % 4) > 0))
  4155.            ep++;
  4156.          ep += (int)((century-18) / 3);
  4157.          if ((((century-18) % 3) > 0) || (decade > 0))
  4158.            ep++;
  4159.          if (ep > 29)
  4160.            ep %= 30;
  4161.          if (ep < 0)
  4162.            ep += 30;
  4163.          return((unsigned short)ep);
  4164.         }
  4165.    }
  4166.  
  4167.  
  4168.  static unsigned short GregorianEP(const unsigned int year)
  4169.  
  4170. /*
  4171. *****i* Date/GregorianEP ****************************************************
  4172. *
  4173. *   NAME
  4174. *    GregorianEP -- Returns the 'Epakte' (V33)
  4175. *
  4176. *   SYNOPSIS
  4177. *    ep = GregorianEP(year);
  4178. *
  4179. *    unsigned short GregorianEP(const unsigned int year);
  4180. *
  4181. *   FUNCTION
  4182. *    Returns the 'Epakte' of a year.
  4183. *
  4184. *   INPUTS
  4185. *    year     - For this year the 'Epakte' is calculated.
  4186. *
  4187. *   RESULT
  4188. *    ep - The 'Epakte' for the specified year.
  4189. *
  4190. *   EXAMPLE
  4191. *    ...
  4192. *    ep = GregorianEP(1994);
  4193. *    ...
  4194. *
  4195. *   NOTES
  4196. *    Use this only for 1582 to 4100!
  4197. *
  4198. *   BUGS
  4199. *    unknown.
  4200. *
  4201. *   SEE ALSO
  4202. *    GEP(),GregorianGZ()
  4203. *
  4204. *****************************************************************************
  4205. *
  4206. *
  4207. */
  4208.  
  4209.  {
  4210.   unsigned short ep;
  4211.  
  4212.   if (year >= AfterGregorianYear)
  4213.    {
  4214.     ep = (unsigned short)(((GregorianGZ(year)-1)*11 + GEP(year)) % 30);
  4215.     if (ep == 0)
  4216.       ep = 30;
  4217.     return(ep);
  4218.    }
  4219.   else
  4220.     return(31);
  4221.  }
  4222.  
  4223.  
  4224.  static unsigned short GregorianJHStartSB(const unsigned short century)
  4225.  
  4226. /*
  4227. *****i* Date/GregorianJHStartSB *********************************************
  4228. *
  4229. *   NAME
  4230. *    GregorianJHStartSB -- Returns the 'Sonntagsbuchstabe' (V33)
  4231. *
  4232. *   SYNOPSIS
  4233. *    csb = GregorianJHStartSB(century);
  4234. *
  4235. *    unsigned short GregorianJHStartSB(const unsigned short century);
  4236. *
  4237. *   FUNCTION
  4238. *    Returns start 'SB' for a century.
  4239. *
  4240. *   INPUTS
  4241. *    century - For this century the start 'SB' is calculated.
  4242. *
  4243. *   RESULT
  4244. *    csb - The start 'SB' for the specified century.
  4245. *
  4246. *   EXAMPLE
  4247. *    ...
  4248. *    csb = GregorianJHStartSB(19);
  4249. *    ...
  4250. *
  4251. *   NOTES
  4252. *    Use this only for 15 to 31!
  4253. *
  4254. *   BUGS
  4255. *    unknown.
  4256. *
  4257. *   SEE ALSO
  4258. *    GregorianJHStartSB()
  4259. *
  4260. *****************************************************************************
  4261. *
  4262. *
  4263. */
  4264.  
  4265.  {
  4266.   unsigned short sb;
  4267.  
  4268.   if (century == 15)
  4269.     return(4);
  4270.   else
  4271.    {
  4272.     sb = GregorianJHStartSB(century-1);
  4273.     if ((century % 4) > 0)
  4274.       sb++;
  4275.     sb %= 7;
  4276.     if (sb == 0)
  4277.       sb = 7;
  4278.     return(sb);
  4279.    }
  4280.  }
  4281.  
  4282. /*
  4283.  static unsigned short GregorianJHSB(const unsigned int year)
  4284.  
  4285. / *
  4286. *****i* Date/GregorianSB ****************************************************
  4287. *
  4288. *   NAME
  4289. *    GregorianJHSB -- Returns the 'Sonntagsbuchstabe' (V33)
  4290. *
  4291. *   SYNOPSIS
  4292. *    sb = GregorianJHSB(year);
  4293. *
  4294. *    unsigned short GregorianJHSB(const unsigned int year);
  4295. *
  4296. *   FUNCTION
  4297. *    Returns the start 'SB' for a century year.
  4298. *
  4299. *   INPUTS
  4300. *    year - For this century year the start 'SB' is calculated.
  4301. *
  4302. *   RESULT
  4303. *    sb - The start 'SB' for the specified year.
  4304. *
  4305. *   EXAMPLE
  4306. *    ...
  4307. *    sb = GregorianJHSB(1994);
  4308. *    ...
  4309. *
  4310. *   NOTES
  4311. *    Use this only for 1583 to 3199!
  4312. *
  4313. *   BUGS
  4314. *    unknown.
  4315. *
  4316. *   SEE ALSO
  4317. *    GregorianLeapYear(),GregorianJHStartSB()
  4318. *
  4319. *****************************************************************************
  4320. *
  4321. *
  4322. * /
  4323.  
  4324.  {
  4325.   if (((year % 100) == 0) && (!GregorianLeapYear((int)year)))
  4326.     return((unsigned short)(((year / 100) % 4) *2 +1));
  4327.   else
  4328.     return(GregorianJHStartSB(year / 100));
  4329.  }
  4330. */
  4331. /*
  4332.  static unsigned short GregorianSB(const unsigned int year)
  4333.  
  4334. / *
  4335. *****i* Date/GregorianSB ****************************************************
  4336. *
  4337. *   NAME
  4338. *    GregorianSB -- Returns the 'Sonntagsbuchstabe' (V33)
  4339. *
  4340. *   SYNOPSIS
  4341. *    sb = GregorianSB(year);
  4342. *
  4343. *    unsigned short GregorianSB(const unsigned int year);
  4344. *
  4345. *   FUNCTION
  4346. *    Returns the 'SB' for a year.
  4347. *
  4348. *   INPUTS
  4349. *    year - For this year the 'SB' is calculated.
  4350. *
  4351. *   RESULT
  4352. *    sb - The 'SB' for the specified year.
  4353. *        This means the day the first Sunday lies on :)
  4354. *
  4355. *   EXAMPLE
  4356. *    ...
  4357. *    sb = GregorianSB(1994);
  4358. *    ...
  4359. *
  4360. *   NOTES
  4361. *    Use this only for 1583 to 3199!
  4362. *
  4363. *   BUGS
  4364. *    unknown.
  4365. *
  4366. *   SEE ALSO
  4367. *    GregorianLeapYear(),GregorianSZ(),GregorianJHStartSB()
  4368. *
  4369. *****************************************************************************
  4370. *
  4371. *
  4372. * /
  4373.  
  4374.  {
  4375.   unsigned short sz,csb,i;
  4376.  
  4377.   if (((year % 100) == 0) && (!GregorianLeapYear((int)year)))
  4378.     return((unsigned short)(((year / 100) % 4) *2 +1));
  4379.   else
  4380.    {
  4381.     sz = GregorianSZ(year);
  4382.     csb = GregorianJHStartSB(year / 100);
  4383.     if (sz == 28)
  4384.       return(csb);
  4385.     else
  4386.      {
  4387.       for (i=27;i>=sz;i--)
  4388.        {
  4389.         csb++;
  4390.         if (csb == 8)
  4391.           csb = 1;
  4392.         if (((i-1) % 4) == 0)
  4393.          {
  4394.           csb++;
  4395.           if (csb == 8)
  4396.             csb =1;
  4397.          }
  4398.        }
  4399.       return(csb);
  4400.      }
  4401.    }
  4402.  }
  4403. */
  4404.  
  4405.  static unsigned short MoonMonthAge(const unsigned short month, unsigned short ep, const int year)
  4406.  
  4407. /*
  4408. *****i* Date/MoonMonthAge ***************************************************
  4409. *
  4410. *   NAME
  4411. *    MoonMonthAge -- Calculates the age of the moon on month start (V33)
  4412. *
  4413. *   SYNOPSIS
  4414. *    ep = MoonMonthAge(month,ep);
  4415. *
  4416. *    unsigned short MoonMonthAge(const unsigned short month,
  4417. *       unsigned short ep, const int year);
  4418. *
  4419. *   FUNCTION
  4420. *    Returns the age of the moon on the start of a month.
  4421. *
  4422. *   INPUTS
  4423. *    month - Month for which the age of the moon is needed.
  4424. *    ep    - 'Epakte' of the New Years day.
  4425. *
  4426. *   RESULT
  4427. *    ep - The moonage on the 1. of the specified month.
  4428. *
  4429. *   EXAMPLE
  4430. *    ...
  4431. *    ep = MoonMonthAge(2,17); \* 17 is for 1994 *\
  4432. *    ...
  4433. *
  4434. *   NOTES
  4435. *    This is only a experimental version!
  4436. *
  4437. *   BUGS
  4438. *    unknown.
  4439. *
  4440. *   SEE ALSO
  4441. *    MoonMonthAge(),GregorianMonthDays()
  4442. *
  4443. *****************************************************************************
  4444. *
  4445. *
  4446. */
  4447.  
  4448.    {
  4449.     if (month == 1)
  4450.       return(ep);
  4451.     else
  4452.       if (month % 2 == 0)
  4453.         ep = (unsigned short)((MoonMonthAge(month-1,ep,year) + GregorianMonthDays(month-1,year)) % 29);
  4454.       else
  4455.         ep = (unsigned short)((MoonMonthAge(month-1,ep,year) + GregorianMonthDays(month-1,year)) % 30);
  4456.       return(ep);
  4457.    }
  4458.  
  4459.  /* ----------------------------------------------------------------------- */
  4460.  
  4461.  #ifndef __MakeLib
  4462.    unsigned short GregorianMoonAge(const unsigned short day, const unsigned short month, const int year)
  4463.  #else
  4464.    unsigned short __saveds __asm GregorianMoonAge(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4465.  #endif
  4466.  
  4467. /*
  4468. ******* Date/GregorianMoonAge ***********************************************
  4469. *
  4470. *   NAME
  4471. *    GregorianMoonAge -- Returns the age of the moon (V33)
  4472. *
  4473. *   SYNOPSIS
  4474. *    ep = GregorianMoonAge(day,month,year);
  4475. *    d0               d0   d1   d2
  4476. *
  4477. *    unsigned short GregorianMoonAge(const unsigned short day,
  4478. *        const unsigned short month, const int year);
  4479. *
  4480. *   FUNCTION
  4481. *    Returns the age of the moon on a specified date.
  4482. *
  4483. *   INPUTS
  4484. *    day   - For this day the age is calculated.
  4485. *    month - For this month the age is calculated.
  4486. *    year  - For this year the age is calculated.
  4487. *
  4488. *   RESULT
  4489. *    ep - The age of the moon on the specified date.
  4490. *
  4491. *   EXAMPLE
  4492. *    ...
  4493. *    ep = GregorianMoonAge(18,9,1994);
  4494. *    ...
  4495. *
  4496. *   NOTES
  4497. *    Use this only for 1582 to 4100!
  4498. *    This is only an experimental version!
  4499. *
  4500. *   BUGS
  4501. *    unknown.
  4502. *
  4503. *   SEE ALSO
  4504. *    MoonMonthAge(),GregorianEP(),GregorianMoonPhase()
  4505. *
  4506. *****************************************************************************
  4507. *
  4508. *
  4509. */
  4510.  
  4511.  {
  4512.   unsigned short ep;
  4513.  
  4514.   ep = GregorianEP(year);
  4515.   ep = MoonMonthAge(month,ep,year);
  4516.   ep += day -1;
  4517.   if (month > 1)
  4518.     if (month % 2 == 0)
  4519.       {
  4520.        ep %= 30;
  4521.        if (ep == 0)
  4522.          ep = 30;
  4523.       }
  4524.     else
  4525.       {
  4526.        ep %= 29;
  4527.        if (ep == 0)
  4528.          ep = 29;
  4529.       }
  4530.   else
  4531.     if (ep > 29)
  4532.       ep %= 29;
  4533.   return(ep);
  4534.  }
  4535.  
  4536.  
  4537.  #ifndef __MakeLib
  4538.    #ifndef __cplusplus
  4539.      void JulianEaster(const int year, unsigned short *const dday, unsigned short *const dmonth)
  4540.    #else
  4541.      void JulianEaster(const int year, unsigned short &dday, unsigned short &dmonth)
  4542.    #endif
  4543.  #else
  4544.    void __saveds __asm JulianEaster(register __d0 const int year, register __a0 unsigned short *const dday, register __a1 unsigned short *const dmonth)
  4545.  #endif
  4546.  
  4547. /*
  4548. ******* Date/JulianEaster ***************************************************
  4549. *
  4550. *   NAME
  4551. *    JulianEaster -- Returns the date of Easter in a year (V33.097)
  4552. *
  4553. *   SYNOPSIS
  4554. *    JulianEaster(year,dday,dmonth);
  4555. *              d0   a0    a1
  4556. *
  4557. *    void JulianEaster(const int year, unsigned short *const dday,
  4558. *        unsigned short *const dmonth);
  4559. *
  4560. *    void JulianEaster(const int year, unsigned short &dday,
  4561. *        unsigned short &dmonth);
  4562. *
  4563. *   FUNCTION
  4564. *    Returns the date of Easter for a specified year.
  4565. *
  4566. *   INPUTS
  4567. *    year  - Easter is calculated for this year
  4568. *
  4569. *   RESULT
  4570. *    dday   - day of Easter Sunday
  4571. *    dmonth - month of Easter Sunday
  4572. *
  4573. *   EXAMPLE
  4574. *    ...
  4575. *    JulianEaster(1994,&dday,&dmonth);
  4576. *    ...
  4577. *
  4578. *   NOTES
  4579. *    Use this only for 31 to 1582!
  4580. *
  4581. *   BUGS
  4582. *    None.
  4583. *
  4584. *   SEE ALSO
  4585. *    GregorianEaster(),HeisEaster()
  4586. *
  4587. *****************************************************************************
  4588. *
  4589. *
  4590. */
  4591.  
  4592.  {
  4593.   unsigned short a,b,c;
  4594.  
  4595.   a = (unsigned short)((19*(year%19)+15)%30);
  4596.   b = (unsigned short)((2*(year%4)+4*(year%7)-a+34)%7);
  4597.   c = (unsigned short)(a+b+114);
  4598.   #ifndef __cplusplus
  4599.     *dday = (unsigned short)(c%31 +1);
  4600.     *dmonth = (unsigned short)(c/31);
  4601.   #else
  4602.     dday = (unsigned short)(c%31 +1);
  4603.     dmonth = (unsigned short)(c/31);
  4604.   #endif
  4605.  }
  4606.  
  4607. /*
  4608.  #ifndef __MakeLib
  4609.    void GregorianEaster(const int year, unsigned short *const dday, unsigned short *const dmonth)
  4610.  #else
  4611.    void __saveds __asm GregorianEaster(register __d0 const int year, register __a0 unsigned short *const dday, register __a1 unsigned short *const dmonth)
  4612.  #endif
  4613.  
  4614. / *
  4615. *****i* Date/GregorianEaster ************************************************
  4616. *
  4617. *   NAME
  4618. *    GregorianEaster -- Returns the date of Easter in a year (V33)
  4619. *
  4620. *   SYNOPSIS
  4621. *    GregorianEaster(year,dday,dmonth);
  4622. *             d0   a0    a1
  4623. *
  4624. *    void GregorianEaster(const int year, unsigned short *const dday,
  4625. *        unsigned short *const dmonth);
  4626. *
  4627. *   FUNCTION
  4628. *    Returns the date of Easter for a specified year.
  4629. *
  4630. *   INPUTS
  4631. *    year  - Easter is calculated for this year
  4632. *
  4633. *   RESULT
  4634. *    dday   - day of Easter Sunday
  4635. *    dmonth - month of Easter Sunday
  4636. *
  4637. *   EXAMPLE
  4638. *    ...
  4639. *    GregorianEaster(1994,&dday,&dmonth);
  4640. *    ...
  4641. *
  4642. *   NOTES
  4643. *    Use this only for 1900 to 2099!
  4644. *    Tested for 1977-1994! But this formula is from Gauß - so it must be
  4645. *    correct :) but extended by me (hope this will be a good thing too!)
  4646. *
  4647. *   BUGS
  4648. *    None.
  4649. *
  4650. *   SEE ALSO
  4651. *    GEP(),GregorianJHSB()
  4652. *
  4653. *****************************************************************************
  4654. *
  4655. *
  4656. * /
  4657.  
  4658.  {
  4659.   unsigned short a,d,e,f;
  4660.   short M,N;
  4661.  
  4662.   M = (short)((30 - GEP(year)) - 7);
  4663.   if (M < 0)
  4664.     M += 30;
  4665.   N = (short)(GregorianJHSB(year)-2);
  4666.   if (N<1)
  4667.     N += 7;
  4668.   a = (unsigned short)(year % 19);
  4669.   d = (unsigned short)((19*(unsigned int)a+M) % 30);
  4670.   e = (unsigned short)((2*(unsigned int)(year % 4)+4*(unsigned int)(year % 7)+6*(unsigned int)(d)+N) % 7);
  4671.   f = (unsigned short)(d+e);
  4672.  
  4673.   if (f < 10)
  4674.    {/ * märz * /
  4675.     *dmonth = 3;
  4676.     *dday = (unsigned short)(22+f);
  4677.    }
  4678.   else
  4679.    {/ * april * /
  4680.     *dmonth = 4;
  4681.     *dday = (unsigned short)(f-9);
  4682.     if (*dday==26)
  4683.       *dday = 19;
  4684.     else
  4685.       if ((*dday==25) && (d==28) && (a>10))
  4686.         *dday = 18;
  4687.    }
  4688.  }
  4689. */
  4690.  
  4691.  #ifndef __MakeLib
  4692.    #ifndef __cplusplus
  4693.      void GregorianEaster(const int year, unsigned short *const dday, unsigned short *const dmonth)
  4694.    #else
  4695.      void GregorianEaster(const int year, unsigned short &dday, unsigned short &dmonth)
  4696.    #endif
  4697.  #else
  4698.    void __saveds __asm GregorianEaster(register __d0 const int year, register __a0 unsigned short *const dday, register __a1 unsigned short *const dmonth)
  4699.  #endif
  4700.  
  4701. /*
  4702. ******* Date/GregorianEaster ************************************************
  4703. *
  4704. *   NAME
  4705. *    GregorianEaster -- Returns the date of Easter in a year (V33)
  4706. *
  4707. *   SYNOPSIS
  4708. *    GregorianEaster(year,dday,dmonth);
  4709. *             d0   a0    a1
  4710. *
  4711. *    void GregorianEaster(const int year, unsigned short *const dday,
  4712. *        unsigned short *const dmonth);
  4713. *
  4714. *    void GregorianEaster(const int year, unsigned short &dday,
  4715. *        unsigned short &dmonth);
  4716. *
  4717. *   FUNCTION
  4718. *    Returns the date of Easter for a specified year.
  4719. *
  4720. *   INPUTS
  4721. *    year  - Easter is calculated for this year
  4722. *
  4723. *   RESULT
  4724. *    dday   - day of Easter Sunday
  4725. *    dmonth - month of Easter Sunday
  4726. *
  4727. *   EXAMPLE
  4728. *    ...
  4729. *    GregorianEaster(1994,&dday,&dmonth);
  4730. *    ...
  4731. *
  4732. *   NOTES
  4733. *    Use this only for 31 to 2099!
  4734. *
  4735. *   BUGS
  4736. *    None.
  4737. *
  4738. *   SEE ALSO
  4739. *    JulianEaster(),HeisEaster()
  4740. *
  4741. *****************************************************************************
  4742. *
  4743. *
  4744. */
  4745.  
  4746.  {
  4747.   unsigned short a,b,c,d,e;
  4748.   unsigned int f;
  4749.  
  4750.   if (year <= BeforeGregorianYear)
  4751.    {
  4752.     JulianEaster(year,dday,dmonth);
  4753.    }
  4754.   else
  4755.    {
  4756.     a = (unsigned short)(year % 19);
  4757.     b = (unsigned short)(year / 100);
  4758.     c = (unsigned short)(year % 100);
  4759.     d = (unsigned short)((19*a+b-(b/4)-((b-((b+8)/25)+1)/3)+15) % 30);
  4760.     e = (unsigned short)((32+2*(b%4)+2*(c/4)-d-(c%4)) % 7);
  4761.     f = d+e-7*((a+11*d+22*e)/451)+114;
  4762.     #ifndef __cplusplus
  4763.       *dday = (unsigned short)(f%31 +1);
  4764.       *dmonth = (unsigned short)(f/31);
  4765.     #else
  4766.       dday = (unsigned short)(f%31 +1);
  4767.       dmonth = (unsigned short)(f/31);
  4768.     #endif
  4769.    }
  4770.  }
  4771.  
  4772.  
  4773.  #ifndef __MakeLib
  4774.    #ifndef __cplusplus
  4775.      void HeisEaster(const int year, unsigned short *const dday, unsigned short *const dmonth)
  4776.    #else
  4777.      void HeisEaster(const int year, unsigned short &dday, unsigned short &dmonth)
  4778.    #endif
  4779.  #else
  4780.    void __saveds __asm HeisEaster(register __d0 const int year, register __a0 unsigned short *const dday, register __a1 unsigned short *const dmonth)
  4781.  #endif
  4782.  
  4783. /*
  4784. ******* Date/HeisEaster *****************************************************
  4785. *
  4786. *   NAME
  4787. *    HeisEaster -- Returns the date of Easter in a year (V33)
  4788. *
  4789. *   SYNOPSIS
  4790. *    HeisEaster(year,dday,dmonth);
  4791. *            d0   a0    a1
  4792. *
  4793. *    void HeisEaster(const int year, unsigned short *const dday,
  4794. *        unsigned short *const dmonth);
  4795. *
  4796. *    void HeisEaster(const int year, unsigned short &dday,
  4797. *        unsigned short &dmonth);
  4798. *
  4799. *   FUNCTION
  4800. *    Returns the date of Easter for a specified year.
  4801. *
  4802. *   INPUTS
  4803. *    year  - Easter is calculated for this year
  4804. *
  4805. *   RESULT
  4806. *    dday   - day of Easter Sunday
  4807. *    dmonth - month of Easter Sunday
  4808. *
  4809. *   EXAMPLE
  4810. *    ...
  4811. *    HeisEaster(1994,&dday,&dmonth);
  4812. *    ...
  4813. *
  4814. *   NOTES
  4815. *    This is only a dummy to GregorianEaster!
  4816. *    Use this only for 31 to 2099!
  4817. *
  4818. *   BUGS
  4819. *    Unknown.
  4820. *
  4821. *   SEE ALSO
  4822. *    JulianEaster(),GregorianEaster()
  4823. *
  4824. *****************************************************************************
  4825. *
  4826. *
  4827. */
  4828.  
  4829.  {
  4830.   GregorianEaster(year,dday,dmonth);
  4831.  }
  4832.  
  4833.  /* ----------------------------------------------------------------------- */
  4834.  
  4835.  #ifndef __MakeLib
  4836.    unsigned short JulianWeek(const unsigned short day, const unsigned short month, const int year)
  4837.  #else
  4838.    unsigned short __saveds __asm JulianWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4839.  #endif
  4840.  
  4841. /*
  4842. ******* Date/JulianWeek *****************************************************
  4843. *
  4844. *   NAME
  4845. *    JulianWeek -- Gets the number of the week for a specified date. (V33)
  4846. *
  4847. *   SYNOPSIS
  4848. *    weeknr = JulianWeek(day,month,year);
  4849. *      d0            d0    d1   d2
  4850. *
  4851. *    unsigned short JulianWeek(const unsigned short day,
  4852. *        const unsigned short month, const int year);
  4853. *
  4854. *   FUNCTION
  4855. *    JulianWeek gets the number of the week for a specified date.
  4856. *
  4857. *   INPUTS
  4858. *    day   - day of the date
  4859. *    month - month of the date
  4860. *    year  - year of the date
  4861. *
  4862. *   RESULT
  4863. *    week - This is the number of the week the specified date lies in.
  4864. *        If the first day in a new year is a Friday, Saturday or
  4865. *        Sunday, this would be the last week of the last year!
  4866. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  4867. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  4868. *        first week of the next year!
  4869. *
  4870. *   EXAMPLE
  4871. *    ...
  4872. *    weeknr = JulianWeek(4,10,1582);
  4873. *    ...
  4874. *
  4875. *   NOTES
  4876. *    It is is better only to use this function for years from 0 to 1582!
  4877. *
  4878. *   BUGS
  4879. *    For years < 0 errors could occur.
  4880. *
  4881. *   SEE ALSO
  4882. *    GregorianWeek(),HeisWeek(),JulianWeekday(),JulianDayDiff()
  4883. *
  4884. *****************************************************************************
  4885. *
  4886. *
  4887. */
  4888.  
  4889.  {
  4890.   long days;
  4891.   Weekdays firstweekday;
  4892.  
  4893.    firstweekday = JulianWeekday(1,1,year);
  4894.    days = (JulianDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  4895.    if (firstweekday > Thursday)
  4896.      {
  4897.       if (days == 0)
  4898.         days = JulianWeek(31,12,year-1);
  4899.       else
  4900.         if ((firstweekday == Sunday) && JulianLeapYear(year) && (month == 12) && (day == 31))
  4901.           days = 1;
  4902.       return((unsigned short)days);
  4903.      }
  4904.    else
  4905.      {
  4906.       if (!JulianDaySmaller(day,month,year,29,12,year))
  4907.         {
  4908.          firstweekday = JulianWeekday(day,12,year);
  4909.          switch (day)
  4910.            {
  4911.             case 31 : if (firstweekday == Wednesday)
  4912.                         days = 0;
  4913.             case 30 : if (firstweekday == Tuesday)
  4914.                         days = 0;
  4915.             case 29 : if (firstweekday == Monday)
  4916.                         days = 0;
  4917.                       break;
  4918.             default : ;
  4919.            }
  4920.         }
  4921.       return((unsigned short)(days +1));
  4922.      }
  4923.  }
  4924.  
  4925.  
  4926.  #ifndef __MakeLib
  4927.    unsigned short GregorianWeek(const unsigned short day, const unsigned short month, const int year)
  4928.  #else
  4929.    unsigned short __saveds __asm GregorianWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  4930.  #endif
  4931.  
  4932. /*
  4933. ******* Date/GregorianWeek **************************************************
  4934. *
  4935. *   NAME
  4936. *    GregorianWeek -- Gets the weeknumber for a specified date. (V33)
  4937. *
  4938. *   SYNOPSIS
  4939. *    weeknr = GregorianWeek(day,month,year);
  4940. *      d0            d0   d1   d2
  4941. *
  4942. *    unsigned short GregorianWeek(const unsigned short day,
  4943. *        const unsigned short month, const int year);
  4944. *
  4945. *   FUNCTION
  4946. *    GregorianWeek gets the number of the week for a specified date.
  4947. *
  4948. *   INPUTS
  4949. *    day   - day of the date
  4950. *    month - month of the date
  4951. *    year  - year of the date
  4952. *
  4953. *   RESULT
  4954. *    week - This is the number of the week the specified date lies in.
  4955. *        If the first day in a new year is a Friday, Saturday or
  4956. *        Sunday, this would be the last week of the last year!
  4957. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  4958. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  4959. *        first week of the next year!
  4960. *
  4961. *   EXAMPLE
  4962. *    ...
  4963. *    weeknr = GregorianWeek(4,10,1582);
  4964. *    ...
  4965. *
  4966. *   NOTES
  4967. *    It is better only to use this function for years from 0 to 3000!
  4968. *
  4969. *   BUGS
  4970. *    For years < 0 errors could occur.
  4971. *
  4972. *   SEE ALSO
  4973. *    JulianWeek(),HeisWeek(),GregorianWeekday(),GregorianDayDiff()
  4974. *
  4975. *****************************************************************************
  4976. *
  4977. *
  4978. */
  4979.  
  4980.  {
  4981.   long days;
  4982.   Weekdays firstweekday;
  4983.  
  4984.    firstweekday = GregorianWeekday(1,1,year);
  4985.    days = (GregorianDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  4986.    if (firstweekday > Thursday)
  4987.      {
  4988.       if (days == 0)
  4989.         days = GregorianWeek(31,12,year-1);
  4990.       else
  4991.         if ((firstweekday == Sunday) && GregorianLeapYear(year) && (month == 12) && (day == 31))
  4992.           days = 1;
  4993.       return((unsigned short)days);
  4994.      }
  4995.    else
  4996.      {
  4997.       if (!GregorianDaySmaller(day,month,year,29,12,year))
  4998.         {
  4999.          firstweekday = GregorianWeekday(day,12,year);
  5000.          switch (day)
  5001.            {
  5002.             case 31 : if (firstweekday == Wednesday)
  5003.                         days = 0;
  5004.             case 30 : if (firstweekday == Tuesday)
  5005.                         days = 0;
  5006.             case 29 : if (firstweekday == Monday)
  5007.                         days = 0;
  5008.                       break;
  5009.             default : ;
  5010.            }
  5011.         }
  5012.       return((unsigned short)(days +1));
  5013.      }
  5014.  }
  5015.  
  5016.  
  5017.  #ifndef __MakeLib
  5018.    unsigned short HeisWeek(const unsigned short day, const unsigned short month, const int year)
  5019.  #else
  5020.    unsigned short __saveds __asm HeisWeek(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  5021.  #endif
  5022.  
  5023. /*
  5024. ******* Date/HeisWeek *******************************************************
  5025. *
  5026. *   NAME
  5027. *    HeisWeek -- Gets the number of the week for a specified date. (V33)
  5028. *
  5029. *   SYNOPSIS
  5030. *    weeknr = HeisWeek(day,month,year);
  5031. *      d0           d0  d1    d2
  5032. *
  5033. *    unsigned short HeisWeek(const unsigned short day,
  5034. *        const unsigned short month, const int year);
  5035. *
  5036. *   FUNCTION
  5037. *    HeisWeek gets the number of the week for a specified date.
  5038. *
  5039. *   INPUTS
  5040. *    day   - day of the date
  5041. *    month - month of the date
  5042. *    year  - year of the date
  5043. *
  5044. *   RESULT
  5045. *    week - This is the number of the week the specified date lies in.
  5046. *        If the first day in a new year is a Friday, Saturday or
  5047. *        Sunday, this would be the last week of the last year!
  5048. *        If the 29.12. is a Monday, the 30.12. is a Monday or a Tuesday,
  5049. *        the 31.12. is a Monday, Tuesday or a Wednesday this is the
  5050. *        first week of the next year!
  5051. *
  5052. *   EXAMPLE
  5053. *    ...
  5054. *    weeknr = HeisWeek(4,10,1582);
  5055. *    ...
  5056. *
  5057. *   NOTES
  5058. *    It is better only to use this function for years from 0 to 8000!
  5059. *
  5060. *   BUGS
  5061. *    For years < 0 errors could occur.
  5062. *
  5063. *   SEE ALSO
  5064. *    JulianWeek(),GregorianWeek(),HeisWeekday(),HeisDayDiff()
  5065. *
  5066. *****************************************************************************
  5067. *
  5068. *
  5069. */
  5070.  
  5071.  {
  5072.   long days;
  5073.   Weekdays firstweekday;
  5074.  
  5075.    firstweekday = HeisWeekday(1,1,year);
  5076.    days = (HeisDayDiff(1,1,year,day,month,year) + (long)firstweekday -1) / 7;
  5077.    if (firstweekday > Thursday)
  5078.      {
  5079.       if (days == 0)
  5080.         days = HeisWeek(31,12,year-1);
  5081.       else
  5082.         if ((firstweekday == Sunday) && HeisLeapYear(year) && (month == 12) && (day == 31))
  5083.           days = 1;
  5084.       return((unsigned short)days);
  5085.      }
  5086.    else
  5087.      {
  5088.       if (!HeisDaySmaller(day,month,year,29,12,year))
  5089.         {
  5090.          firstweekday = HeisWeekday(day,12,year);
  5091.          switch (day)
  5092.            {
  5093.             case 31 : if (firstweekday == Wednesday)
  5094.                         days = 0;
  5095.             case 30 : if (firstweekday == Tuesday)
  5096.                         days = 0;
  5097.             case 29 : if (firstweekday == Monday)
  5098.                         days = 0;
  5099.                       break;
  5100.             default : ;
  5101.            }
  5102.         }
  5103.       return((unsigned short)(days +1));
  5104.      }
  5105.  }
  5106.  
  5107.  /* ----------------------------------------------------------------------- */
  5108.  
  5109.  #ifndef __MakeLib
  5110.    unsigned short WeekdayText(const Weekdays wday, char *const wtext, Languages lang)
  5111.  #else
  5112.    unsigned short __saveds __asm WeekdayText(register __d0 const Weekdays wday, register __a0 char *const wtext, register __d1 Languages lang)
  5113.  #endif
  5114.  
  5115. /*
  5116. ******* Date/WeekdayText ****************************************************
  5117. *
  5118. *   NAME
  5119. *    WeekdayText -- Get the weekday as text string. (V33.091)
  5120. *
  5121. *   SYNOPSIS
  5122. *    maxlen = WeekdayText(wday,wtext,lang);
  5123. *      d0                  d0   a0    d1
  5124. *
  5125. *    unsigned short WeekdayText(const Weekdays wday, char *const wtext,
  5126. *        Languages lang);
  5127. *
  5128. *   FUNCTION
  5129. *    This function gets the text string for the weekday-number.
  5130. *
  5131. *   INPUTS
  5132. *    wday  - Weekday to transform into a string.
  5133. *    wtext - Pointer to a string to fill in the weekday-text.
  5134. *    lang  - Language for wich you want the weekday-text.
  5135. *
  5136. *   RESULT
  5137. *    maxlen - Maximum possible length for the weekday-string, this should
  5138. *        help you if you want to justify the string right or if you
  5139. *        want to center it!
  5140. *        0 indicates an error!
  5141. *
  5142. *   EXAMPLE
  5143. *    ...
  5144. *    char wtxt[20];
  5145. *    ...
  5146. *    maxlen = WeekdayText(Monday,&wtxt,English);
  5147. *    ...
  5148. *
  5149. *   NOTES
  5150. *    Available languages:
  5151. *    Locale    : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5152. *                and other systems it will return English text!
  5153. *    English
  5154. *    Deutsch
  5155. *    français  : For non ISO8859_Latin1-systems this is called francais!
  5156. *    español   : For non ISO8859_Latin1-systems this is called espanol!
  5157. *    português : For non ISO8859_Latin1-systems this is called portugues!
  5158. *    dansk
  5159. *    italiano
  5160. *    nederlands
  5161. *    norsk
  5162. *    svenska
  5163. *    polski
  5164. *    suomalainen
  5165. *
  5166. *   BUGS
  5167. *    In this version there is no check, if there is enough space in
  5168. *    wtext!
  5169. *
  5170. *   SEE ALSO
  5171. *    MonthText(),WeekdayShortText(),MonthShortText()
  5172. *
  5173. *****************************************************************************
  5174. *
  5175. *
  5176. */
  5177.  
  5178.  {
  5179.   unsigned short len=0;
  5180.   const unsigned short WEEKDAYMAXLEN[13]   = {0,9,10,8,9,13,7,10,9,7,7,12,11};
  5181.   const char           WEEKDAYS[13][8][14] = {{"","","","","","","",""},
  5182.                                               {"","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"},
  5183.                                               {"","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"},
  5184.                                               {"","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"},
  5185.                                               {"","lunes","martes",
  5186.                                                #ifdef _ISO8859_Latin1
  5187.                                                  "miércoles"
  5188.                                                #else
  5189.                                                  "miercoles"
  5190.                                                #endif
  5191.                                                ,"jueves","viernes",
  5192.                                                #ifdef _ISO8859_Latin1
  5193.                                                  "sábado"
  5194.                                                #else
  5195.                                                  "sabado"
  5196.                                                #endif
  5197.                                                ,"domingo"},
  5198.                                               {"","Segunda-feira","Terça-feira","Quarta-feira","Quinta-feira","Sexta-feira","Sábado","Domingo"},
  5199.                                               {"","Mandag","Tirsdag","Onsdag","Torsdag","Fredag",
  5200.                                                #ifdef _ISO8859_Latin1
  5201.                                                  "Lørdag","Søndag"
  5202.                                                #else
  5203.                                                  "Lordag","Sondag"
  5204.                                                #endif
  5205.                                               },
  5206.                                               {"",
  5207.                                                #ifdef _ISO8859_Latin1
  5208.                                                  "Lunedì","Martedì","Mercoledì","Giovedì","Venerdì"
  5209.                                                #else
  5210.                                                  "Lunedi","Martedi","Mercoledi","Giovedi","Venerdi"
  5211.                                                #endif
  5212.                                                ,"Sabato","Domenica"},
  5213.                                               {"","maandag","dinsdag","woensdag","donderdag","vrijdag","zaterdag","zondag"},
  5214.                                               {"","Mandag","Tirsdag","Onsdag","Torsdag","Fredag",
  5215.                                                #ifdef _ISO8859_Latin1
  5216.                                                  "Lørdag","Søndag"
  5217.                                                #else
  5218.                                                  "Lordag","Sondag"
  5219.                                                #endif
  5220.                                               },
  5221.                                               {"",
  5222.                                                #ifdef _ISO8859_Latin1
  5223.                                                  "Måndag"
  5224.                                                #else
  5225.                                                  "Mandag"
  5226.                                                #endif
  5227.                                                ,"Tisdag","Onsdag","Torsdag","Fredag",
  5228.                                                #ifdef _ISO8859_Latin1
  5229.                                                  "Lördag","Söndag"
  5230.                                                #else
  5231.                                                  "Lordag","Sondag"
  5232.                                                #endif
  5233.                                               },
  5234.                                               {"",
  5235.                                                #ifdef _ISO8859_Latin1
  5236.                                                  "Poniedzia?ek"
  5237.                                                #else
  5238.                                                  "Poniedzialek"
  5239.                                                #endif
  5240.                                                ,"Wtorek",
  5241.                                                #ifdef _ISO8859_Latin1
  5242.                                                  "?roda"
  5243.                                                #else
  5244.                                                  "Sroda"
  5245.                                                #endif
  5246.                                                ,"Czwartek",
  5247.                                                #ifdef _ISO8859_Latin1
  5248.                                                  "Pi?tek"
  5249.                                                #else
  5250.                                                  "Piatek"
  5251.                                                #endif
  5252.                            ,"Sobota","Niedziela"},
  5253.                           {"","maanantai","tiistai","keskiviikko","torstai","perjantai","lauantai","sunnuntai"}
  5254.                                              };
  5255.  
  5256.   if (wtext != NULL)
  5257.    {
  5258.     wtext[0] = '\0';
  5259.     switch (lang)
  5260.      {
  5261.       case Locale :
  5262.       #ifdef _AMIGA
  5263.                     if (locale != NULL)
  5264.                      {
  5265.                       len = wlen;
  5266.                       switch (wday)
  5267.                        {
  5268.                         case Sunday : strcpy(wtext,GetLocaleStr(locale,DAY_1));
  5269.                                       break;
  5270.                         case dayerr : len = 0;
  5271.                                       break;
  5272.                         default     : strcpy(wtext,GetLocaleStr(locale,DAYS[(unsigned short)wday]));
  5273.                        }
  5274.                       break;
  5275.                      }
  5276.       #endif
  5277.                     lang = English;
  5278.       default     : len = WEEKDAYMAXLEN[(unsigned short)lang];
  5279.                     if (wday == dayerr)
  5280.                       len = 0;
  5281.                     else
  5282.                       strcpy(wtext,WEEKDAYS[(unsigned short)lang][(unsigned short)wday]);
  5283.      }
  5284.    }
  5285.   return(len);
  5286.  }
  5287.  
  5288.  
  5289.  #ifndef __MakeLib
  5290.    unsigned short MonthText(const unsigned short month, char *const mtext, Languages lang)
  5291.  #else
  5292.    unsigned short __saveds __asm MonthText(register __d0 const unsigned short month, register __a0 char *const mtext, register __d1 Languages lang)
  5293.  #endif
  5294.  
  5295. /*
  5296. ******* Date/MonthText ******************************************************
  5297. *
  5298. *   NAME
  5299. *    MonthText -- Get the month as text string. (V33.091)
  5300. *
  5301. *   SYNOPSIS
  5302. *    maxlen = MonthText(month,mtext,lang);
  5303. *     d0                 d0   a0    d1
  5304. *
  5305. *    unsigned short MonthText(const unsigned short month,
  5306. *        char *const mtext, Languages lang);
  5307. *
  5308. *   FUNCTION
  5309. *    This function gets the text string for the month-number.
  5310. *
  5311. *   INPUTS
  5312. *    month - Month to transform into a string.
  5313. *    mtext - Pointer to a string to fill in the month-text.
  5314. *    lang  - Language for which you want the month-text.
  5315. *
  5316. *   RESULT
  5317. *    maxlen - Maximum possible length for the month-string, this should
  5318. *        help you if you want to justify the string right or if you
  5319. *        want to center it!
  5320. *        0 indicates an error!
  5321. *
  5322. *   EXAMPLE
  5323. *    ...
  5324. *    char mtxt[20];
  5325. *    ...
  5326. *    maxlen = MonthText(12,&mtxt,English);
  5327. *    ...
  5328. *
  5329. *   NOTES
  5330. *    Available languages:
  5331. *    Locale    : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5332. *                and other systems it will return English text!
  5333. *    English
  5334. *    Deutsch
  5335. *    français  : For non ISO8859_Latin1-systems this is called francais!
  5336. *    español   : For non ISO8859_Latin1-systems this is called espanol!
  5337. *    português : For non ISO8859_Latin1-systems this is called portugues!
  5338. *    dansk
  5339. *    italiano
  5340. *    nederlands
  5341. *    norsk
  5342. *    svenska
  5343. *    polski
  5344. *    suomalainen
  5345. *
  5346. *   BUGS
  5347. *    In this version there is no check, if there is enough space in
  5348. *    wtext!
  5349. *
  5350. *   SEE ALSO
  5351. *    WeekdayText(),WeekdayShortText(),MonthShortText()
  5352. *
  5353. *****************************************************************************
  5354. *
  5355. *
  5356. */
  5357.  
  5358.  {
  5359.   unsigned short len=0;
  5360.   const unsigned short MONTHMAXLEN[13]    = {0,9,9,9,10,9,9,9,9,9,9,11,9};
  5361.   const char           MONTHS[13][13][12] = {{"","","","","","","","","","","","",""},
  5362.                                              {"","January","February","March","April","May","June","July","August","September","October","November","December"},
  5363.                                              {"","Januar","Februar",
  5364.                                               #ifdef _ISO8859_Latin1
  5365.                                                 "März"
  5366.                                               #else
  5367.                                                 "Maerz"
  5368.                                               #endif
  5369.                                               ,"April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"},
  5370.                                              {"","Janvier",
  5371.                                               #ifdef _ISO8859_Latin1
  5372.                                                 "Février"
  5373.                                               #else
  5374.                                                 "Fevrier"
  5375.                                               #endif
  5376.                                               ,"Mars","Avril","Mai","Juin","Juillet",
  5377.                                               #ifdef _ISO8859_Latin1
  5378.                                                 "Août"
  5379.                                               #else
  5380.                                                 "Aout"
  5381.                                               #endif
  5382.                                               ,"Septembre","Octobre","Novembre",
  5383.                                               #ifdef _ISO8859_Latin1
  5384.                                                 "Décembre"
  5385.                                               #else
  5386.                                                 "Decembre"
  5387.                                               #endif
  5388.                                              },
  5389.                                              {"","enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre"},
  5390.                                              {"","Janeiro","Fevereiro",
  5391.                                               #ifdef _ISO8859_Latin1
  5392.                                                 "Março"
  5393.                                               #else
  5394.                                                 "Marco"
  5395.                                               #endif
  5396.                                               ,"Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"},
  5397.                                              {"","Januar","Februar","Marts","April","Maj","Juni","Juli","August","September","Oktober","November","December"},
  5398.                                              {"","Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"},
  5399.                                              {"","januari","februari","maart","april","mei","juni","juli","augustus","september","oktober","november","december"},
  5400.                                              {"","Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"},
  5401.                                              {"","Januari","Februari","Mars","April","Maj","Juni","Juli","Augusti","September","Oktober","November","December"},
  5402.                                              {"",
  5403.                                               #ifdef _ISO8859_Latin1
  5404.                                                 "Stycze?"
  5405.                                               #else
  5406.                                                 "Styczen"
  5407.                                               #endif
  5408.                                               ,"Luty","Marzec",
  5409.                                               #ifdef _ISO8859_Latin1
  5410.                                                 "Kwiecie?"
  5411.                                               #else
  5412.                                                 "Kwiecien"
  5413.                                               #endif
  5414.                                               ,"Maj","Czerwiec","Lipiec",
  5415.                                               #ifdef _ISO8859_Latin1
  5416.                                                 "Sierpie?","Wrzesie?","Pa?dziernik"
  5417.                                               #else
  5418.                                                 "Sierpien","Wrzesien","Pazdziernik"
  5419.                                               #endif
  5420.                                               ,"Listopad",
  5421.                                               #ifdef _ISO8859_Latin1
  5422.                                                 "Grudzie?"
  5423.                                               #else
  5424.                                                 "Grudzien"
  5425.                                               #endif
  5426.                                              },
  5427.                                              {"","tammikuu","helmikuu","maaliskuu","huhtikuu","toukokuu",
  5428.                                               #ifdef _ISO8859_Latin1
  5429.                                                 "kes?kuu","hein?kuu"
  5430.                                               #else
  5431.                                                 "kesakuu","heinakuu"
  5432.                                               #endif
  5433.                                               ,"elokuu","syyskuu","lokakuu","marraskuu","joulukuu"}
  5434.                                             };
  5435.  
  5436.   if (mtext != NULL)
  5437.    {
  5438.     mtext[0] = '\0';
  5439.     if (!((month > 0) && (month < 13)))
  5440.       return(0);
  5441.     switch (lang)
  5442.      {
  5443.       case Locale  :
  5444.       #ifdef _AMIGA
  5445.                      if (locale != NULL)
  5446.                       {
  5447.                        len = mlen;
  5448.                        strcpy(mtext,GetLocaleStr(locale,MONS[month-1]));
  5449.                        break;
  5450.                       }
  5451.       #endif
  5452.                      lang = English;
  5453.       default      : len = MONTHMAXLEN[(unsigned short)lang];
  5454.                      strcpy(mtext,MONTHS[(unsigned short)lang][month]);
  5455.      }
  5456.    }
  5457.   return(len);
  5458.  }
  5459.  
  5460.  /* ----------------------------------------------------------------------- */
  5461.  
  5462.  #ifndef __MakeLib
  5463.    unsigned short WeekdayShortText(const Weekdays wday, char *const wtext, Languages lang)
  5464.  #else
  5465.    unsigned short __saveds __asm WeekdayShortText(register __d0 const Weekdays wday, register __a0 char *const wtext, register __d1 Languages lang)
  5466.  #endif
  5467.  
  5468. /*
  5469. ******* Date/WeekdayShortText ***********************************************
  5470. *
  5471. *   NAME
  5472. *    WeekdayShortText -- Get the weekday as short text string. (V33.092)
  5473. *
  5474. *   SYNOPSIS
  5475. *    maxlen = WeekdayShortText(wday,wtext,lang);
  5476. *    d0                         d0   a0    d1
  5477. *
  5478. *    unsigned short WeekdayShortText(const Weekdays wday,
  5479.         char *const wtext, Languages lang);
  5480. *
  5481. *   FUNCTION
  5482. *    This function gets the short text string for the weekday-number.
  5483. *
  5484. *   INPUTS
  5485. *    wday  - Weekday to transform into a string.
  5486. *    wtext - Pointer to a string to fill in the short weekday-text.
  5487. *    lang  - Language for wich you want the short weekday-text.
  5488. *
  5489. *   RESULT
  5490. *    maxlen - Maximum possible length for the weekday-string, this should
  5491. *        help you if you want to justify the string right or if you
  5492. *        want to center it! (Normal it's two or three!)
  5493. *        0 indicates an error!
  5494. *
  5495. *   EXAMPLE
  5496. *    ...
  5497. *    char wtxt[3];
  5498. *    ...
  5499. *    maxlen = WeekdayShortText(Monday,&wtxt,English);
  5500. *    ...
  5501. *
  5502. *   NOTES
  5503. *    Available languages:
  5504. *    Locale    : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5505. *                and other systems it will return English text!
  5506. *    English
  5507. *    Deutsch
  5508. *    français  : For non ISO8859_Latin1-systems this is called francais!
  5509. *    español   : For non ISO8859_Latin1-systems this is called espanol!
  5510. *    português : For non ISO8859_Latin1-systems this is called portugues!
  5511. *    dansk
  5512. *    italiano
  5513. *    nederlands
  5514. *    norsk
  5515. *    svenska
  5516. *    polski
  5517. *    suomalainen
  5518. *
  5519. *   BUGS
  5520. *    In this version there is no check, if there is enough space in
  5521. *    wtext!
  5522. *
  5523. *   SEE ALSO
  5524. *    WeekdayText(),MonthText(),MonthShortText()
  5525. *
  5526. *****************************************************************************
  5527. *
  5528. *
  5529. */
  5530.  
  5531.  {
  5532.   unsigned short len=0;
  5533.   const unsigned short WEEKDAYMAXLEN[13]  = {0,3,2,3,3,3,
  5534.                                              #ifdef _ISO8859_Latin1
  5535.                                                3
  5536.                                              #else
  5537.                                                4
  5538.                                              #endif
  5539.                                              ,3,2,
  5540.                                              #ifdef _ISO8859_Latin1
  5541.                                                3,3
  5542.                                              #else
  5543.                                                4,4
  5544.                                              #endif
  5545.                                              ,3,3
  5546.                                             };
  5547.   const char           WEEKDAYS[13][8][5] = {{"","","","","","","",""},
  5548.                                              {"","Mon","Tue","Wed","Thu","Fri","Sat","Sun"},
  5549.                                              {"","Mo","Di","Mi","Do","Fr","Sa","So"},
  5550.                                              {"","Lun","Mar","Mer","Jeu","Ven","Sam","Dim"},
  5551.                                              {"","lun","mar","mie","jue","vie","sab","dom"},
  5552.                                              {"","Seg","Ter","Qua","Qui","Sex","Sab","Dom"},
  5553.                                              {"","Man","Tir","Ons","Tor","Fre",
  5554.                                               #ifdef _ISO8859_Latin1
  5555.                                                 "Lør","Søn"
  5556.                                               #else
  5557.                                                 "Lo/r","So/n"
  5558.                                               #endif
  5559.                                              },
  5560.                                              {"","Lun","Mar","Mer","Gio","Ven","Sab","Dom"},
  5561.                                              {"","ma","di","wo","do","vr","za","zo"},
  5562.                                              {"","Man","Tir","Ons","Tor","Fre",
  5563.                                               #ifdef _ISO8859_Latin1
  5564.                                                 "Lør","Søn"
  5565.                                               #else
  5566.                                                 "Lo/r","So/n"
  5567.                                               #endif
  5568.                                              },
  5569.                                              {"",
  5570.                                               #ifdef _ISO8859_Latin1
  5571.                                                 "Mån"
  5572.                                               #else
  5573.                                                 "Ma?n"
  5574.                                               #endif
  5575.                                               ,"Tis","Ons","Tor","Fre",
  5576.                                               #ifdef _ISO8859_Latin1
  5577.                                                 "Lör","Sön"
  5578.                                               #else
  5579.                                                 "Lo?r","So?n"
  5580.                                               #endif
  5581.                                              },
  5582.                                              {"","Pon","Wto",
  5583.                                               #ifdef _ISO8859_Latin1
  5584.                                                 "?ro"
  5585.                                               #else
  5586.                                                 "Sro"
  5587.                                               #endif
  5588.                                               ,"Czw",
  5589.                                               #ifdef _ISO8859_Latin1
  5590.                                                 "Pi?"
  5591.                                               #else
  5592.                                                 "Pia"
  5593.                                               #endif
  5594.                                               ,"Sob","Nie"},
  5595.                                              {"","maa","tii","kes","tor","per","lau","sun"}
  5596.                                             };
  5597.  
  5598.   if (wtext != NULL)
  5599.    {
  5600.     wtext[0] = '\0';
  5601.     switch (lang)
  5602.      {
  5603.       case Locale :
  5604.       #ifdef _AMIGA
  5605.                     if (locale != NULL)
  5606.                      {
  5607.                       len = abwlen;
  5608.                       switch (wday)
  5609.                        {
  5610.                         case Sunday : strcpy(wtext,GetLocaleStr(locale,ABDAY_1));
  5611.                                       break;
  5612.                         case dayerr : len = 0;
  5613.                                       break;
  5614.                         default     : strcpy(wtext,GetLocaleStr(locale,ABDAYS[(unsigned short)wday]));
  5615.                        }
  5616.                       break;
  5617.                      }
  5618.       #endif
  5619.                     lang = English;
  5620.       default     : len = WEEKDAYMAXLEN[(unsigned short)lang];
  5621.                     if (wday == dayerr)
  5622.                       len = 0;
  5623.                     else
  5624.                       strcpy(wtext,WEEKDAYS[(unsigned short)lang][(unsigned short)wday]);
  5625.      }
  5626.    }
  5627.   return(len);
  5628.  }
  5629.  
  5630.  
  5631.  #ifndef __MakeLib
  5632.    unsigned short MonthShortText(const unsigned short month, char *const mtext, Languages lang)
  5633.  #else
  5634.    unsigned short __saveds __asm MonthShortText(register __d0 const unsigned short month, register __a0 char *const mtext, register __d1 Languages lang)
  5635.  #endif
  5636.  
  5637. /*
  5638. ******* Date/MonthShortText *************************************************
  5639. *
  5640. *   NAME
  5641. *    MonthShortText -- Get the month as short text string. (V33.092)
  5642. *
  5643. *   SYNOPSIS
  5644. *    maxlen = MonthShortText(month,mtext,lang);
  5645. *     d0                       d0   a0    d1
  5646. *
  5647. *    unsigned short MonthShortText(const unsigned short month,
  5648. *        char *const mtext, Languages lang);
  5649. *
  5650. *   FUNCTION
  5651. *    This function gets the short text string for the month-number.
  5652. *
  5653. *   INPUTS
  5654. *    month - Month to transform into a string.
  5655. *    mtext - Pointer to a string to fill in the short month-text.
  5656. *    lang  - Language for which you want the short month-text.
  5657. *
  5658. *   RESULT
  5659. *    maxlen - Maximum possible length for the short month-string, this
  5660. *        should help you if you want to justify the string right or if
  5661. *        you want to center it (Normal is three!).
  5662. *        0 indicates an error!
  5663. *
  5664. *   EXAMPLE
  5665. *    ...
  5666. *    char mtxt[4];
  5667. *    ...
  5668. *    maxlen = MonthShortText(12,&mtxt,English);
  5669. *    ...
  5670. *
  5671. *   NOTES
  5672. *    Available languages:
  5673. *    Locale    : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5674. *                and other systems it will return English text!
  5675. *    English
  5676. *    Deutsch
  5677. *    français  : For non ISO8859_Latin1-systems this is called francais!
  5678. *    español   : For non ISO8859_Latin1-systems this is called espanol!
  5679. *    português : For non ISO8859_Latin1-systems this is called portugues!
  5680. *    dansk
  5681. *    italiano
  5682. *    nederlands
  5683. *    norsk
  5684. *    svenska
  5685. *    polski
  5686. *    suomalainen
  5687. *
  5688. *   BUGS
  5689. *    In this version there is no check, if there is enough space in
  5690. *    wtext!
  5691. *
  5692. *   SEE ALSO
  5693. *    WeekdayText(),WeekdayShortText(),MonthText()
  5694. *
  5695. *****************************************************************************
  5696. *
  5697. *
  5698. */
  5699.  
  5700.  {
  5701.   unsigned short len=0;
  5702.   const unsigned short MONTHMAXLEN[13]   = {0,3,3,
  5703.                                             #ifdef _ISO8859_Latin1
  5704.                                               4
  5705.                                             #else
  5706.                                               5
  5707.                                             #endif
  5708.                                              ,3,3,3,3,3,3,3,3,3};
  5709.   const char           MONTHS[13][13][6] = {{"","","","","","","","","","","","",""},
  5710.                                             {"","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
  5711.                                             {"","Jan","Feb",
  5712.                                              #ifdef _ISO8859_Latin1
  5713.                                                "Mär"
  5714.                                              #else
  5715.                                                "Maer"
  5716.                                              #endif
  5717.                                              ,"Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"},
  5718.                                             {"","Jan",
  5719.                                              #ifdef _ISO8859_Latin1
  5720.                                                "Fév"
  5721.                                              #else
  5722.                                                "Fe'v"
  5723.                                              #endif
  5724.                                              ,"Mars","Avr","Mai","Juin","Juil",
  5725.                                              #ifdef _ISO8859_Latin1
  5726.                                                "Août"
  5727.                                              #else
  5728.                                                "Aou^t"
  5729.                                              #endif
  5730.                                              ,"Sep","Oct","Nov",
  5731.                                              #ifdef _ISO8859_Latin1
  5732.                                                "Déc"
  5733.                                              #else
  5734.                                                "De'c"
  5735.                                              #endif
  5736.                                             },
  5737.                                             {"","ene","feb","mar","abr","may","jun","jul","ago","sep","oct","nov","dic"},
  5738.                                             {"","Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"},
  5739.                                             {"","Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec"},
  5740.                                             {"","Gen","Feb","Mar","Apr","Mag","Giu","Lug","Ago","Set","Ott","Nov","Dic"},
  5741.                                             {"","jan","feb","maa","apr","mei","jun","jul","aug","sep","oct","nov","dec"},
  5742.                                             {"","Jan","Feb","Mar","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Des"},
  5743.                                             {"","Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec"},
  5744.                                             {"","Sty","Lut","Mar","Kwi","Maj","Cze","Lip","Sie","Wrz","Pa?","Lis","Gru"},
  5745.                                             {"","tam","hel","maa","huh","tou","kes","hei","elo","syy","lok","mar","jou"}
  5746.                                            };
  5747.  
  5748.   if (mtext != NULL)
  5749.    {
  5750.     mtext[0] = '\0';
  5751.     if (!((month > 0) && (month < 13)))
  5752.       return(0);
  5753.     switch (lang)
  5754.      {
  5755.       case Locale  :
  5756.       #ifdef _AMIGA
  5757.                      if (locale != NULL)
  5758.                       {
  5759.                        len = abmlen;
  5760.                        strcpy(mtext,GetLocaleStr(locale,ABMONS[month-1]));
  5761.                        break;
  5762.                       }
  5763.       #endif
  5764.                      lang = English;
  5765.       default      : len = MONTHMAXLEN[(unsigned short)lang];
  5766.                      strcpy(mtext,MONTHS[(unsigned short)lang][month]);
  5767.      }
  5768.    }
  5769.   return(len);
  5770.  }
  5771.  
  5772.  
  5773.  #ifndef __MakeLib
  5774.    void DateText(const DateTexts dt, char *const text, Languages lang, const bool plural)
  5775.  #else
  5776.    void __saveds __asm DateText(register __d0 const DateTexts dt, register __a0 char *const text, register __d1 Languages lang, register __d2 const bool plural)
  5777.  #endif
  5778.  
  5779. /*
  5780. ******* Date/DateText *******************************************************
  5781. *
  5782. *   NAME
  5783. *    DateText -- Get a date text string. (V33.130)
  5784. *
  5785. *   SYNOPSIS
  5786. *    DateText(dt,mtext,lang,plural);
  5787. *             d0  a0    d1    d2
  5788. *
  5789. *    void DateText(const DateTexts dt, char *const text,
  5790. *        Languages lang, const bool plural);
  5791. *
  5792. *   FUNCTION
  5793. *    This function gets a date specified text in each supported language
  5794. *
  5795. *   INPUTS
  5796. *    dt     - The text you want.
  5797. *    text   - Pointer to a string to fill in the text.
  5798. *    lang   - Language for which you want the text.
  5799. *    plural - false: The singular form is given.
  5800. *             true : The plural form is given.
  5801. *
  5802. *   RESULT
  5803. *    None
  5804. *
  5805. *   EXAMPLE
  5806. *    ...
  5807. *    char txt[20];
  5808. *    ...
  5809. *    DateText(day,&txt,English,false);
  5810. *    ...
  5811. *
  5812. *   NOTES
  5813. *    Available languages:
  5814. *    Locale    : This is an Amiga >= OS2.1 only feature, for <= OS2.0
  5815. *                and other systems it will return English text!
  5816. *    English
  5817. *    Deutsch
  5818. *    français  : For non ISO8859_Latin1-systems this is called francais!
  5819. *    español   : For non ISO8859_Latin1-systems this is called espanol!
  5820. *    português : For non ISO8859_Latin1-systems this is called portugues!
  5821. *    dansk
  5822. *    italiano
  5823. *    nederlands
  5824. *    norsk
  5825. *    svenska
  5826. *    polski
  5827. *    suomalainen
  5828. *
  5829. *    Available strings:
  5830. *    DAY,MONTH,YEAR,WEEK,WEEKDAY,HOUR,MINUTE,SECOND,YESTERDAY,TODAY,
  5831. *    TOMORROW
  5832. *
  5833. *    In the moment there is only the singular text available!!!
  5834. *
  5835. *   BUGS
  5836. *    In this version there is no check, if there is enough space in
  5837. *    text!
  5838. *
  5839. *   SEE ALSO
  5840. *    WeekdayText(),WeekdayShortText(),MonthText(),MonthShortText()
  5841. *
  5842. *****************************************************************************
  5843. *
  5844. *
  5845. */
  5846.  
  5847.  {
  5848.   const char           DATETEXTS[13][11][17] = {{"","","","","","","","","","",""},
  5849.                                                 {"day","month","year","week","weekday","hour","minute","second","yesterday","today","tomorrow"},
  5850.                                                 {"Tag","Monat","Jahr","Woche","Wochentag","Stunde","Minute","Sekunde","gestern","heute","morgen"},
  5851.                                                 {"jour","mois","an","semaine","jour de semaine","heure","minute","seconde","hier","aujourd'hui","demain"},
  5852.                                                 {
  5853.                                                  #ifdef _ISO8859_Latin1
  5854.                                                    "dìa"
  5855.                                                  #else
  5856.                                                    "dia"
  5857.                                                  #endif
  5858.                                                  ,"mes",
  5859.                                                  #ifdef _ISO8859_Latin1
  5860.                                                    "año"
  5861.                                                  #else
  5862.                                                    "ano"
  5863.                                                  #endif
  5864.                                                  ,"semana",
  5865.                                                  #ifdef _ISO8859_Latin1
  5866.                                                    "dìa de semana"
  5867.                                                  #else
  5868.                                                    "dia de semana"
  5869.                                                  #endif
  5870.                                                  ,"hora","minuto","segundo","ayer","hoy",
  5871.                                                  #ifdef _ISO8859_Latin1
  5872.                                                    "mañana"
  5873.                                                  #else
  5874.                                                    "manana"
  5875.                                                  #endif
  5876.                                                 },
  5877.                                                 {"dia",
  5878.                                                  #ifdef _ISO8859_Latin1
  5879.                                                    "m?s"
  5880.                                                  #else
  5881.                                                    "mes"
  5882.                                                  #endif
  5883.                                                  ,"ano","semana","dia da semana","hora","minuto","segundo","ontem","hoje",
  5884.                                                  #ifdef _ISO8859_Latin1
  5885.                                                    "amann?"
  5886.                                                  #else
  5887.                                                    "amanna"
  5888.                                                  #endif
  5889.                                                 },
  5890.                                                 {"dag",
  5891.                                                  #ifdef _ISO8859_Latin1
  5892.                                                    "m?ned","?r"
  5893.                                                  #else
  5894.                                                    "maned","ar"
  5895.                                                  #endif
  5896.                                                  ,"uge","hverdag","time","minut","sekund",
  5897.                                                  #ifdef _ISO8859_Latin1
  5898.                                                    "i g?r"
  5899.                                                  #else
  5900.                                                    "i gar"
  5901.                                                  #endif
  5902.                                                  ,"i dag","i morgen"},
  5903.                                                 {"giomo","mese","anno","settimana","giomo lavorativo","ora","minuto","secondo","ieri","oggi","domani"},
  5904.                                                 {"dag","maand","jaar","week","weekdag","ure","minuut","seconde","gisteren","vandaag","morgen"},
  5905.                                                 {"dag",
  5906.                                                  #ifdef _ISO8859_Latin1
  5907.                                                    "m?ned","?r"
  5908.                                                  #else
  5909.                                                    "maned","ar"
  5910.                                                  #endif
  5911.                                                  ,"uke","ukedag","time","minutt","sekund",
  5912.                                                  #ifdef _ISO8859_Latin1
  5913.                                                    "i g?r"
  5914.                                                  #else
  5915.                                                    "i gar"
  5916.                                                  #endif
  5917.                                                  ,"i dag","i morgen"},
  5918.                                                 {"dag",
  5919.                                                  #ifdef _ISO8859_Latin1
  5920.                                                    "m?nad","?r"
  5921.                                                  #else
  5922.                                                    "manad","ar"
  5923.                                                  #endif
  5924.                                                  ,"vecka","vardag","timme","minut","sekund",
  5925.                                                  #ifdef _ISO8859_Latin1
  5926.                                                    "i g?r"
  5927.                                                  #else
  5928.                                                    "i gar"
  5929.                                                  #endif
  5930.                                                  ,"i dag","i morgen"},
  5931.                                                 {"dzien",
  5932.                                                  #ifdef _ISO8859_Latin1
  5933.                                                    "miesi?c"
  5934.                                                  #else
  5935.                                                    "miesiac"
  5936.                                                  #endif
  5937.                                                  ,"lat","tydzien","dzien poweszdni","godzin","minuta","sekunda","wczorja","dzisiaj","jutro"},
  5938.                                                 {
  5939.                                                  #ifdef _ISO8859_Latin1
  5940.                                                    "päivä"
  5941.                                                  #else
  5942.                                                    "paiva"
  5943.                                                  #endif
  5944.                                                  ,"kuukausi","vuosi","viikko",
  5945.                                                  #ifdef _ISO8859_Latin1
  5946.                                                    "arkipäivä"
  5947.                                                  #else
  5948.                                                    "arkipaiva"
  5949.                                                  #endif
  5950.                                                  ,"tunti","minuutti","sekunti","eilinen",
  5951.                                                  #ifdef _ISO8859_Latin1
  5952.                                                    "tänään"
  5953.                                                  #else
  5954.                                                    "tanaan"
  5955.                                                  #endif
  5956.                                                  ,"huomenna"}
  5957.                                                };
  5958.  
  5959.   if (text != NULL)
  5960.    {
  5961.     text[0] = '\0';
  5962.     switch (lang)
  5963.      {
  5964.       case Locale  :
  5965.       #ifdef _AMIGA
  5966.                      if (locale != NULL)
  5967.                       {
  5968.                        char localestr[33];
  5969.  
  5970.                        strcpy(localestr,locale->loc_LanguageName);
  5971.                        localestr[strchr(localestr,'.')-localestr] = '\x0';
  5972.                        if (strcmp(localestr,"deutsch") == 0)
  5973.                          lang = Deutsch;
  5974.                        else if (strcmp(localestr,"français") == 0)
  5975.                          lang = français;
  5976.                        else if (strcmp(localestr,"español") == 0)
  5977.                          lang = español;
  5978.                        else if (strcmp(localestr,"português") == 0)
  5979.                          lang = português;
  5980.                        else if (strcmp(localestr,"dansk") == 0)
  5981.                          lang = dansk;
  5982.                        else if (strcmp(localestr,"italiano") == 0)
  5983.                          lang = italiano;
  5984.                        else if (strcmp(localestr,"nederlands") == 0)
  5985.                          lang = nederlands;
  5986.                        else if (strcmp(localestr,"norsk") == 0)
  5987.                          lang = norsk;
  5988.                        else if (strcmp(localestr,"svenska") == 0)
  5989.                          lang = svenska;
  5990.                        else /* if (strcmp(localestr,"english") == 0) */
  5991.                          lang = English;
  5992.                       }
  5993.                      else
  5994.       #endif
  5995.                        lang = English;
  5996.       default      : if (!plural)
  5997.                        strcpy(text,DATETEXTS[(unsigned short)lang][dt]);
  5998.      }
  5999.    }
  6000.  }
  6001.  
  6002.  /* ----------------------------------------------------------------------- */
  6003.  
  6004.  #ifndef __MakeLib
  6005.    #ifndef __cplusplus
  6006.      void JDToJulian(const unsigned long jd, unsigned short *const day, unsigned short *const month, int *const year)
  6007.    #else
  6008.      void JDToJulian(const unsigned long jd, unsigned short &day, unsigned short &month, int &year)
  6009.    #endif
  6010.  #else
  6011.    void __saveds __asm JDToJulian(register __d0 const unsigned long jd, register __a0 unsigned short *const day, register __a1 unsigned short *const month, register __a2 int *const year)
  6012.  #endif
  6013.  
  6014. /*
  6015. ******* Date/JDToJulian *****************************************************
  6016. *
  6017. *   NAME
  6018. *    JDToJulian -- Returns the Julian date for a JD. (V33.095)
  6019. *
  6020. *   SYNOPSIS
  6021. *    JDToJulian(jd,day,month,year);
  6022. *           d0 a0   a1    a2
  6023. *
  6024. *    void JDToJulian(const unsigned long jd, unsigned short *const day,
  6025. *        unsigned short *const month, int *const year);
  6026. *
  6027. *    void JDToJulian(const unsigned long jd, unsigned short &day,
  6028. *        unsigned short &month, int &year);
  6029. *
  6030. *   FUNCTION
  6031. *    Returns the Julian date for a JD.
  6032. *
  6033. *   INPUTS
  6034. *    jd    - This is the given JD.
  6035. *
  6036. *   RESULT
  6037. *    day    - Day of the date.
  6038. *    month    - Month of the date.
  6039. *    year    - Year of the date.
  6040. *
  6041. *   EXAMPLE
  6042. *    ...
  6043. *    JDToJulian(2299160,&day,&month,&year);
  6044. *    ...
  6045. *
  6046. *   NOTES
  6047. *    It is better to use this function only from 1718867 to 2299160!
  6048. *
  6049. *   BUGS
  6050. *    unknown.
  6051. *
  6052. *   SEE ALSO
  6053. *    JDToGregorian(),JDToHeis()
  6054. *
  6055. *****************************************************************************
  6056. *
  6057. *
  6058. */
  6059.  
  6060.  {
  6061.   unsigned long a;
  6062.   unsigned int  b,c;
  6063.   unsigned short d;
  6064.  
  6065.   a = jd+1524;
  6066.   b = (unsigned int)((a-122.1)/365.25);
  6067.   c = (unsigned int)(a-(unsigned long)(365.25*b));
  6068.   d = (unsigned short)(c/30.6001);
  6069.   #ifndef __cplusplus
  6070.     *day = (unsigned short)(c-(unsigned int)(30.6001*d));
  6071.     *month = (unsigned short)(d<14 ? d-1 : d-13);
  6072.     *year = (int)((*month)>2 ? b-4716 : b-4715);
  6073.     if ((*year) < 1)
  6074.       (*year)--;
  6075.   #else
  6076.     day = (unsigned short)(c-(unsigned int)(30.6001*d));
  6077.     month = (unsigned short)(d<14 ? d-1 : d-13);
  6078.     year = (int)(month>2 ? b-4716 : b-4715);
  6079.     if (year < 1)
  6080.       year--;
  6081.   #endif
  6082.  }
  6083.  
  6084.  
  6085.  #ifndef __MakeLib
  6086.    #ifndef __cplusplus
  6087.      void JDToGregorian(const unsigned long jd, unsigned short *const day, unsigned short *const month, int *const year)
  6088.    #else
  6089.      void JDToGregorian(const unsigned long jd, unsigned short &day, unsigned short &month, int &year)
  6090.    #endif
  6091.  #else
  6092.    void __saveds __asm JDToGregorian(register __d0 const unsigned long jd, register __a0 unsigned short *const day, register __a1 unsigned short *month, register __a2 int *const year)
  6093.  #endif
  6094.  
  6095. /*
  6096. ******* Date/JDToGregorian **************************************************
  6097. *
  6098. *   NAME
  6099. *    JDToGregorian -- Returns the Gregorian date for a JD. (V33.095)
  6100. *
  6101. *   SYNOPSIS
  6102. *    JDToGregorian(jd,day,month,year);
  6103. *              d0 a0   a1    a2
  6104. *
  6105. *    void JDToGregorian(const unsigned long jd, unsigned short *const day,
  6106. *        unsigned short *const month, int *const year);
  6107. *
  6108. *    void JDToGregorian(const unsigned long jd, unsigned short &day,
  6109. *        unsigned short &month, int &year);
  6110. *
  6111. *   FUNCTION
  6112. *    Returns the Gregorian date for a JD.
  6113. *
  6114. *   INPUTS
  6115. *    jd    - This is the given JD.
  6116. *
  6117. *   RESULT
  6118. *    day    - Day of the date.
  6119. *    month    - Month of the date.
  6120. *    year    - Year of the date.
  6121. *
  6122. *   EXAMPLE
  6123. *    ...
  6124. *    JDToGregorian(2299161,&day,&month,&year);
  6125. *    ...
  6126. *
  6127. *   NOTES
  6128. *    It is better to use this function only from 1718867 to 2889835!
  6129. *
  6130. *   BUGS
  6131. *    unknown.
  6132. *
  6133. *   SEE ALSO
  6134. *    JDToJulian(),JDToHeis()
  6135. *
  6136. *****************************************************************************
  6137. *
  6138. *
  6139. */
  6140.  
  6141.  {
  6142.   unsigned long a;
  6143.   unsigned int  b,c;
  6144.   unsigned short d,e;
  6145.  
  6146.   if (jd < 2299161L)
  6147.    {
  6148.     JDToJulian(jd,day,month,year);
  6149.    }
  6150.   else
  6151.    {
  6152.     e = (unsigned short)((jd-1867216.25)/36524.25);
  6153.     a = jd+1524+1+ e - e/4;
  6154.     b = (unsigned int)((a-122.1)/365.25);
  6155.     c = (unsigned int)(a-(unsigned long)(365.25*b));
  6156.     d = (unsigned short)(c/30.6001);
  6157.     #ifndef __cplusplus
  6158.       *day = (unsigned short)(c-(unsigned int)(30.6001*d));
  6159.       *month = (unsigned short)(d<14 ? d-1 : d-13);
  6160.       *year = (int)((*month)>2 ? b-4716 : b-4715);
  6161.       if ((*year) < 1)
  6162.         (*year)--;
  6163.     #else
  6164.       day = (unsigned short)(c-(unsigned int)(30.6001*d));
  6165.       month = (unsigned short)(d<14 ? d-1 : d-13);
  6166.       year = (int)(month>2 ? b-4716 : b-4715);
  6167.       if (year < 1)
  6168.         year--;
  6169.     #endif
  6170.    }
  6171.  }
  6172.  
  6173.  
  6174.  #ifndef __MakeLib
  6175.    #ifndef __cplusplus
  6176.      void JDToHeis(const unsigned long jd, unsigned short *const day, unsigned short *const month, int *const year)
  6177.    #else
  6178.      void JDToHeis(const unsigned long jd, unsigned short &day, unsigned short &month, int &year)
  6179.    #endif
  6180.  #else
  6181.    void __saveds __asm JDToHeis(register __d0 const unsigned long jd, register __a0 unsigned short *const day, register __a1 unsigned short *const month, register __a2 int *const year)
  6182.  #endif
  6183.  
  6184. /*
  6185. ******* Date/JDToHeis *******************************************************
  6186. *
  6187. *   NAME
  6188. *    JDToHeis -- Returns the Heis date for a JD. (V33.095)
  6189. *
  6190. *   SYNOPSIS
  6191. *    JDToHeis(jd,day,month,year);
  6192. *         d0 a0   a1    a2
  6193. *
  6194. *    void JDToHeis(const unsigned long jd, unsigned short *const day,
  6195. *        unsigned short *const month, int *const year);
  6196. *
  6197. *    void JDToHeis(const unsigned long jd, unsigned short &day,
  6198. *        unsigned short &month, int &year);
  6199. *
  6200. *   FUNCTION
  6201. *    Returns the Heis date for a JD.
  6202. *
  6203. *   INPUTS
  6204. *    jd    - This is the given JD.
  6205. *
  6206. *   RESULT
  6207. *    day    - Day of the date.
  6208. *    month    - Month of the date.
  6209. *    year    - Year of the date.
  6210. *
  6211. *   EXAMPLE
  6212. *    ...
  6213. *    JDToHeis(2299161,&day,&month,&year);
  6214. *    ...
  6215. *
  6216. *   NOTES
  6217. *    At the moment this is only a dummy to JDToGregorian, so:
  6218. *    It is better to use this function only from 1718867 to 2889835!
  6219. *
  6220. *   BUGS
  6221. *    unknown.
  6222. *
  6223. *   SEE ALSO
  6224. *    JDToJulian(), JDToGregorian()
  6225. *
  6226. *****************************************************************************
  6227. *
  6228. *
  6229. */
  6230.  
  6231.  {
  6232.   JDToGregorian(jd,day,month,year);
  6233.  }
  6234.  
  6235.  /* ----------------------------------------------------------------------- */
  6236.  
  6237.  static unsigned long GregorianMoonPhaseHelp(const unsigned short day, const unsigned short month, const int year, const MoonPhases phase)
  6238.  
  6239. /*
  6240. *****i* Date/GregorianMoonPhaseHelp *****************************************
  6241. *
  6242. *   NAME
  6243. *    GregorianMoonPhaseHelp -- Searches for the next moon phase (V33.099)
  6244. *
  6245. *   SYNOPSIS
  6246. *    jd = GregorianMoonPhaseHelp(day,month,year,phase);
  6247. *    d0                     d0   d1    d2   d3
  6248. *
  6249. *    unsigned long GregorianMoonPhaseHelp(const unsigned short day,
  6250. *        const unsigned short month, const int year,
  6251. *        const MoonPhases phase);
  6252. *
  6253. *   FUNCTION
  6254. *    Returns the next moon phase you are searching for after
  6255. *    an specified date.
  6256. *
  6257. *   INPUTS
  6258. *    day   - Start day for the search.
  6259. *    month - Start month for the search.
  6260. *    year  - Start year for the search.
  6261. *    phase - The moon phase you want to know.
  6262. *
  6263. *   RESULT
  6264. *    jd - The day (as JD) on wich the moon phase was found.
  6265. *
  6266. *   EXAMPLE
  6267. *    ...
  6268. *    jd = GregorianMoonPhaseHelp(18,9,1994,FullMoon);
  6269. *    JDToGregorian(jd,&day,&month,&year);
  6270. *    ...
  6271. *
  6272. *   NOTES
  6273. *    The range of this function is unknown for me!
  6274. *    So use it only from 1583 to 2500.
  6275. *    This is only an experimental version!
  6276. *
  6277. *   BUGS
  6278. *    unknown.
  6279. *
  6280. *   SEE ALSO
  6281. *    GregorianMoonPhase()
  6282. *
  6283. *****************************************************************************
  6284. *
  6285. *
  6286. */
  6287.  
  6288.  {
  6289.   double y,k,t,t2,jd;
  6290.  
  6291.   y = year+(GregorianDayDiff(1,1,year,day,month,year)/(double)GregorianYearDays(year));
  6292.   k = floor((y-2000)*12.3685);
  6293.   switch (phase)
  6294.    {
  6295.     case NewMoon      : /* k += 0; */
  6296.                         break;
  6297.     case FirstQuarter : k += 0.25;
  6298.                         break;
  6299.     case FullMoon     : k += 0.5;
  6300.                         break;
  6301.     case LastQuarter  : k += 0.75;
  6302.                         /* break; */
  6303.    }
  6304.   t = k/1236.85;
  6305.   t2 = t*t;
  6306.   jd = 2451550.09765+29.530588853*k+0.0001337*t2-0.00000015*t2*t+0.00000000073*t2*t2;
  6307.   return((unsigned long)jd);
  6308.  }
  6309.  
  6310.  
  6311.  #ifndef __MakeLib
  6312.    unsigned long GregorianMoonPhase(const unsigned short day, const unsigned short month, const int year, const MoonPhases phase)
  6313.  #else
  6314.    unsigned long __saveds __asm GregorianMoonPhase(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year, register __d3 const MoonPhases phase)
  6315.  #endif
  6316.  
  6317. /*
  6318. ******* Date/GregorianMoonPhase *********************************************
  6319. *
  6320. *   NAME
  6321. *    GregorianMoonPhase -- Searches for the next moon phase (V33.098)
  6322. *
  6323. *   SYNOPSIS
  6324. *    jd = GregorianMoonPhase(day,month,year,phase);
  6325. *    d0                d0   d1    d2   d3
  6326. *
  6327. *    unsigned long GregorianMoonPhase(const unsigned short day,
  6328. *        const unsigned short month, const int year,
  6329. *        const MoonPhases phase);
  6330. *
  6331. *   FUNCTION
  6332. *    Returns the next moon phase you are searching for after
  6333. *    a specified date.
  6334. *
  6335. *   INPUTS
  6336. *    day   - Start day for the search.
  6337. *    month - Start month for the search.
  6338. *    year  - Start year for the search.
  6339. *    phase - The moon phase you want to know.
  6340. *
  6341. *   RESULT
  6342. *    jd - The day (as JD) on wich the moon phase was found.
  6343. *
  6344. *   EXAMPLE
  6345. *    ...
  6346. *    jd = GregorianMoonPhase(18,9,1994,FullMoon);
  6347. *    JDToGregorian(jd,&day,&month,&year);
  6348. *    ...
  6349. *
  6350. *   NOTES
  6351. *    The range of this function is unknown to me!
  6352. *    So use it only from 1583 to 2500.
  6353. *    This is only an experimental version!
  6354. *
  6355. *   BUGS
  6356. *    unknown.
  6357. *
  6358. *   SEE ALSO
  6359. *    MoonMonthAge()
  6360. *
  6361. *****************************************************************************
  6362. *
  6363. *
  6364. */
  6365.  
  6366.  {
  6367.   unsigned long jd;
  6368.  
  6369.   jd = GregorianMoonPhaseHelp(day,month,year,phase);
  6370.   if (jd >= GregorianToJD(day,month,year))
  6371.    {
  6372.     return(jd);
  6373.    }
  6374.   else
  6375.    {
  6376.     unsigned short d,m;
  6377.     int y;
  6378.  
  6379.     #ifndef __cplusplus
  6380.       GregorianDiffDate(day,month,year,25,&d,&m,&y);
  6381.     #else
  6382.       GregorianDiffDate(day,month,year,25,d,m,y);
  6383.     #endif
  6384.     jd = GregorianMoonPhaseHelp(d,m,y,phase);
  6385.     return(jd);
  6386.    }
  6387.  }
  6388.  
  6389.  /* ----------------------------------------------------------------------- */
  6390.  
  6391.  #ifndef __MakeLib
  6392.    bool ValidJulianDate(const unsigned short day, const unsigned short month, const int year)
  6393.  #else
  6394.    bool __saveds __asm ValidJulianDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  6395.  #endif
  6396.  
  6397. /*
  6398. ******* Date/ValidJulianDate ************************************************
  6399. *
  6400. *   NAME
  6401. *    ValidJulianDate -- Checks if the date is a valid date (V33.135)
  6402. *
  6403. *   SYNOPSIS
  6404. *    valid = ValidJulianDate(day,month,year);
  6405. *      d0                 d0   d1  d2
  6406. *
  6407. *    bool ValidJulianDate(const unsigned short day,
  6408. *        const unsigned short month, const int year);
  6409. *
  6410. *   FUNCTION
  6411. *    ValidJulianDate checks if the date is valid.
  6412. *
  6413. *   INPUTS
  6414. *    day   - Day of the date.
  6415. *    month - Month of the date.
  6416. *    year  - Year of the date.
  6417. *
  6418. *   RESULT
  6419. *    valid - true  : The date is ok.
  6420. *        false : This is not a correct date!
  6421. *
  6422. *   EXAMPLE
  6423. *    ...
  6424. *    if (ValidJulianDate(29,2,2000))
  6425. *      printf("ok\n");
  6426. *    else
  6427. *      printf("wrong date!!!\n");
  6428. *    ...
  6429. *
  6430. *   NOTES
  6431. *    None.
  6432. *
  6433. *   BUGS
  6434. *    None.
  6435. *
  6436. *   SEE ALSO
  6437. *    ValidTime(),ValidGregorianDate(),ValidHeisDate()
  6438. *
  6439. *****************************************************************************
  6440. *
  6441. *
  6442. */
  6443.  
  6444.  {
  6445.   if ((year >= 8) && (month >= 1) && (month <= 12) && (day >= 1) && (day <= JulianMonthDays(month,year)))
  6446.     return(true);
  6447.   else
  6448.     return(false);
  6449.  }
  6450.  
  6451.  
  6452.  #ifndef __MakeLib
  6453.    bool ValidGregorianDate(const unsigned short day, const unsigned short month, const int year)
  6454.  #else
  6455.    bool __saveds __asm ValidGregorianDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  6456.  #endif
  6457.  
  6458. /*
  6459. ******* Date/ValidGregorianDate *********************************************
  6460. *
  6461. *   NAME
  6462. *    ValidGregorianDate -- Checks if the date is a valid date (V33.135)
  6463. *
  6464. *   SYNOPSIS
  6465. *    valid = ValidGregorianDate(day,month,year);
  6466. *      d0                 d0   d1  d2
  6467. *
  6468. *    bool ValidGregorianDate(const unsigned short day,
  6469. *        const unsigned short month, const int year);
  6470. *
  6471. *   FUNCTION
  6472. *    ValidGregorianDate checks if the date is valid.
  6473. *
  6474. *   INPUTS
  6475. *    day   - Day of the date.
  6476. *    month - Month of the date.
  6477. *    year  - Year of the date.
  6478. *
  6479. *   RESULT
  6480. *    valid - true  : The date is ok.
  6481. *        false : This is not a correct date!
  6482. *
  6483. *   EXAMPLE
  6484. *    ...
  6485. *    if (ValidGregorianDate(29,2,2000))
  6486. *      printf("ok\n");
  6487. *    else
  6488. *      printf("wrong date!!!\n");
  6489. *    ...
  6490. *
  6491. *   NOTES
  6492. *    None.
  6493. *
  6494. *   BUGS
  6495. *    None.
  6496. *
  6497. *   SEE ALSO
  6498. *    ValidTime(),ValidJulianDate(),ValidHeisDate()
  6499. *
  6500. *****************************************************************************
  6501. *
  6502. *
  6503. */
  6504.  
  6505.  {
  6506.   if ((year == BeforeGregorianYear) && (month == BeforeGregorianMonth))
  6507.     if (((day >= 1) && (day <= BeforeGregorianDay)) || ((day >= AfterGregorianDay) && (day <= 31)))
  6508.       return(true);
  6509.     else
  6510.       return(false);
  6511.   else if ((year >= 8) && (month >= 1) && (month <= 12) && (day >= 1) && (day <= GregorianMonthDays(month,year)))
  6512.     return(true);
  6513.   else
  6514.     return(false);
  6515.  }
  6516.  
  6517.  
  6518.  #ifndef __MakeLib
  6519.    bool ValidHeisDate(const unsigned short day, const unsigned short month, const int year)
  6520.  #else
  6521.    bool __saveds __asm ValidHeisDate(register __d0 const unsigned short day, register __d1 const unsigned short month, register __d2 const int year)
  6522.  #endif
  6523.  
  6524. /*
  6525. ******* Date/ValidHeisDate **************************************************
  6526. *
  6527. *   NAME
  6528. *    ValidHeisDate -- Checks if the date is a valid date (V33.135)
  6529. *
  6530. *   SYNOPSIS
  6531. *    valid = ValidHeisDate(day,month,year);
  6532. *      d0                 d0   d1  d2
  6533. *
  6534. *    bool ValidHeisDate(const unsigned short day,
  6535. *        const unsigned short month, const int year);
  6536. *
  6537. *   FUNCTION
  6538. *    ValidHeisDate checks if the date is valid.
  6539. *
  6540. *   INPUTS
  6541. *    day   - Day of the date.
  6542. *    month - Month of the date.
  6543. *    year  - Year of the date.
  6544. *
  6545. *   RESULT
  6546. *    valid - true  : The date is ok.
  6547. *        false : This is not a correct date!
  6548. *
  6549. *   EXAMPLE
  6550. *    ...
  6551. *    if (ValidHeisDate(29,2,2000))
  6552. *      printf("ok\n");
  6553. *    else
  6554. *      printf("wrong date!!!\n");
  6555. *    ...
  6556. *
  6557. *   NOTES
  6558. *    None.
  6559. *
  6560. *   BUGS
  6561. *    None.
  6562. *
  6563. *   SEE ALSO
  6564. *    ValidTime(),ValidJulianDate(),ValidGregorianDate()
  6565. *
  6566. *****************************************************************************
  6567. *
  6568. *
  6569. */
  6570.  
  6571.  {
  6572.   if (year <= BeforeGregorianYear)
  6573.     return(ValidGregorianDate(day,month,year));
  6574.   if ((month >= 1) && (month <= 12) && (day >= 1) && (day <= HeisMonthDays(month,year)))
  6575.     return(true);
  6576.   else
  6577.     return(false);
  6578.  }
  6579.  
  6580.  /* ----------------------------------------------------------------------- */
  6581.  
  6582.  #ifndef __MakeLib
  6583.    void SetCountry(const Countries country)
  6584.  #else
  6585.    void __saveds __asm SetCountry(register __d0 const Countries country)
  6586.  #endif
  6587.  
  6588. /*
  6589. ******* Date/SetCountry *****************************************************
  6590. *
  6591. *   NAME
  6592. *    SetCountry -- Sets the country defaults for the date lib. (V33.140)
  6593. *
  6594. *   SYNOPSIS
  6595. *    SetCountry(country);
  6596. *             d0
  6597. *
  6598. *    void SetCountry(const Countries country);
  6599. *
  6600. *   FUNCTION
  6601. *    SetCountry sets the defaults for your country.
  6602. *    Like: correct start of gregorian calendar.
  6603. *
  6604. *   INPUTS
  6605. *    country - Country to set.
  6606. *
  6607. *   RESULT
  6608. *    None.
  6609. *
  6610. *   EXAMPLE
  6611. *    ...
  6612. *    SetCountry(unknown);
  6613. *    ...
  6614. *
  6615. *   NOTES
  6616. *    Will *not* work correct if something other than 'unknown' is set
  6617. *    in the moment!
  6618. *
  6619. *   BUGS
  6620. *    None.
  6621. *
  6622. *   SEE ALSO
  6623. *
  6624. *
  6625. *****************************************************************************
  6626. *
  6627. *
  6628. */
  6629.  
  6630.  {
  6631.   Country = country;
  6632.   switch (country)
  6633.    {
  6634.     case Deutschland  :
  6635.     case Schweiz      :
  6636.     case Danmark      :
  6637.     case Nederland    : BeforeGregorianDay = 17;
  6638.                         BeforeGregorianMonth = 2;
  6639.                         BeforeGregorianYear = 1700;
  6640.                         AfterGregorianDay = 2;
  6641.                         AfterGregorianMonth = 3;
  6642.                         AfterGregorianYear = 1700;
  6643.                         break;
  6644.     case GreatBritain : BeforeGregorianDay = 1;
  6645.                         BeforeGregorianMonth = 9;
  6646.                         BeforeGregorianYear = 1752;
  6647.                         AfterGregorianDay = 15;
  6648.                         AfterGregorianMonth = 9;
  6649.                         AfterGregorianYear = 1752;
  6650.                         break;
  6651.     /* case Schweden  : BeforeGregorianDay = 16;
  6652.                         BeforeGregorianMonth = 2;
  6653.                         BeforeGregorianYear = 1753;
  6654.                         AfterGregorianDay = 2;
  6655.                         AfterGregorianMonth = 3;
  6656.                         AfterGregorianYear = 1753;
  6657.                         break; */
  6658.     case unknown      :
  6659.     case Italia       :
  6660.     default           : BeforeGregorianDay = 4;
  6661.                         BeforeGregorianMonth = 10;
  6662.                         BeforeGregorianYear = 1582;
  6663.                         AfterGregorianDay = 15;
  6664.                         AfterGregorianMonth = 10;
  6665.                         AfterGregorianYear = 1582;
  6666.    }
  6667.  }
  6668.  
  6669.  /* ----------------------------------------------------------------------- */
  6670.  
  6671.  #include "Date_Time.c"
  6672.  
  6673.  /* ----------------------------------------------------------------------- */
  6674.  /* ----------------------------------------------------------------------- */
  6675.  
  6676.  #ifdef _AMIGA
  6677.    static unsigned short maximum(const unsigned short a, const unsigned short b)
  6678.  
  6679. /*
  6680. *****i* Date/maximum ********************************************************
  6681. *
  6682. *   NAME
  6683. *    maximum -- Procedure to find the maximum of a and b (V33)
  6684. *
  6685. *   SYNOPSIS
  6686. *    max = maximum(a,b);
  6687. *
  6688. *    unsigned short maximum(const unsigned short a,
  6689. *        const unsigned short b);
  6690. *
  6691. *   FUNCTION
  6692. *    Calculating the maximum of a and b.
  6693. *
  6694. *   INPUTS
  6695. *    a - First number.
  6696. *    b - Second number.
  6697. *
  6698. *   RESULT
  6699. *    max - The maximum of a and b.
  6700. *
  6701. *   EXAMPLE
  6702. *    ...
  6703. *    max = maximum(10,15); \* Should be 15 *\
  6704. *    ...
  6705. *
  6706. *   NOTES
  6707. *    None.
  6708. *
  6709. *   BUGS
  6710. *    none.
  6711. *
  6712. *   SEE ALSO
  6713. *
  6714. *
  6715. *****************************************************************************
  6716. *
  6717. *
  6718. */
  6719.  
  6720.    {
  6721.     if (a > b)
  6722.       return(a);
  6723.     else
  6724.      return(b);
  6725.    }
  6726.  #endif
  6727.  
  6728.  /* ----------------------------------------------------------------------- */
  6729.  
  6730.  #ifndef __SASC_650
  6731.    void _DateInit(void)
  6732.  #else
  6733.    #ifndef __MakeLib
  6734.      void _STI_600__DateInit(void)
  6735.    #else
  6736.      int __saveds __UserLibInit(struct Library *libbase)
  6737.    #endif
  6738.  #endif
  6739.  
  6740. /*
  6741. ******* Date/_DateInit ******************************************************
  6742. *
  6743. *   NAME
  6744. *    _DateInit -- Procedure to initialize this module! (V33)
  6745. *
  6746. *   SYNOPSIS
  6747. *    _DateInit();
  6748. *
  6749. *    void _DateInit(void);
  6750. *
  6751. *   FUNCTION
  6752. *    Initialize this module, like the modulebody in Modula-II or Oberon-2
  6753. *
  6754. *   INPUTS
  6755. *    None.
  6756. *
  6757. *   RESULT
  6758. *    None.
  6759. *
  6760. *   EXAMPLE
  6761. *    ...
  6762. *    _DateInit();
  6763. *    ...
  6764. *
  6765. *   NOTES
  6766. *    This function is only needed/available if you do not compile this
  6767. *    with a SAS C Compiler (using Autoinitialization!)
  6768. *    If you are not using SASC - don't forget to init this module with
  6769. *    this function - or you will get into trouble!!!
  6770. *
  6771. *   BUGS
  6772. *    unknown.
  6773. *
  6774. *   SEE ALSO
  6775. *    _DateCleanup()
  6776. *
  6777. *****************************************************************************
  6778. *
  6779. *
  6780. */
  6781.  
  6782.  {/* Dates of Gregorian reform in
  6783.      Rom:
  6784.        5.10.1582-14.10.1582
  6785.      Deutschland, Niederlande, Schweiz, Dänemark:
  6786.        18.02.1700-01.03.1700
  6787.      Großbritannien
  6788.        02.09.1752-14.09.1752
  6789.      Schweden
  6790.        17.02.1753-01.03.1753
  6791.      Rußland
  6792.        ? (oktober Revolution)
  6793.      Griechenland
  6794.        ??.??.1923-??.??.1923 */
  6795.   /* Bremen/Arbergen = 8° 55' 23" East, 53° 4' 8" North */
  6796.   #ifdef _AMIGA
  6797.     #ifndef __SASC_650
  6798.       LocaleBase = OpenLibrary("locale.library",0);
  6799.     #endif
  6800.     if (LocaleBase != NULL)
  6801.      {
  6802.       locale = OpenLocale(NULL);
  6803.       if (locale != NULL)
  6804.        {
  6805.         unsigned short i;
  6806.  
  6807.         wlen = (unsigned short)strlen(GetLocaleStr(locale,DAY_1));
  6808.         abwlen = (unsigned short)strlen(GetLocaleStr(locale,ABDAY_1));
  6809.         for (i=1;i<7;i++)
  6810.          {
  6811.           wlen = maximum(wlen,strlen(GetLocaleStr(locale,DAYS[i])));
  6812.           abwlen = maximum(abwlen,strlen(GetLocaleStr(locale,ABDAYS[i])));
  6813.          }
  6814.         mlen = (unsigned short)strlen(GetLocaleStr(locale,MON_1));
  6815.         abmlen = (unsigned short)strlen(GetLocaleStr(locale,ABMON_1));
  6816.         for (i=1;i<12;i++)
  6817.          {
  6818.           mlen = maximum(mlen,strlen(GetLocaleStr(locale,MONS[i])));
  6819.           abmlen = maximum(abmlen,strlen(GetLocaleStr(locale,ABMONS[i])));
  6820.          }
  6821.        }
  6822.      }
  6823.   #endif
  6824.   #ifdef __MakeLib
  6825.     return(0);
  6826.   #endif
  6827.  }
  6828.  
  6829.  
  6830.  #ifndef _SASC_650
  6831.    void _DateCleanup(void)
  6832.  #else
  6833.    #ifndef __MakeLib
  6834.      void _STD_600__DateCleanup(void)
  6835.    #else
  6836.      void __saveds __UserLibCleanup(struct Library *libbase)
  6837.    #endif
  6838.  #endif
  6839.  
  6840. /*
  6841. ******* Date/_DateCleanup ***************************************************
  6842. *
  6843. *   NAME
  6844. *    _DateCleanup -- Procedure to cleanup this module! (V33)
  6845. *
  6846. *   SYNOPSIS
  6847. *    _DateCleanup();
  6848. *
  6849. *    void _DateCleanup(void);
  6850. *
  6851. *   FUNCTION
  6852. *    Cleanup this module, after using!
  6853. *
  6854. *   INPUTS
  6855. *    None.
  6856. *
  6857. *   RESULT
  6858. *    None.
  6859. *
  6860. *   EXAMPLE
  6861. *    ...
  6862. *    _DateCleanup();
  6863. *    ...
  6864. *
  6865. *   NOTES
  6866. *    This function is only needed/available if you do not compile this
  6867. *    with a SAS C Compiler (using Autoinitialization!)
  6868. *    If you are not using SASC - don't forget to cleanup this module with
  6869. *    this function - or you will get into trouble!!!
  6870. *
  6871. *   BUGS
  6872. *    unknown.
  6873. *
  6874. *   SEE ALSO
  6875. *    _DateInit()
  6876. *
  6877. *****************************************************************************
  6878. *
  6879. *
  6880. */
  6881.  
  6882.  {
  6883.   #ifdef _AMIGA
  6884.   if (locale != NULL)
  6885.     CloseLocale(locale);
  6886.     #ifndef __SASC_650
  6887.       if (LocaleBase != NULL)
  6888.         CloseLibrary(LocaleBase);
  6889.     #endif
  6890.   #endif
  6891.  }
  6892.