2 * This routine converts time as follows.
3 * The epoch is 0000 Jan 1 1970 GMT.
4 * The argument time is in seconds since then.
5 * The localtime(t) entry returns a pointer to an array
14 * weekday (0-6, Sun is 0)
16 * daylight savings flag
18 * The routine gets the daylight savings time from the environment.
21 * where tvec is produced by localtime
22 * returns a ptr to a character string
23 * that has the ascii time in the form
26 * Thu Jan 01 00:00:00 GMT 1970n0
27 * 012345678901234567890123456789
30 * ctime(t) just calls localtime, then asctime.
38 static char dmsize[12] =
40 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
43 #define dysize ctimedysize
44 static int dysize(int);
45 static void ct_numb(char*, int);
50 return asctime(localtime(t));
59 if (zonelookuptinfo(&ti, tim)!=-1) {
60 ct = gmtime(tim+ti.tzoff);
61 strncpy(ct->zone, ti.zone, sizeof ct->zone);
62 ct->zone[sizeof ct->zone-1] = 0;
77 * break initial number into days
87 * generate hours:minutes:seconds
96 * day is the day number.
97 * generate day of the week.
98 * The addend is 4 mod 7 (1/1/1970 was Thursday)
101 xtime.wday = (day + 7340036L) % 7;
107 for(d1 = 1970; day >= dysize(d1); d1++)
110 for (d1 = 1970; day < 0; d1--)
112 xtime.year = d1-1900;
113 xtime.yday = d0 = day;
119 if(dysize(d1) == 366)
121 for(d1 = 0; d0 >= dmsize[d1]; d1++)
126 strcpy(xtime.zone, "GMT");
134 static char cbuf[30];
136 strcpy(cbuf, "Thu Jan 01 00:00:00 GMT 1970\n");
137 ncp = &"SunMonTueWedThuFriSat"[t->wday*3];
141 ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[t->mon*3];
145 ct_numb(cbuf+8, t->mday);
146 ct_numb(cbuf+11, t->hour+100);
147 ct_numb(cbuf+14, t->min+100);
148 ct_numb(cbuf+17, t->sec+100);
157 ct_numb(cbuf+26, t->year+100);
166 if(y%4 == 0 && (y%100 != 0 || y%400 == 0))
173 ct_numb(char *cp, int n)
178 cp[0] = (n/10)%10 + '0';