2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 #include <libraries/locale.h>
9 #include <proto/locale.h> */
11 #define ADDS(st) tmp=strftime(s,maxsize-size,(st),timeptr);break;
13 #define ADDN(a,b) tmp=strfnumb(s,maxsize-size,(a),(b));break;
15 #define STOR(c) if(++size<=maxsize)*s++=(c);
19 (__localevec[LC_TIME-1]==NULL?strings[(a)-1]:GetLocaleStr(__localevec[LC_TIME-1],(a)))
21 #define STR(a) (strings[(a)-1])
24 /* extern struct Locale *__localevec[]; */
26 /* All calendar strings */
27 static const unsigned char *strings
[]=
30 "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday",
32 "Sun","Mon","Tue","Wed","Thu","Fri","Sat",
34 "January","February","March","April","May","June",
35 "July","August","September","October","November","December",
37 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",
49 static size_t strfnumb(char *s
, size_t maxsize
, signed int places
, size_t value
)
55 size
= strfnumb(s
, maxsize
, places
- 1, value
/ 10);
59 size
= strfnumb(s
, maxsize
, places
+ 1, value
/ 10);
63 while ((places
++ < -1) && (++size
<= maxsize
))
69 if (++size
<= maxsize
) s
[size
- 1] = (value
% 10 + '0');
74 /*****************************************************************************
84 const struct tm
*timeptr
)
102 ******************************************************************************/
104 size_t size
= 0, tmp
;
106 if (format
== NULL
|| timeptr
== NULL
) return 0;
117 ADDS(STR(ABDAY_1
+timeptr
->tm_wday
+1));
120 ADDS(STR(ABMON_1
+timeptr
->tm_mon
+1));
124 ADDN(2,timeptr
->tm_mday
);
126 ADDN(-2,timeptr
->tm_mday
);
128 ADDN(3,timeptr
->tm_yday
+1);
130 ADDN(-2,timeptr
->tm_hour
);
132 ADDN(-2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
134 ADDN(2,timeptr
->tm_mon
+1);
136 ADDS(STR(AM_STR
+(timeptr
->tm_hour
>=12)));
140 ADDN(1,timeptr
->tm_wday
);
142 ADDS("%m/%d/%y %H:%M:%S");
144 ADDN(2,timeptr
->tm_year
%100);
146 ADDS(STR(DAY_1
+timeptr
->tm_wday
+1));
148 ADDS(STR(MON_1
+timeptr
->tm_mon
+1));
150 ADDS("%a %b %e %H:%M:%S %Y");
154 ADDN(2,timeptr
->tm_hour
);
156 ADDN(2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
158 ADDN(2,timeptr
->tm_min
);
162 ADDN(2,timeptr
->tm_sec
);
167 ADDN(2,(timeptr
->tm_yday
+7-timeptr
->tm_wday
)/7);
169 ADDN(2,(timeptr
->tm_yday
+7-(6+timeptr
->tm_wday
)%7)/7);
171 ADDN(4,timeptr
->tm_year
+1900);
203 if (maxsize
) /* Don't know if this is necessary, therefore it's here ;-) */
205 s
[maxsize
- 1] = '\0';