Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc.ansi / time / gmtime.c
1 /*
2  * gmtime - convert the calendar time into broken down time
3  */
4 /* $Id: gmtime.c,v 1.6 1994/06/24 11:58:08 ceriel Exp $ */
5
6 #include        <time.h>
7 #include        <limits.h>
8 #include        "loc_time.h"
9
10 struct tm *
11 gmtime(register const time_t *timer)
12 {
13         static struct tm br_time;
14         register struct tm *timep = &br_time;
15         time_t tim = *timer;
16         register unsigned long dayclock, dayno;
17         int year = EPOCH_YR;
18
19         dayclock = (unsigned long)tim % SECS_DAY;
20         dayno = (unsigned long)tim / SECS_DAY;
21
22         timep->tm_sec = dayclock % 60;
23         timep->tm_min = (dayclock % 3600) / 60;
24         timep->tm_hour = dayclock / 3600;
25         timep->tm_wday = (dayno + 4) % 7;       /* day 0 was a thursday */
26         while (dayno >= YEARSIZE(year)) {
27                 dayno -= YEARSIZE(year);
28                 year++;
29         }
30         timep->tm_year = year - YEAR0;
31         timep->tm_yday = dayno;
32         timep->tm_mon = 0;
33         while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
34                 dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
35                 timep->tm_mon++;
36         }
37         timep->tm_mday = dayno + 1;
38         timep->tm_isdst = 0;
39
40         return timep;
41 }