Back to index

php5  5.3.10
french.c
Go to the documentation of this file.
00001 /* $selId: french.c,v 2.0 1995/10/24 01:13:06 lees Exp $
00002  * Copyright 1993-1995, Scott E. Lee, all rights reserved.
00003  * Permission granted to use, copy, modify, distribute and sell so long as
00004  * the above copyright and this permission statement are retained in all
00005  * copies.  THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
00006  */
00007 
00008 /**************************************************************************
00009  *
00010  * These are the externally visible components of this file:
00011  *
00012  *     void
00013  *     SdnToFrench(
00014  *         long int  sdn,
00015  *         int      *pYear,
00016  *         int      *pMonth,
00017  *         int      *pDay);
00018  *
00019  * Convert a SDN to a French republican calendar date.  If the input SDN is
00020  * before the first day of year 1 or after the last day of year 14, the
00021  * three output values will all be set to zero, otherwise *pYear will be in
00022  * the range 1 to 14 inclusive; *pMonth will be in the range 1 to 13
00023  * inclusive; *pDay will be in the range 1 to 30 inclusive.  If *pMonth is
00024  * 13, the SDN represents one of the holidays at the end of the year and
00025  * *pDay will be in the range 1 to 6 inclusive.
00026  *
00027  *     long int
00028  *     FrenchToSdn(
00029  *         int year,
00030  *         int month,
00031  *         int day);
00032  *
00033  * Convert a French republican calendar date to a SDN.  Zero is returned
00034  * when the input date is detected as invalid or out of the supported
00035  * range.  The return value will be > 0 for all valid, supported dates, but
00036  * there are some invalid dates that will return a positive value.  To
00037  * verify that a date is valid, convert it to SDN and then back and compare
00038  * with the original.
00039  *
00040  *     char *FrenchMonthName[14];
00041  *
00042  * Convert a French republican month number (1 to 13) to the name of the
00043  * French republican month (null terminated).  An index of 13 (for the
00044  * "extra" days at the end of the year) will return the string "Extra".  An
00045  * index of zero will return a zero length string.
00046  *
00047  * VALID RANGE
00048  *
00049  *     These routines only convert dates in years 1 through 14 (Gregorian
00050  *     dates 22 September 1792 through 22 September 1806).  This more than
00051  *     covers the period when the calendar was in use.
00052  *
00053  *     I would support a wider range of dates, but I have not been able to
00054  *     find an authoritative definition of when leap years were to have
00055  *     occurred.  There are suggestions that it was to skip a leap year ever
00056  *     100 years like the Gregorian calendar.
00057  *
00058  * CALENDAR OVERVIEW
00059  *
00060  *     The French republican calendar was adopted in October 1793 during
00061  *     the French Revolution and was abandoned in January 1806.  The intent
00062  *     was to create a new calendar system that was based on scientific
00063  *     principals, not religious traditions.
00064  *
00065  *     The year is divided into 12 months of 30 days each.  The remaining 5
00066  *     to 6 days in the year are grouped at the end and are holidays.  Each
00067  *     month is divided into three decades (instead of weeks) of 10 days
00068  *     each.
00069  *
00070  *     The epoch (first day of the first year) is 22 September 1792 in the
00071  *     Gregorian calendar.  Leap years are every fourth year (year 3, 7,
00072  *     11, etc.)
00073  *
00074  * TESTING
00075  *
00076  *     This algorithm has been tested from the year 1 to 14.  The source
00077  *     code of the verification program is included in this package.
00078  *
00079  * REFERENCES
00080  *
00081  *     I have found no detailed, authoritative reference on this calendar.
00082  *     The algorithms are based on a preponderance of less authoritative
00083  *     sources.
00084  *
00085  **************************************************************************/
00086 
00087 #include "sdncal.h"
00088 
00089 #define FRENCH_SDN_OFFSET         2375474
00090 #define DAYS_PER_4_YEARS   1461
00091 #define DAYS_PER_MONTH     30
00092 #define FIRST_VALID        2375840
00093 #define LAST_VALID         2380952
00094 
00095 void SdnToFrench(
00096                                    long int sdn,
00097                                    int *pYear,
00098                                    int *pMonth,
00099                                    int *pDay)
00100 {
00101        long int temp;
00102        int dayOfYear;
00103 
00104        if (sdn < FIRST_VALID || sdn > LAST_VALID) {
00105               *pYear = 0;
00106               *pMonth = 0;
00107               *pDay = 0;
00108               return;
00109        }
00110        temp = (sdn - FRENCH_SDN_OFFSET) * 4 - 1;
00111        *pYear = temp / DAYS_PER_4_YEARS;
00112        dayOfYear = (temp % DAYS_PER_4_YEARS) / 4;
00113        *pMonth = dayOfYear / DAYS_PER_MONTH + 1;
00114        *pDay = dayOfYear % DAYS_PER_MONTH + 1;
00115 }
00116 
00117 long int FrenchToSdn(
00118                                           int year,
00119                                           int month,
00120                                           int day)
00121 {
00122        /* check for invalid dates */
00123        if (year < 1 || year > 14 ||
00124               month < 1 || month > 13 ||
00125               day < 1 || day > 30) {
00126               return (0);
00127        }
00128        return ((year * DAYS_PER_4_YEARS) / 4
00129                      + (month - 1) * DAYS_PER_MONTH
00130                      + day
00131                      + FRENCH_SDN_OFFSET);
00132 }
00133 
00134 char *FrenchMonthName[14] =
00135 {
00136        "",
00137        "Vendemiaire",
00138        "Brumaire",
00139        "Frimaire",
00140        "Nivose",
00141        "Pluviose",
00142        "Ventose",
00143        "Germinal",
00144        "Floreal",
00145        "Prairial",
00146        "Messidor",
00147        "Thermidor",
00148        "Fructidor",
00149        "Extra"
00150 };
00151 
00152 
00153 /*
00154  * Local variables:
00155  * tab-width: 4
00156  * c-basic-offset: 4
00157  * End:
00158  * vim600: sw=4 ts=4 fdm=marker
00159  * vim<600: sw=4 ts=4
00160  */