2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
8 TODO: Implement localization support
10 #include <libraries/locale.h>
11 #include <proto/locale.h>
14 #define ADDS(st) tmp=strftime(s,maxsize-size,(st),timeptr);break;
16 #define ADDN(a,b) tmp=strfnumb(s,maxsize-size,(a),(b));break;
18 #define STOR(c) if(++size<=maxsize)*s++=(c);
22 (__localevec[LC_TIME-1]==NULL?strings[(a)-1]:GetLocaleStr(__localevec[LC_TIME-1],(a)))
24 #define STR(a) (strings[(a)-1])
27 /* extern struct Locale *__localevec[]; */
29 /* All calendar strings */
30 static const unsigned char *strings
[]=
33 "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday",
35 "Sun","Mon","Tue","Wed","Thu","Fri","Sat",
37 "January","February","March","April","May","June",
38 "July","August","September","October","November","December",
40 "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",
52 static size_t strfnumb(char *s
, size_t maxsize
, signed int places
, size_t value
)
58 size
= strfnumb(s
, maxsize
, places
- 1, value
/ 10);
62 size
= strfnumb(s
, maxsize
, places
+ 1, value
/ 10);
66 while ((places
++ < -1) && (++size
<= maxsize
))
72 if (++size
<= maxsize
) s
[size
- 1] = (value
% 10 + '0');
77 /*****************************************************************************
87 const struct tm
*timeptr
)
96 Function does not take localization into account at the moment
106 ******************************************************************************/
108 size_t size
= 0, tmp
;
110 if (format
== NULL
|| timeptr
== NULL
) return 0;
121 ADDS(STR(ABDAY_1
+timeptr
->tm_wday
+1));
124 ADDS(STR(ABMON_1
+timeptr
->tm_mon
+1));
128 ADDN(2,timeptr
->tm_mday
);
130 ADDN(-2,timeptr
->tm_mday
);
132 ADDN(3,timeptr
->tm_yday
+1);
134 ADDN(-2,timeptr
->tm_hour
);
136 ADDN(-2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
138 ADDN(2,timeptr
->tm_mon
+1);
140 ADDS(STR(AM_STR
+(timeptr
->tm_hour
>=12)));
144 ADDN(1,timeptr
->tm_wday
);
146 ADDS("%m/%d/%y %H:%M:%S");
148 ADDN(2,timeptr
->tm_year
%100);
150 ADDS(STR(DAY_1
+timeptr
->tm_wday
+1));
152 ADDS(STR(MON_1
+timeptr
->tm_mon
+1));
154 ADDS("%a %b %e %H:%M:%S %Y");
158 ADDN(2,timeptr
->tm_hour
);
160 ADDN(2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
162 ADDN(2,timeptr
->tm_min
);
166 ADDN(2,timeptr
->tm_sec
);
171 ADDN(2,(timeptr
->tm_yday
+7-timeptr
->tm_wday
)/7);
173 ADDN(2,(timeptr
->tm_yday
+7-(6+timeptr
->tm_wday
)%7)/7);
175 ADDN(4,timeptr
->tm_year
+1900);
207 if (maxsize
) /* Don't know if this is necessary, therefore it's here ;-) */
209 s
[maxsize
- 1] = '\0';