/******************************************************************************* * c0xcalendar.h * Proposed ISO/IEC C 200X calendar date types and functions. * * Notes * The following preprocessor macro definition must be modified to suit * your runtime environment: * * _TIME_ERROR * * Unmodified, this header file assumes by default that the 'time_t' is * type 'int' and that only positive time values are valid, and defines the * macro above accordingly. * * Author * This code was written by David R. Tribble (david@tribble.com), Jul 2004 * thru Mar 2006. * It is hereby placed into the public domain, and may be used for all * purposes, both commercial and private. No warranty is provided for this * source code, and the author cannot be held liable for its use in any * way. * * References * See , Revision 2.1. * * See also * c0xcalendar.c * c0xlongtime.h * c0xtimezone.h * * Since * 2004-07-12 */ #ifndef c0x_calendar_h #define c0x_calendar_h 204 /* Identification */ #ifndef NO_H_IDENT static const char c0x_calendar_h_rev[] = "@(#)drt/text/stdc/c0xcalendar.h $Revision: 1.5 $ $Date: 2006/03/13 04:16:50 $"; #endif /* Standard includes */ #ifndef _stdc_stddef_h #include #define _stdc_stddef_h 1 #endif #ifndef _stdc_limits_h #include #define _stdc_limits_h 1 #endif #ifndef _stdc_time_h #include #define _stdc_time_h 1 #endif /* Local includes */ #ifndef c0x_longtime_h #include "c0xlongtime.h" #endif struct timezone; /******************************************************************************* * Public constants *******************************************************************************/ #define _CAL_YR_ERROR INT_MIN /* cal_year: Erroneous date */ #define _CAL_ERA_COMMON 0 /* cal_era: AD/CE */ #define _CAL_TYPE_GREGORIAN 0 /* Gregorian calendar type */ #define _CAL_NAME_GREGORIAN _c0x_cal_name_gregorian /* Gregorian calendar name */ #ifndef _TIME_ERROR #define _TIME_ERROR ((time_t) -1) /* Erroneous time_t value */ #endif extern const char _c0x_cal_name_gregorian[]; /******************************************************************************* * Public types *******************************************************************************/ /*------------------------------------------------------------------------------ * struct calendar * Contains a broken-down calendar date for a specific calendric type and * timezone. Also used to hold a broken-down delta time. * * See also * struct tm, */ #define _C0X_CALENDAR_VS 20060311 struct calendar { int cal__vers; /* Struct version */ int cal_type; /* Calendar type (_CAL_TYPE_XXX) */ int cal_era; /* Era [0] */ int cal_year; /* Year [1900,2399] */ int cal_mon; /* Month [1,12] */ int cal_week; /* Week of year [1,53] */ int cal_mday; /* Day of month [1,31] */ int cal_yday; /* Day of year [1,366] */ int cal_wday; /* Day of week [1,7] */ int cal_hour; /* Hour [0,23] */ int cal_min; /* Minute [0,59] */ int cal_sec; /* Second [0,60] */ long int cal_nsec; /* Nanosecond [0,999999999] */ long int cal_nmons; /* Total months difference */ long int cal_nweeks; /* Total weeks difference */ long int cal_ndays; /* Total days difference */ int cal_dsti; /* DST index [-1,1] */ int cal_leapsec; /* Accumulated leap seconds */ const struct timezone * cal_zone; /* Timezone applied */ int cal__r[12]; /* (Reserved for future use) */ }; /*------------------------------------------------------------------------------ * struct calendarinfo * Contains information about a supported calendric system. */ #define _C0X_CALENDARINFO_VS 20040702 struct calendarinfo { int ci__vers; /* Struct version */ int ci_type; /* Calendar type */ const char * ci_name; /* Calendar name */ longtime_t ci_time_min; /* Minimum long time value */ longtime_t ci_time_max; /* Maximum long time value */ int ci_era_min; /* Minimum era number */ int ci_era_max; /* Maximum era number */ int ci_year_min; /* Minimum year number (1900) */ int ci_year_max; /* Maximum year number (2399) */ int ci_mon_min; /* Minimum month (12) */ int ci_mon_max; /* Maximum month (12) */ int ci_week_min; /* Minimum week of year (0) */ int ci_week_max; /* Maximum week of year (53) */ int ci_mday_min; /* Minimum day of month (1) */ int ci_mday_max; /* Maximum day of month (31) */ int ci_yday_min; /* Minimum day of year (1) */ int ci_yday_max; /* Maximum day of year (366) */ int ci_wday_min; /* Minimum day of week (1) */ int ci_wday_max; /* Maximum day of week (7) */ int ci_wday_1st; /* Weekday in the 1st week (4) */ int ci_hour_min; /* Minimum hour of day (0) */ int ci_hour_max; /* Maximum hour of day (23) */ int ci_min_max; /* Maximum minute (59) */ int ci_sec_max; /* Maximum second (59) */ int ci_leap_sec; /* Leap seconds in effect (0) */ int ci__r[12]; /* (Reserved for future use) */ }; /******************************************************************************* * Public functions *******************************************************************************/ int calendaradd(struct calendar *date, const struct calendar *dif, int add); int calendardiff(struct calendar *dif, const struct calendar *a, const struct calendar *b); int calendarformat(char *buf, size_t max, const char *fmt, const struct calendar *date); int calendarscanf(const char *buf, const char *fmt, struct calendar *date, struct timezone *zone); int convertcalendar(struct calendar *dst, const struct calendar *src); const struct calendarinfo * getcalendarinfo(int type); int initcalendar(struct calendar *date, const char *name); longtime_t mklongtime(struct calendar *date, const struct timezone *zone); int setcalendartime(struct calendar *date, const struct timezone *zone, longtime_t t); int setcalendarzone(struct calendar *date, const struct timezone *oldzone, const struct timezone *newzone); #endif /* c0x_calendar_h */ /* End c0xcalendar.h */