6 static char *wday_ab
[] = {
7 "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
9 static char *wday
[] = {
10 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
12 static char *mon_ab
[] = {
13 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
14 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
16 static char *mon
[] = {
17 "January", "February", "March", "April", "May", "June",
18 "July", "August", "September", "October", "November", "December"
21 static char *putstr(char *d
, char *s
)
28 static char *puti(char *s
, unsigned long n
, int wid
, int zpad
)
31 for (i
= wid
- 1; i
>= 0; i
--) {
33 if (!zpad
&& i
< wid
- 1)
45 static char *puttz(char *s
)
47 int d
= timezone
/ 60;
54 s
= puti(s
, d
/ 60, 2, 1);
55 s
= puti(s
, d
% 60, 2, 1);
59 int strftime(char *s
, int n
, char *f
, struct tm
*tm
)
64 while (s
+ 1 < e
&& *f
) {
76 s
= putstr(s
, wday_ab
[tm
->tm_wday
]);
79 s
= putstr(s
, wday
[tm
->tm_wday
]);
83 s
= putstr(s
, mon_ab
[tm
->tm_mon
]);
86 s
= putstr(s
, mon
[tm
->tm_mon
]);
89 s
+= strftime(s
, e
- s
, "%b %a %d %k:%M:%S %Z %Y", tm
);
92 s
= puti(s
, (1900 + tm
->tm_year
) / 100, 2, 1);
95 s
= puti(s
, tm
->tm_mday
, 2, 1);
98 s
+= strftime(s
, e
- s
, "%m/%d/%y", tm
);
101 s
= puti(s
, tm
->tm_mday
, 2, 0);
104 s
+= strftime(s
, e
- s
, "%Y/%m/%d", tm
);
107 s
= puti(s
, tm
->tm_hour
, 2, 1);
110 val
= tm
->tm_hour
> 12 ? tm
->tm_hour
- 12 : tm
->tm_hour
;
111 s
= puti(s
, val
? val
: 12, 2, 1);
114 s
= puti(s
, tm
->tm_yday
+ 1, 3, 1);
117 s
= puti(s
, tm
->tm_hour
, 2, 1);
120 s
= puti(s
, tm
->tm_mon
+ 1, 2, 1);
123 s
= puti(s
, tm
->tm_min
, 2, 1);
129 s
= putstr(s
, tm
->tm_hour
>= 12 ? "PM" : "AM");
132 s
= putstr(s
, tm
->tm_hour
>= 12 ? "pm" : "am");
135 s
+= strftime(s
, e
- s
, "%I:%M:%S %p", tm
);
138 s
+= strftime(s
, e
- s
, "%H:%M", tm
);
141 s
= puti(s
, tm
->tm_sec
, 2, 1);
147 s
+= strftime(s
, e
- s
, "%H:%M:%S", tm
);
150 s
= puti(s
, tm
->tm_wday
? tm
->tm_wday
: 7, 1, 0);
153 s
= puti(s
, tm
->tm_wday
, 1, 0);
156 s
+= strftime(s
, e
- s
, "%b %a %d", tm
);
159 s
+= strftime(s
, e
- s
, "%k:%M:%S", tm
);
162 s
= puti(s
, tm
->tm_year
% 100, 2, 1);
165 s
= puti(s
, 1900 + tm
->tm_year
, 4, 1);