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

44 lines
947 B
C
Raw Normal View History

1989-06-12 15:22:14 +00:00
/*
* gmtime - convert the calendar time into broken down time
*/
1994-06-24 14:02:31 +00:00
/* $Id$ */
1989-06-12 15:22:14 +00:00
2018-06-21 20:33:47 +00:00
#include <time.h>
#include <limits.h>
#include "loc_time.h"
1989-06-12 15:22:14 +00:00
2018-06-21 20:33:47 +00:00
struct tm*
gmtime(register const time_t* timer)
1989-06-12 15:22:14 +00:00
{
static struct tm br_time;
2018-06-21 20:33:47 +00:00
register struct tm* timep = &br_time;
1991-09-30 16:24:45 +00:00
time_t tim = *timer;
1989-06-12 15:22:14 +00:00
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
1991-09-30 16:24:45 +00:00
dayclock = (unsigned long)tim % SECS_DAY;
dayno = (unsigned long)tim / 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;
2018-06-21 20:33:47 +00:00
timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
while (dayno >= YEARSIZE(year))
{
1989-06-12 15:22:14 +00:00
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;
2018-06-21 20:33:47 +00:00
while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon])
{
1989-06-12 15:22:14 +00:00
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
timep->tm_mon++;
}
timep->tm_mday = dayno + 1;
timep->tm_isdst = 0;
return timep;
}