nuclear@36: #include nuclear@36: #include "time.h" nuclear@36: nuclear@36: #define MINSEC 60 nuclear@36: #define HOURSEC (60 * MINSEC) nuclear@36: #define DAYSEC (24 * HOURSEC) nuclear@36: nuclear@36: static int is_leap_year(int yr); nuclear@36: nuclear@36: nuclear@36: static char *wday[] = { nuclear@36: "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" nuclear@36: }; nuclear@36: static char *mon[] = { nuclear@36: "Jan", "Feb", "Mar", "Apr", "May", "Jun", nuclear@36: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" nuclear@36: }; nuclear@36: nuclear@36: nuclear@36: char *asctime(struct tm *tm) nuclear@36: { nuclear@36: static char buf[64]; nuclear@36: nuclear@36: sprintf(buf, "%s %s %d %02d:%02d:%02d %d\n", wday[tm->tm_wday], nuclear@36: mon[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, nuclear@36: tm->tm_sec, tm->tm_year + 1900); nuclear@36: return buf; nuclear@36: } nuclear@36: nuclear@36: time_t mktime(struct tm *tm) nuclear@36: { nuclear@36: int i, num_years = tm->tm_year - 70; nuclear@36: int year = 1970; nuclear@36: int days = day_of_year(tm->tm_year + 1900, tm->tm_mon, tm->tm_mday - 1); nuclear@36: nuclear@36: for(i=0; itm_hour * HOURSEC + nuclear@36: tm->tm_min * MINSEC + tm->tm_sec; nuclear@36: } nuclear@36: nuclear@36: int day_of_year(int year, int mon, int day) nuclear@36: { nuclear@36: static int commdays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; nuclear@36: static int leapdays[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; nuclear@36: int *mdays, i, yday; nuclear@36: nuclear@36: mdays = is_leap_year(year) ? leapdays : commdays; nuclear@36: nuclear@36: yday = day; nuclear@36: for(i=0; i