ack/lang/cem/libcc/gen/gmtime.c

40 lines
942 B
C
Raw Normal View History

1987-01-27 15:57:55 +00:00
#include <time.h>
static int monthsize[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
1987-02-05 21:36:42 +00:00
#define SECS_DAY (24*60L*60L)
1987-01-27 15:57:55 +00:00
#define YEARSIZE(year) ((year) % 4 ? 365 : 366)
struct tm *
gmtime(clock)
long *clock;
{
1987-02-05 21:36:42 +00:00
long cl = *clock;
1987-01-27 15:57:55 +00:00
long dayclock, dayno;
1987-02-05 21:36:42 +00:00
static struct tm tm_buf;
1987-01-27 15:57:55 +00:00
register struct tm *pbuf = &tm_buf;
register int *months = monthsize;
int year = 1970;
dayclock = cl % SECS_DAY;
dayno = cl / SECS_DAY;
pbuf->tm_sec = dayclock % 60;
pbuf->tm_min = (dayclock % 3600) / 60;
pbuf->tm_hour = dayclock / 3600;
pbuf->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
while (dayno >= YEARSIZE(year)) {
dayno -= YEARSIZE(year);
year++;
}
1987-02-05 21:36:42 +00:00
pbuf->tm_year = year - 1900;
1987-01-27 15:57:55 +00:00
pbuf->tm_yday = dayno;
pbuf->tm_isdst = 0;
if (YEARSIZE(year) == 366) monthsize[1] = 29;
while (dayno - *months >= 0) dayno -= *months++;
pbuf->tm_mday = dayno + 1;
pbuf->tm_mon = months - monthsize;
monthsize[1] = 28;
return pbuf;
}