sdncal.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * zend_long 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. #include "php.h"
  66. /* Gregorian calendar conversions. */
  67. void SdnToGregorian(zend_long sdn, int *pYear, int *pMonth, int *pDay);
  68. zend_long GregorianToSdn(int year, int month, int day);
  69. extern const char * const MonthNameShort[13];
  70. extern const char * const MonthNameLong[13];
  71. /* Julian calendar conversions. */
  72. void SdnToJulian(zend_long sdn, int *pYear, int *pMonth, int *pDay);
  73. zend_long JulianToSdn(int year, int month, int day);
  74. /* Jewish calendar conversions. */
  75. void SdnToJewish(zend_long sdn, int *pYear, int *pMonth, int *pDay);
  76. zend_long JewishToSdn(int year, int month, int day);
  77. extern const char * const JewishMonthName[14];
  78. extern const char * const JewishMonthNameLeap[14];
  79. extern const char * const JewishMonthHebName[14];
  80. extern const char * const JewishMonthHebNameLeap[14];
  81. extern const int monthsPerYear[19];
  82. /* French republic calendar conversions. */
  83. void SdnToFrench(zend_long sdn, int *pYear, int *pMonth, int *pDay);
  84. zend_long FrenchToSdn(int inputYear, int inputMonth, int inputDay);
  85. extern const char * const FrenchMonthName[14];
  86. /* Islamic calendar conversions. */
  87. /* Not implemented yet. */
  88. /* Day of week conversion. 0=Sunday, 6=Saturday */
  89. int DayOfWeek(zend_long sdn);
  90. extern const char * const DayNameShort[7];
  91. extern const char * const DayNameLong[7];
  92. #endif /* SDNCAL_H */