/*==JULIAN.H==========================================================*/ /* */ /* Module : JULIAN */ /* */ /* Project : UTILS */ /* */ /* Description: General date utility for computing Julian days */ /* and a number of nice goodies (weekday, validity */ /* of a date ...) */ /* */ /* Julian calendar (introduced by Julius Caesar): every fourth */ /* year is a leap year. ("Old Style") */ /* Gregorian calendar (introduced by pope Gregor): every fourth */ /* year is a leap year with the exception of every hundredth */ /* year. But every fourhundredth year we have the exception */ /* of the exception. (1700, 1800, 1900 were no leap years, */ /* 2000 will be one). ("New Style") */ /* Julian days (introduced by Scaliger (1629): continuous */ /* count of days since the first of January 4713 BC (Old */ /* Style). */ /* */ /* See Arno Schmidt's "Julianische Tage" (in "Aus julianischen */ /* Tagen", Fischer Taschenbuch 1926, Frankfurt am Main, 1979) */ /* for details about Julian days. */ /* */ /* Eulers Analysis Infinitorum has a nice application of */ /* continued fractions to the Julian/Gregorian question. */ /* The date given as an argument is assumed to be in the */ /* "New Style". */ /* */ /* When Gregor introduced this style in 1582 he dropped 10 days */ /* (after October 4th 1582 followed October 15th). */ /* The catholic cantons of Switzerland made the switch in the */ /* year 1583. The other cantons had the year 1701 start on Jan */ /* 12th. */ /* */ /* In the functions below we assume that the dates BC are */ /* given as negative years (-1 for 1 BC) and that no year 0 */ /* was counted. We don't support dates before 4713 BC. */ /* */ /*--------------------------------------------------------------------*/ /* */ /* (c) Enter AG, Zrich, 1991 */ /* */ /*--------------------------------------------------------------------*/ /* */ /* Author(s) : Hartwig Thomas */ /* */ /* Started : 2'448'595 */ /* */ /* Finished : 2'448'599 */ /* */ /*--------------------------------------------------------------------*/ /* */ /* Modifications: */ /* */ /* AUTHOR | DATE | COMMENT */ /* ----------------|--------------|-------------------------------- */ /* | | */ /* | | */ /* */ /*====================================================================*/ #ifndef JULIAN_DEF #define JULIAN_DEF #include /* for struct date and struct time */ #define bool int #define FALSE 0 #define TRUE 1 /* defines for timedate in daystostr and strtodays */ #define DATE_USA 0 #define DATE_EUROPE 1 #define DATE_JAPAN 2 /*--------------------------------------------------------------------*/ /* timedatereal reports whether realtimeclock is available on system */ /*--------------------------------------------------------------------*/ bool timedatereal(void); /*--------------------------------------------------------------------*/ /* datevalid returns TRUE if conversion to Julian days and back is */ /* identity */ /*--------------------------------------------------------------------*/ int datevalid(struct date *pdate,bool gregorian); /*--------------------------------------------------------------------*/ /* dayinyear returns the day in the year (assumes gregorian date) */ /*--------------------------------------------------------------------*/ int dayinyear(struct date *pdate); /*--------------------------------------------------------------------*/ /* calendarweek returns the calendar week (assumes gregorian date) */ /*--------------------------------------------------------------------*/ int calendarweek(struct date *pdate); /*--------------------------------------------------------------------*/ /* julianweekday determines the weekday (0 = Monday, ..., 6 = Sunday) */ /*--------------------------------------------------------------------*/ int julianweekday(double days); /*--------------------------------------------------------------------*/ /* getjuliantime gets the (real time) time and date in Julian days */ /*--------------------------------------------------------------------*/ double getjuliantime(void); /*--------------------------------------------------------------------*/ /* setjuliantime sets the (real time) time and date from julian days */ /*--------------------------------------------------------------------*/ void setjuliantime(double days); /*--------------------------------------------------------------------*/ /* juliantostr converts date according to country specification */ /* (timedate = 0 (USA mm/dd/yy), 1 (Europe dd.mm.yy), */ /* 2 (Japan yy:mm:dd). */ /* The boolean full selects expansion of year to include century. */ /* If ts is not NULL 'hh:mm:ss' is returned as time string ts. */ /*--------------------------------------------------------------------*/ void juliantostr(int timedate, double days, char *ds, char *ts, bool gregorian, bool full); /*--------------------------------------------------------------------*/ /* strtojulian converts date according to country specification */ /* (timedate = 0 (USA mm/dd/yy), 1 (Europe dd.mm.yy), */ /* 2 (Japan yy:mm:dd) */ /* The boolean full selects expansion of year to include century. */ /* If ts is not NULL then the time is added as a fraction of the day. */ /*--------------------------------------------------------------------*/ bool strtojulian(int timedate, char *ds, char *ts, double *pdays, bool gregorian, bool full); /*--------------------------------------------------------------------*/ /* juliandays */ /* converts a date (Julian or Gregorian) into Julian days. */ /*--------------------------------------------------------------------*/ double juliandays(struct date *pdate, bool gregorian); /*--------------------------------------------------------------------*/ /* juliandate */ /* converts a Julian day into a date. */ /*--------------------------------------------------------------------*/ void juliandate(double days, struct date *pdate, bool gregorian); #endif /*--End JULIAN.H------------------------------------------------------*/