ack/lang/cem/libcc.ansi/time/gmtime.c

42 lines
953 B
C
Raw Normal View History

1989-06-12 15:22:14 +00:00
/*
* gmtime - convert the calendar time into broken down time
*/
/* $Header$ */
#include <time.h>
#include <limits.h>
#include "loc_incl.h"
struct tm *
gmtime(register const time_t *timer)
{
static struct tm br_time;
register struct tm *timep = &br_time;
time_t time = *timer;
register unsigned long dayclock, dayno;
1989-12-18 15:33:48 +00:00
int year = EPOCH_YR;
1989-06-12 15:22:14 +00:00
dayclock = (unsigned long)time % SECS_DAY;
dayno = (unsigned long)time / SECS_DAY;
1989-06-12 15:22:14 +00:00
timep->tm_sec = dayclock % 60;
timep->tm_min = (dayclock % 3600) / 60;
timep->tm_hour = dayclock / 3600;
timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
while (dayno >= YEARSIZE(year)) {
dayno -= YEARSIZE(year);
year++;
}
1989-12-18 15:33:48 +00:00
timep->tm_year = year - YEAR0;
1989-06-12 15:22:14 +00:00
timep->tm_yday = dayno;
timep->tm_mon = 0;
while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
timep->tm_mon++;
}
timep->tm_mday = dayno + 1;
timep->tm_isdst = 0;
return timep;
}