#ifndef librock_ISOLATED /**************************************************************/ #define librock_IMPLEMENT_sdnfrnch #include /**************************************************************/ #endif #ifdef librock_IMPL_LIDESC #ifndef librock_NOIMPL_LIDESC_sdnfrnch /**************************************************************/ /* License awareness system. See http://www.mibsoftware.com/librock */ #include /* librock_LIDESC_HC=553e181388455f0eef17ccd9e2a51c1f3ae8daf0 */ char *librock_LIDESC_sdnfrnch[] = { "\n" __FILE__ librock_LIDESC_sdncal "\n", 0 }; /**************************************************************/ #endif #endif #ifdef librock_MANUAL_french_calendar librock_CHISEL subject /hard/time/ /* librock_french_calendar - French republican serial day number conversions (Scott E. Lee's sdncal library) */ /**/ #include void SdnToFrench( long int sdn, int *pYear, int *pMonth, int *pDay); /* * Convert a SDN to a French republican calendar date. If the input SDN is * before the first day of year 1 or after the last day of year 14, the * three output values will all be set to zero, otherwise *pYear will be in * the range 1 to 14 inclusive; *pMonth will be in the range 1 to 13 * inclusive; *pDay will be in the range 1 to 30 inclusive. If *pMonth is * 13, the SDN represents one of the holidays at the end of the year and * *pDay will be in the range 1 to 6 inclusive. */ long int librock_FrenchToSdn( int year, int month, int day); /* * Convert a French republican calendar date to a SDN. Zero is returned * when the input date is detected as invalid or out of the supported * range. The return value will be > 0 for all valid, supported dates, but * there are some invalid dates that will return a positive value. To * verify that a date is valid, convert it to SDN and then back and compare * with the original. */ char *librock_FrenchMonthName[14]; /* * Convert a French republican month number (1 to 13) to the name of the * French republican month (null terminated). An index of 13 (for the * "extra" days at the end of the year) will return the string "Extra". An * index of zero will return a zero length string. */ /* */ /* This package defines a set of routines that convert calendar dates to * and from a serial day number (SDN). The SDN is a serial numbering of * days where SDN 1 is November 25, 4714 BC in the Gregorian calendar and * SDN 2447893 is January 1, 1990. This system of day numbering is * sometimes referred to as Julian days, but to avoid confusion with the * Julian calendar, it is referred to as serial day numbers here. The term * Julian days is also used to mean the number of days since the beginning * of the current year. * * The SDN can be used as an intermediate step in converting from one * calendar system to another (such as Gregorian to Jewish). It can also * be used for date computations such as easily comparing two dates, * determining the day of the week, finding the date of yesterday or * calculating the number of days between two dates. * * SDN values less than one are not supported. If a conversion routine * returns an SDN of zero, this means that the date given is either invalid * or is outside the supported range for that calendar. * * At least some validity checks are performed on input dates. For * example, a negative month number will result in the return of zero for * the SDN. A returned SDN greater than one does not necessarily mean that * the input date was valid. To determine if the date is valid, convert it * to SDN, and if the SDN is greater than zero, convert it back to a date * and compare to the original. For example: */ int y1, m1, d1; int y2, m2, d2; long int sdn; ... sdn = GregorianToSdn(y1, m1, d1); if (sdn > 0) { SdnToGregorian(sdn, &y2, &m2, &d2); if (y1 == y2 && m1 == m2 && d1 == d2) { ... date is valid ... } } /* */ /* * These routines only convert dates in years 1 through 14 (Gregorian * dates 22 September 1792 through 22 September 1806). This more than * covers the period when the calendar was in use. * * I would support a wider range of dates, but I have not been able to * find an authoritative definition of when leap years were to have * occurred. There are suggestions that it was to skip a leap year ever * 100 years like the Gregorian calendar. */ /* */ /* * The French republican calendar was adopted in October 1793 during * the French Revolution and was abandoned in January 1806. The intent * was to create a new calendar system that was based on scientific * principals, not religious traditions. * * The year is divided into 12 months of 30 days each. The remaining 5 * to 6 days in the year are grouped at the end and are holidays. Each * month is divided into three decades (instead of weeks) of 10 days * each. * * The epoch (first day of the first year) is 22 September 1792 in the * Gregorian calendar. Leap years are every fourth year (year 3, 7, * 11, etc.) */ /* */ /* * This algorithm has been tested from the year 1 to 14. The source * code of the verification program is included in the sdncal package. */ /* */ /* * I have found no detailed, authoritative reference on this calendar. * The algorithms are based on a preponderance of less authoritative * sources. */ /* //No external calls */ /* Copyright 1993-1995, Scott E. Lee, all rights reserved. Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block. License text in librock_LIDESC_HC=553e181388455f0eef17ccd9e2a51c1f3ae8daf0 */ #endif /* MANUAL */ /* $selId: french.c,v 2.0 1995/10/24 01:13:06 lees Exp $ * Copyright 1993-1995, Scott E. Lee, all rights reserved. * Permission granted to use, copy, modify, distribute and sell so long as * the above copyright and this permission statement are retained in all * copies. THERE IS NO WARRANTY - USE AT YOUR OWN RISK. */ /************************************************************************** * * These are the externally visible components of this file: * * void * SdnToFrench( * long int sdn, * int *pYear, * int *pMonth, * int *pDay); * * Convert a SDN to a French republican calendar date. If the input SDN is * before the first day of year 1 or after the last day of year 14, the * three output values will all be set to zero, otherwise *pYear will be in * the range 1 to 14 inclusive; *pMonth will be in the range 1 to 13 * inclusive; *pDay will be in the range 1 to 30 inclusive. If *pMonth is * 13, the SDN represents one of the holidays at the end of the year and * *pDay will be in the range 1 to 6 inclusive. * * long int * FrenchToSdn( * int year, * int month, * int day); * * Convert a French republican calendar date to a SDN. Zero is returned * when the input date is detected as invalid or out of the supported * range. The return value will be > 0 for all valid, supported dates, but * there are some invalid dates that will return a positive value. To * verify that a date is valid, convert it to SDN and then back and compare * with the original. * * char *FrenchMonthName[14]; * * Convert a French republican month number (1 to 13) to the name of the * French republican month (null terminated). An index of 13 (for the * "extra" days at the end of the year) will return the string "Extra". An * index of zero will return a zero length string. * * VALID RANGE * * These routines only convert dates in years 1 through 14 (Gregorian * dates 22 September 1792 through 22 September 1806). This more than * covers the period when the calendar was in use. * * I would support a wider range of dates, but I have not been able to * find an authoritative definition of when leap years were to have * occurred. There are suggestions that it was to skip a leap year ever * 100 years like the Gregorian calendar. * * CALENDAR OVERVIEW * * The French republican calendar was adopted in October 1793 during * the French Revolution and was abandoned in January 1806. The intent * was to create a new calendar system that was based on scientific * principals, not religious traditions. * * The year is divided into 12 months of 30 days each. The remaining 5 * to 6 days in the year are grouped at the end and are holidays. Each * month is divided into three decades (instead of weeks) of 10 days * each. * * The epoch (first day of the first year) is 22 September 1792 in the * Gregorian calendar. Leap years are every fourth year (year 3, 7, * 11, etc.) * * TESTING * * This algorithm has been tested from the year 1 to 14. The source * code of the verification program is included in this package. * * REFERENCES * * I have found no detailed, authoritative reference on this calendar. * The algorithms are based on a preponderance of less authoritative * sources. * **************************************************************************/ #include "sdncal.h" #define SDN_OFFSET 2375474 #define DAYS_PER_4_YEARS 1461 #define DAYS_PER_MONTH 30 #define FIRST_VALID 2375840 #define LAST_VALID 2380952 void SdnToFrench( long int sdn, int *pYear, int *pMonth, int *pDay) { long int temp; int dayOfYear; if (sdn < FIRST_VALID || sdn > LAST_VALID) { *pYear = 0; *pMonth = 0; *pDay = 0; return; } temp = (sdn - SDN_OFFSET) * 4 - 1; *pYear = temp / DAYS_PER_4_YEARS; dayOfYear = (temp % DAYS_PER_4_YEARS) / 4; *pMonth = dayOfYear / DAYS_PER_MONTH + 1; *pDay = dayOfYear % DAYS_PER_MONTH + 1; } long int FrenchToSdn( int year, int month, int day) { /* check for invalid dates */ if (year < 1 || year > 14 || month < 1 || month > 13 || day < 1 || day > 30) { return(0); } return( (year * DAYS_PER_4_YEARS) / 4 + (month - 1) * DAYS_PER_MONTH + day + SDN_OFFSET ); } char *FrenchMonthName[14] = { "", "Vendemiaire", "Brumaire", "Frimaire", "Nivose", "Pluviose", "Ventose", "Germinal", "Floreal", "Prairial", "Messidor", "Thermidor", "Fructidor", "Extra" }; /* $Log: sdnfrnch.c,v $ Revision 1.5 2002/04/19 14:45:10 forrest@mibsoftware.com rights=#1 Correct license tags. Revision 1.4 2002/02/05 21:08:54 forrest@mibsoftware.com rights=#1 Standardized log Revision 1.3 2002/01/30 16:07:38 forrest@mibsoftware.com rights=#1 Renamed some .h files Revision 1.2 2002/01/28 17:29:10 forrest@mibsoftware.com rights=#1 Initial Revision 1.1 2001/11/20 04:34:18 forrest@mibsoftware.com rights=#1 rename rights#1 Copyright (c) Forrest J Cavalier III d-b-a Mib Software rights#1 License text in librock_LIDESC_HC=12440211096131f5976d36be0cddca4cd9152e45 Added librock_ISOLATED and librock_IMPL_LIDESC sections at the top. See http://www.mibsoftware.com/librock Renamed to be sdnfrnch.c (was french.c) Otherwise identical to original. librock_ACQUIRED: 2001-10-30 ftp://ftp.genealogy.org/pub/users/scottlee/sdncal20.zip http://genealogy.org/~scottlee/cal-overview.html License text in librock_LIDESC_HC=553e181388455f0eef17ccd9e2a51c1f3ae8daf0 */