/*============================================================================= * drt/sys/ktimec.h * DRT primitive date and time local definitions. * * Notes * This header file is meant to be used only for compiling the drt_time_t * source files, and is not meant to be distributed publicly. * * History * 0.01, 1999-03-22, David R Tribble. * First cut. * * 1.00, 1999-04-27, David R Tribble. * Corrected macro constants. * * [Private] * Copyright ©1999, by David R. Tribble, all rights reserved. * See "drt/sys/copyr.txt" for more information. *----------------------------------------------------------------------------*/ #ifndef drt_sys_ktimec_h #define drt_sys_ktimec_h 1 #ifdef __cplusplus extern "C" { #endif /* Identification */ #ifndef NO_H_IDENT static const char drt_sys_ktimec_h_id[] = "@(#)drt/sys/ktimec.h 1.00"; #endif /* System includes */ #ifndef drt_std_time_h #include #define drt_std_time_h 1 #endif /* Special includes */ #ifndef drt_sys_kdefs_h #include "kdefs.h" #endif /* Local includes */ #ifndef drt_sys_ktime_h #include "ktime.h" #endif /* Local wrappers */ #include "klib1.h" /*----------------------------------------------------------------------------- * Public constants *----------------------------------------------------------------------------*/ extern const short drt_time_mdays[]; /* Accumulated days per month */ extern const drt_time_t DRT_TIME_BC4713; /* BC4713-01-01 12:00:00.000 Z */ extern const drt_time_t DRT_TIME_BC0001; /* BC0001-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD0001; /* AD0001-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1601; /* AD1601-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1865; /* AD1865-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1858; /* AD1858-11-17 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1900; /* AD1900-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1970; /* AD1970-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1972; /* AD1972-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD1980; /* AD1980-01-01 00:00:00.000 Z */ extern const drt_time_t DRT_TIME_AD2001; /* AD2001-01-01 00:00:00.000 Z */ /*----------------------------------------------------------------------------- * Local constants *----------------------------------------------------------------------------*/ /* Constants that define the epoch */ #define TICKS_PER_SEC 10000000L /* Ticks in a second */ #define NSEC_PER_TICKS (1000000000L/TICKS_PER_SEC) /* Nanoseconds in a tick */ #define TIME_ZDYEAR 2001 /* Zero year (ZD) of the epoch */ #define TIME_ZDOFFSET 0L /* ZD days offset since 400yr */ #define TIME_ZDYRDAY 0 /* 1st yday of ZD */ #define TIME_Z400YR ((TIME_ZDYEAR-1)/400*400 + 1) /* 1st year of 400yr cycle */ #define TIME_ZWKDAY 1 /* 1st wkday of 400yr cycle */ #define TIME_UNKNOWN LLONG_MIN /* Unknown time */ #define TIME_NEVER LLONG_MAX /* Never time */ #define TIME_MINYEAR -9998 /* Min year number */ #define TIME_MAXYEAR +9999 /* Max year number */ #define TIME_MIN MAKE_TICKS(TIME_MINYEAR, 0, 0,0,0,0) /* Minimum valid time */ #define TIME_MAX (MAKE_TICKS(TIME_MAXYEAR+1, 0, 0,0,0,0) - 1) /* Maximum valid time */ /* Manifest constants */ #define LLONG_FMT DRT_LLONG_FMT #define SECS_PER_HOUR 3600L /* Seconds per hour */ #define SECS_PER_DAY 86400L /* 24 hours of 60*60 secs */ #define SECS_PER_YEAR 31556952L /* 365.2425 days, 365+05:49:12 */ #define SECS_PER_4YR (SECS_PER_YEAR * 4) /* Seconds in a 4-year period */ #define SECS_PER_100YR ((drt_time_t)SECS_PER_YEAR * 100) /* Seconds in a 100-year period */ #define SECS_PER_400YR ((drt_time_t)SECS_PER_YEAR * 400) /* Seconds in a 400-year period */ #define DAYS_PER_YEAR 365L /* 365, no leap days */ #define DAYS_PER_4YR 1461L /* 365*4 + 1 leap day */ #define DAYS_PER_100YR 36524L /* 365*100 + 24 leap days */ #define DAYS_PER_400YR 146097L /* 365*400 + 97 leap days */ #define TICKS_PER_HOUR ((drt_int64_t)TICKS_PER_SEC * SECS_PER_HOUR) /* Ticks in an hour */ #define TICKS_PER_DAY ((drt_int64_t)TICKS_PER_SEC * SECS_PER_DAY) /* Ticks in a day */ #define TICKS_PER_YEAR ((drt_int64_t)TICKS_PER_SEC * SECS_PER_YEAR) /* Ticks in a year */ #define TICKS_PER_4YR (DAYS_PER_4YR * TICKS_PER_DAY) /* Ticks in a 4-year period */ #define TICKS_PER_100YR (DAYS_PER_100YR * TICKS_PER_DAY) /* Ticks in a 100-year period */ #define TICKS_PER_400YR (DAYS_PER_400YR * TICKS_PER_DAY) /* Ticks in a 400-year cycle */ #define TIME_YR_UNKNOWN INT_MIN /* Indicates INVALID date */ #define TIME_YR_NEVER INT_MAX /* Indicates NEVER date */ /*----------------------------------------------------------------------------- * Local function macros *----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- * MAKE_TICKS() * Computes the proper drt_time_t (ticks) value for a given year 'yr', day * of year 'yd', hour 'h', minute 'm', second 's', and nanosecond 'n'. *----------------------------------------------------------------------------*/ #define MAKE_TICKS(yr,yd,h,m,s,n) \ ( ( ((yr) >= TIME_Z400YR) ? DATE_DAYSP(yr, yd) : DATE_DAYSN(yr, yd) )\ * TICKS_PER_DAY + TIME_TICKS(h, m, s, n) ) #define DATE_DAYSP(yr,yday) \ DATE_DAYS(yr, yday) #define DATE_DAYSN(yr,yday) \ ( DATE_DAYS( (yr) + ((TIME_Z400YR-(yr))/400+1)*400, yday)\ - ((TIME_Z400YR-(yr))/400+1) * DAYS_PER_400YR ) #define DATE_DAYS(yr,yday) \ (\ ((yr) - TIME_Z400YR)/400 * DAYS_PER_400YR + \ ((yr) - TIME_Z400YR)%400/100 * DAYS_PER_100YR +\ ((yr) - TIME_Z400YR)%100/4 * DAYS_PER_4YR + \ ((yr) - TIME_Z400YR)%4 * DAYS_PER_YEAR + \ (yday) +\ TIME_ZDOFFSET\ ) #define TIME_TICKS(h,m,s,n) \ ((((h)*60L + (m))*60L + (s)) * (drt_time_t)TICKS_PER_SEC\ + (n)/NSEC_PER_TICKS) /* Wrapper end */ #include "klib2.h" #ifdef __cplusplus } #endif #endif /* drt_sys_ktimec_h */ /* End ktimec.h */