sdncal.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef SDNCAL_H
  2. #define SDNCAL_H
  3. /*
  4. * This code has been modified for use with PHP
  5. * by Shane Caraveo shane@caraveo.com
  6. * see below for more details
  7. *
  8. */
  9. /* $selId: sdncal.h,v 2.0 1995/10/24 01:13:06 lees Exp $
  10. * Copyright 1993-1995, Scott E. Lee, all rights reserved.
  11. * Permission granted to use, copy, modify, distribute and sell so long as
  12. * the above copyright and this permission statement are retained in all
  13. * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
  14. */
  15. /**************************************************************************
  16. *
  17. * This package defines a set of routines that convert calendar dates to
  18. * and from a serial day number (SDN). The SDN is a serial numbering of
  19. * days where SDN 1 is November 25, 4714 BC in the Gregorian calendar and
  20. * SDN 2447893 is January 1, 1990. This system of day numbering is
  21. * sometimes referred to as Julian days, but to avoid confusion with the
  22. * Julian calendar, it is referred to as serial day numbers here. The term
  23. * Julian days is also used to mean the number of days since the beginning
  24. * of the current year.
  25. *
  26. * The SDN can be used as an intermediate step in converting from one
  27. * calendar system to another (such as Gregorian to Jewish). It can also
  28. * be used for date computations such as easily comparing two dates,
  29. * determining the day of the week, finding the date of yesterday or
  30. * calculating the number of days between two dates.
  31. *
  32. * When using this software on 16 bit systems, be careful to store SDNs in
  33. * a long int, because it will not fit in the 16 bits that some systems
  34. * allocate to an int.
  35. *
  36. * For each calendar, there are two routines provided. One converts dates
  37. * in that calendar to SDN and the other converts SDN to calendar dates.
  38. * The routines are named SdnTo<CALENDAR>() and <CALENDAR>ToSdn(), where
  39. * <CALENDAR> is the name of the calendar system.
  40. *
  41. * SDN values less than one are not supported. If a conversion routine
  42. * returns an SDN of zero, this means that the date given is either invalid
  43. * or is outside the supported range for that calendar.
  44. *
  45. * At least some validity checks are performed on input dates. For
  46. * example, a negative month number will result in the return of zero for
  47. * the SDN. A returned SDN greater than one does not necessarily mean that
  48. * the input date was valid. To determine if the date is valid, convert it
  49. * to SDN, and if the SDN is greater than zero, convert it back to a date
  50. * and compare to the original. For example:
  51. *
  52. * int y1, m1, d1;
  53. * int y2, m2, d2;
  54. * long int sdn;
  55. * ...
  56. * sdn = GregorianToSdn(y1, m1, d1);
  57. * if (sdn > 0) {
  58. * SdnToGregorian(sdn, &y2, &m2, &d2);
  59. * if (y1 == y2 && m1 == m2 && d1 == d2) {
  60. * ... date is valid ...
  61. * }
  62. * }
  63. *
  64. **************************************************************************/
  65. /* Gregorian calendar conversions. */
  66. void SdnToGregorian(long int sdn, int *pYear, int *pMonth, int *pDay);
  67. long int GregorianToSdn(int year, int month, int day);
  68. extern char *MonthNameShort[13];
  69. extern char *MonthNameLong[13];
  70. /* Julian calendar conversions. */
  71. void SdnToJulian(long int sdn, int *pYear, int *pMonth, int *pDay);
  72. long int JulianToSdn(int year, int month, int day);
  73. /* Jewish calendar conversions. */
  74. void SdnToJewish(long int sdn, int *pYear, int *pMonth, int *pDay);
  75. long int JewishToSdn(int year, int month, int day);
  76. extern char *JewishMonthName[14];
  77. extern char *JewishMonthNameLeap[14];
  78. extern char *JewishMonthHebName[14];
  79. extern char *JewishMonthHebNameLeap[14];
  80. extern int monthsPerYear[19];
  81. /* French republic calendar conversions. */
  82. void SdnToFrench(long int sdn, int *pYear, int *pMonth, int *pDay);
  83. long int FrenchToSdn(int inputYear, int inputMonth, int inputDay);
  84. extern char *FrenchMonthName[14];
  85. /* Islamic calendar conversions. */
  86. /* Not implemented yet. */
  87. /* Day of week conversion. 0=Sunday, 6=Saturday */
  88. int DayOfWeek(long int sdn);
  89. extern char *DayNameShort[7];
  90. extern char *DayNameLong[7];
  91. #endif /* SDNCAL_H */