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
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
1991-04-22 13:21:11 +00:00
|
|
|
#include "loc_time.h"
|
1989-06-12 15:22:14 +00:00
|
|
|
|
|
|
|
struct tm *
|
|
|
|
gmtime(register const time_t *timer)
|
|
|
|
{
|
|
|
|
static struct tm br_time;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
}
|