typedef unsigned char BYTE; typedef unsigned short WORD; typedef struct { WORD wYear; BYTE byMonth; BYTE byDay; BYTE byHour; BYTE byMinute; BYTE bySecond; WORD wMilliSec; }SDateTime; #define TM_YEAR_BASE 0 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0 ) || (((y) % 400) == 0 && ((y) % 4000) != 0)) /************************************************************************ * * daysSinceEpoch - calculate number days since ANSI C epoch * * The (year + 1)/4 term accounts for leap years, the * first of which was 1972 & should be added starting '73 * * RETURNS: * NOMANUAL */ int __daysSinceEpoch_db( int year, /* Years since epoch */int yday /* days since Jan 1 */) { if( year >= 0 ) /* 1970 + */ return ( (365 * year) + (year + 1) / 4 + yday ); else /* 1969 - */ return ( (365 * year) + (year - 2) / 4 + yday ); } /************************************************************************ * * julday - calculate Julian Day given year, month, day * Inputs : year (years since 1900), month (0 - 11), * day (1 - 31) * Comment : Returns Julian day in range 1:366. * Unix wants 0:365 * RETURNS: Julian day * NOMANUAL */ int __julday_db( int yr, /* year */int mon, /* month */int day /* day */) { static jdays[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; int leap = 0; if (isleap (yr + TM_YEAR_BASE)) { /* * If it is a leap year, leap only gets set if the day is * after beginning of March (SPR #4251). */ if (mon > 1) leap = 1; } return (jdays[mon] + day + leap); } /********************************************************************** GetSecondSinceEpoch--Get Seconds since 1970 */ int GetSecondSinceEpoch(SDateTime* sDateTime) { int julday; int day; if( sDateTime->wYear < 100 ) { sDateTime->wYear += 2000 ; }/*if*/ julday=__julday_db(sDateTime->wYear,sDateTime->byMonth - 1,sDateTime->byDay ); day=__daysSinceEpoch_db(sDateTime->wYear-1970,julday); return( ( (day*24 + sDateTime->byHour)*60 + sDateTime->byMinute )*60 +sDateTime->bySecond); }