Back to index

php5  5.3.10
sdncal.h
Go to the documentation of this file.
00001 #ifndef SDNCAL_H
00002 #define SDNCAL_H
00003 /*
00004  * This code has been modified for use with PHP
00005  * by Shane Caraveo shane@caraveo.com
00006  * see below for more details
00007  *
00008  */
00009 
00010 /* $selId: sdncal.h,v 2.0 1995/10/24 01:13:06 lees Exp $
00011  * Copyright 1993-1995, Scott E. Lee, all rights reserved.
00012  * Permission granted to use, copy, modify, distribute and sell so long as
00013  * the above copyright and this permission statement are retained in all
00014  * copies.  THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
00015  */
00016 
00017 /**************************************************************************
00018  *
00019  * This package defines a set of routines that convert calendar dates to
00020  * and from a serial day number (SDN).  The SDN is a serial numbering of
00021  * days where SDN 1 is November 25, 4714 BC in the Gregorian calendar and
00022  * SDN 2447893 is January 1, 1990.  This system of day numbering is
00023  * sometimes referred to as Julian days, but to avoid confusion with the
00024  * Julian calendar, it is referred to as serial day numbers here.  The term
00025  * Julian days is also used to mean the number of days since the beginning
00026  * of the current year.
00027  *
00028  * The SDN can be used as an intermediate step in converting from one
00029  * calendar system to another (such as Gregorian to Jewish).  It can also
00030  * be used for date computations such as easily comparing two dates,
00031  * determining the day of the week, finding the date of yesterday or
00032  * calculating the number of days between two dates.
00033  *
00034  * When using this software on 16 bit systems, be careful to store SDNs in
00035  * a long int, because it will not fit in the 16 bits that some systems
00036  * allocate to an int.
00037  *
00038  * For each calendar, there are two routines provided.  One converts dates
00039  * in that calendar to SDN and the other converts SDN to calendar dates.
00040  * The routines are named SdnTo<CALENDAR>() and <CALENDAR>ToSdn(), where
00041  * <CALENDAR> is the name of the calendar system.
00042  *
00043  * SDN values less than one are not supported.  If a conversion routine
00044  * returns an SDN of zero, this means that the date given is either invalid
00045  * or is outside the supported range for that calendar.
00046  *
00047  * At least some validity checks are performed on input dates.  For
00048  * example, a negative month number will result in the return of zero for
00049  * the SDN.  A returned SDN greater than one does not necessarily mean that
00050  * the input date was valid.  To determine if the date is valid, convert it
00051  * to SDN, and if the SDN is greater than zero, convert it back to a date
00052  * and compare to the original.  For example:
00053  *
00054  *    int y1, m1, d1;
00055  *    int y2, m2, d2;
00056  *    long int sdn;
00057  *    ...
00058  *    sdn = GregorianToSdn(y1, m1, d1);
00059  *    if (sdn > 0) {
00060  *        SdnToGregorian(sdn, &y2, &m2, &d2);
00061  *        if (y1 == y2 && m1 == m2 && d1 == d2) {
00062  *            ... date is valid ...
00063  *        }
00064  *    }
00065  *
00066  **************************************************************************/
00067 
00068 /* Gregorian calendar conversions. */
00069 void SdnToGregorian(long int sdn, int *pYear, int *pMonth, int *pDay);
00070 long int GregorianToSdn(int year, int month, int day);
00071 extern char *MonthNameShort[13];
00072 extern char *MonthNameLong[13];
00073 
00074 /* Julian calendar conversions. */
00075 void SdnToJulian(long int sdn, int *pYear, int *pMonth, int *pDay);
00076 long int JulianToSdn(int year, int month, int day);
00077 
00078 /* Jewish calendar conversions. */
00079 void SdnToJewish(long int sdn, int *pYear, int *pMonth, int *pDay);
00080 long int JewishToSdn(int year, int month, int day);
00081 extern char *JewishMonthName[14];
00082 extern char *JewishMonthHebName[14];
00083 
00084 /* French republic calendar conversions. */
00085 void SdnToFrench(long int sdn, int *pYear, int *pMonth, int *pDay);
00086 long int FrenchToSdn(int inputYear, int inputMonth, int inputDay);
00087 extern char *FrenchMonthName[14];
00088 
00089 /* Islamic calendar conversions. */
00090 /* Not implemented yet. */
00091 
00092 /* Day of week conversion.  0=Sunday, 6=Saturday */
00093 int DayOfWeek(long int sdn);
00094 extern char *DayNameShort[7];
00095 extern char *DayNameLong[7];
00096 
00097 #endif /* SDNCAL_H */