i4 adu_2monthsize( i4 month, i4 year) { register i4 size; i4 yrDays; /* WECO compilers can't pass address ** of register variable */ size = Adu_ii_dmsize[month - 1]; if ( month == 2 ) { TMyrsize((i4) year, &yrDays); if ( yrDays == LEAPYEAR ) size++; /* This is February of a leap year */ } return (size); }
static VOID TMtz_cvtime( i4 time, struct timevect *t) { i4 mo, yr; i4 mdays, ydays; i4 noyears; i4 nodays; i4 i; /* get seconds, minutes, hours */ t->tm_sec = time % 60; time /= 60; if( t->tm_sec < 0) { t->tm_sec += 60; time--; } t->tm_min = time % 60; time /= 60; if( t->tm_min < 0) { t->tm_min += 60; time--; } t->tm_hour = time % 24; time /= 24; if( t->tm_hour < 0) { t->tm_hour += 24; time--; } /* get day of week */ t->tm_wday = (time + 4) % 7; /* at this point, time is number of days since 1-jan-1970 */ /* get the year. first, add enough days to get us to 1/1/1601. ** this date is special in that it is after a leapyear where ** the year is divisible by 400 and 100. The formula is good till ** the year 3012 or so. */ #define DAYS_SINCE_1601 134774 /* 1-1-1970 - 1-1-1601 */ /* number of days since 1601 */ i = time + DAYS_SINCE_1601; /* number of years since 1601 */ noyears = (i-i/1460+i/36500-i/146000)/365; /* number of days to first day of current year */ nodays = noyears*365 + noyears/4 - noyears/100 + noyears/400 - DAYS_SINCE_1601; time -= nodays; yr = noyears + 1601; /* xxxx year */ t->tm_year = yr - 1900; /* offset from 1900 . why?? */ t->tm_yday = time; /* get month */ TMyrsize(yr, &ydays); for (mo = 0; mo < 12; mo++) { if ((mo == 1) && (ydays == LEAPYEAR)) mdays = 29; else { switch( mo) { case 1: mdays = 28; break; case 3: case 5: case 8: case 10: mdays = 30; break; default: mdays = 31; break; } } if (time >= mdays) time -= mdays; else break; } if (mo > 11) mo = 11; t->tm_mon = mo; t->tm_mday = time + 1; return; }