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
)
122 ADDS(STR(ABDAY_1
+timeptr
->tm_wday
+1));
125 ADDS(STR(ABMON_1
+timeptr
->tm_mon
+1));
129 ADDN(2,timeptr
->tm_mday
);
131 ADDN(-2,timeptr
->tm_mday
);
133 ADDN(3,timeptr
->tm_yday
+1);
135 ADDN(-2,timeptr
->tm_hour
);
137 ADDN(-2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
139 ADDN(2,timeptr
->tm_mon
+1);
141 ADDS(STR(AM_STR
+(timeptr
->tm_hour
>=12)));
145 ADDN(1,timeptr
->tm_wday
);
147 ADDS("%m/%d/%y %H:%M:%S");
149 ADDN(2,timeptr
->tm_year
%100);
151 ADDS(STR(DAY_1
+timeptr
->tm_wday
+1));
153 ADDS(STR(MON_1
+timeptr
->tm_mon
+1));
155 ADDS("%a %b %e %H:%M:%S %Y");
159 ADDN(2,timeptr
->tm_hour
);
161 ADDN(2,timeptr
->tm_hour
%12+(timeptr
->tm_hour
%12==0)*12);
163 ADDN(2,timeptr
->tm_min
);
167 ADDN(2,timeptr
->tm_sec
);
172 ADDN(2,(timeptr
->tm_yday
+7-timeptr
->tm_wday
)/7);
174 ADDN(2,(timeptr
->tm_yday
+7-(6+timeptr
->tm_wday
)%7)/7);
176 ADDN(4,timeptr
->tm_year
+1900);
208 if (maxsize
) /* Don't know if this is necessary, therefore it's here ;-) */
210 s
[maxsize
- 1] = '\0';