1 /* This file is taken from http://www.genealogy.org/~scottlee/
2 Only this initial comment has been added. The next comment
3 gives the original copyright notice.
7 /* $selId: french.c,v 2.0 1995/10/24 01:13:06 lees Exp $
8 * Copyright 1993-1995, Scott E. Lee, all rights reserved.
9 * Permission granted to use, copy, modify, distribute and sell so long as
10 * the above copyright and this permission statement are retained in all
11 * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK.
14 /**************************************************************************
16 * These are the externally visible components of this file:
25 * Convert a SDN to a French republican calendar date. If the input SDN is
26 * before the first day of year 1 or after the last day of year 14, the
27 * three output values will all be set to zero, otherwise *pYear will be in
28 * the range 1 to 14 inclusive; *pMonth will be in the range 1 to 13
29 * inclusive; *pDay will be in the range 1 to 30 inclusive. If *pMonth is
30 * 13, the SDN represents one of the holidays at the end of the year and
31 * *pDay will be in the range 1 to 6 inclusive.
39 * Convert a French republican calendar date to a SDN. Zero is returned
40 * when the input date is detected as invalid or out of the supported
41 * range. The return value will be > 0 for all valid, supported dates, but
42 * there are some invalid dates that will return a positive value. To
43 * verify that a date is valid, convert it to SDN and then back and compare
46 * char *FrenchMonthName[14];
48 * Convert a French republican month number (1 to 13) to the name of the
49 * French republican month (null terminated). An index of 13 (for the
50 * "extra" days at the end of the year) will return the string "Extra". An
51 * index of zero will return a zero length string.
55 * These routines only convert dates in years 1 through 14 (Gregorian
56 * dates 22 September 1792 through 22 September 1806). This more than
57 * covers the period when the calendar was in use.
59 * I would support a wider range of dates, but I have not been able to
60 * find an authoritative definition of when leap years were to have
61 * occurred. There are suggestions that it was to skip a leap year ever
62 * 100 years like the Gregorian calendar.
66 * The French republican calendar was adopted in October 1793 during
67 * the French Revolution and was abandoned in January 1806. The intent
68 * was to create a new calendar system that was based on scientific
69 * principals, not religious traditions.
71 * The year is divided into 12 months of 30 days each. The remaining 5
72 * to 6 days in the year are grouped at the end and are holidays. Each
73 * month is divided into three decades (instead of weeks) of 10 days
76 * The epoch (first day of the first year) is 22 September 1792 in the
77 * Gregorian calendar. Leap years are every fourth year (year 3, 7,
82 * This algorithm has been tested from the year 1 to 14. The source
83 * code of the verification program is included in this package.
87 * I have found no detailed, authoritative reference on this calendar.
88 * The algorithms are based on a preponderance of less authoritative
91 **************************************************************************/
95 #define SDN_OFFSET 2375474
96 #define DAYS_PER_4_YEARS 1461
97 #define DAYS_PER_MONTH 30
98 #define FIRST_VALID 2375840
99 #define LAST_VALID 2380952
111 if (sdn < FIRST_VALID || sdn > LAST_VALID) {
118 temp = (sdn - SDN_OFFSET) * 4 - 1;
119 *pYear = temp / DAYS_PER_4_YEARS;
120 dayOfYear = (temp % DAYS_PER_4_YEARS) / 4;
121 *pMonth = dayOfYear / DAYS_PER_MONTH + 1;
122 *pDay = dayOfYear % DAYS_PER_MONTH + 1;
131 /* check for invalid dates */
132 if (year < 1 || year > 14 ||
133 month < 1 || month > 13 ||
139 return( (year * DAYS_PER_4_YEARS) / 4
140 + (month - 1) * DAYS_PER_MONTH
145 char *FrenchMonthName[14] = {