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