/* @(#)ctime.c 4.1 (Berkeley) 12/21/80 */
* This routine converts time as follows.
* The epoch is 0000 Jan 1 1970 GMT.
* The argument time is in seconds since then.
* The localtime(t) entry returns a pointer to an array
* weekday (0-6, Sun is 0)
* The routine calls the system to determine the local
* timezone and whether Daylight Saving Time is permitted locally.
* (DST is then determined by the current US standard rules)
* There is a table that accounts for the peculiarities
* undergone by daylight time in 1974-1975.
* The routine does not work
* in Saudi Arabia which runs on Solar time.
* where tvec is produced by localtime
* returns a ptr to a character string
* that has the ascii time in the form
* Thu Jan 01 00:00:00 1970n0\b\b\\
* 01234567890123456789012345
* ctime(t) just calls localtime, then asctime.
* The following table is used for 1974 and 1975 and
* gives the day number of the first day after the Sunday of the
5, 333, /* 1974: Jan 6 - last Sun. in Nov */
58, 303, /* 1975: Last Sun. in Feb - last Sun in Oct */
return(asctime(localtime(t
)));
register daylbegin
, daylend
;
copyt
= *tim
- (long)systime
.timezone
*60;
daylbegin
= 119; /* last Sun in Apr */
daylend
= 303; /* Last Sun in Oct */
if (ct
->tm_year
==74 || ct
->tm_year
==75) {
daylbegin
= daytab
[ct
->tm_year
-74].daylb
;
daylend
= daytab
[ct
->tm_year
-74].dayle
;
daylbegin
= sunday(ct
, daylbegin
);
daylend
= sunday(ct
, daylend
);
(dayno
>daylbegin
|| (dayno
==daylbegin
&& ct
->tm_hour
>=2)) &&
(dayno
<daylend
|| (dayno
==daylend
&& ct
->tm_hour
<1))) {
* The argument is a 0-origin day number.
* The value is the day number of the first
* Sunday on or after the day.
d
+= dysize(t
->tm_year
) - 365;
return(d
- (d
- t
->tm_yday
+ t
->tm_wday
+ 700) % 7);
* break initial number into days
* generate hours:minutes:seconds
* generate day of the week.
* The addend is 4 mod 7 (1/1/1970 was Thursday)
xtime
.tm_wday
= (day
+7340036)%7;
if (day
>=0) for(d1
=70; day
>= dysize(d1
); d1
++)
else for (d1
=70; day
<0; d1
--)
xtime
.tm_yday
= d0
= day
;
for(d1
=0; d0
>= dmsize
[d1
]; d1
++)
for (ncp
= "Day Mon 00 00:00:00 1900\n"; *cp
++ = *ncp
++;);
ncp
= &"SunMonTueWedThuFriSat"[3*t
->tm_wday
];
ncp
= &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp
)*3];
cp
= ct_numb(cp
, *--tp
+100);
cp
= ct_numb(cp
, *--tp
+100);
cp
= ct_numb(cp
, *--tp
+100);
cp
= ct_numb(cp
, t
->tm_year
+100);