2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
5 Desc: LocDateToStr - locale.library's private replacement
6 of dos.library/DateToStr function. IPrefs will install
12 #include <exec/types.h>
13 #include <dos/datetime.h>
14 #include <proto/exec.h>
15 #include <proto/dos.h>
16 #include <proto/locale.h>
17 #include "locale_intern.h"
18 #include <aros/asmcall.h>
20 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
21 #define YEAR_FORMAT "%y"
23 #define YEAR_FORMAT "%Y"
30 AROS_UFH3(void, LocDateToStrPutCharFunc
,
31 AROS_UFHA(struct Hook
*, hook
, A0
),
32 AROS_UFHA(struct Locale
*, locale
, A2
),
33 AROS_UFHA(char, c
, A1
))
37 STRPTR
*buf
= (STRPTR
*)hook
->h_Data
;
44 /*****************************************************************************
47 #include <proto/locale.h>
49 AROS_PLH1(LONG
, LocDateToStr
,
52 AROS_LHA(struct DateTime
*, datetime
, D1
),
55 struct DosLibrary
*, DOSBase
, 36, Locale
)
58 See dos.library/DateToStr
61 See dos.library/DateToStr
66 This function is not called by apps directly. Instead dos.library/DateToStr
67 is patched to use this function. This means, that the LocaleBase parameter
68 above actually points to DOSBase!!! But I may not rename it, because then
69 no entry for this function is generated in the Locale functable by the
77 dos.library/DateToStr, locale.library/FormatDate.
83 *****************************************************************************/
93 LONG days
, mins
, tick
;
96 days
= datetime
->dat_Stamp
.ds_Days
;
97 mins
= datetime
->dat_Stamp
.ds_Minute
;
98 tick
= datetime
->dat_Stamp
.ds_Tick
;
101 Check if timestamp is correct. Correct timestamps lie
102 between the 1.1.1978 0:00:00 and the 11.7.5881588 23:59:59.
105 ((ULONG
)mins
>= 24 * 60) ||
106 ((ULONG
)tick
>= TICKS_PER_SECOND
* 60))
111 hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(LocDateToStrPutCharFunc
);
116 loc
= (struct Locale
*)IntLB(LocaleBase
)->lb_CurrentLocale
;
118 if (datetime
->dat_StrDay
)
120 buf
= datetime
->dat_StrDay
;
121 name
= GetLocaleStr(loc
, DAY_1
+ (days
% 7));
123 while((*buf
++ = *name
++) != 0)
127 if (datetime
->dat_StrDate
)
129 buf
= datetime
->dat_StrDate
;
131 switch(datetime
->dat_Format
)
134 fstring
= YEAR_FORMAT
"-%b-%d";
138 fstring
= "%m-%d-" YEAR_FORMAT
;
142 fstring
= "%d-%m-" YEAR_FORMAT
;
146 fstring
= loc
->loc_ShortDateFormat
;
150 fstring
= "%d-%b-" YEAR_FORMAT
;
155 if (datetime
->dat_Flags
& DTF_SUBST
)
157 struct DateStamp curr
;
161 curr
.ds_Days
-= datetime
->dat_Stamp
.ds_Days
;
163 if ((curr
.ds_Days
>= -1) && (curr
.ds_Days
<= 7))
180 strid
= YESTERDAYSTR
;
184 strid
= DAY_1
+ (days
% 7);
188 name
= GetLocaleStr(loc
, strid
);
190 while((*buf
++ = *name
++) != 0)
193 } /* if ((curr.ds_Days >= -1) && (cur.ds_Days <= 7)) */
195 } /* if (datetime->dat_Flags & DTF_SUBST) */
199 FormatDate(loc
, fstring
, &datetime
->dat_Stamp
, &hook
);
202 } /* if (datetime->dat_StrDate) */
204 if (datetime
->dat_StrTime
)
206 buf
= datetime
->dat_StrTime
;
208 switch(datetime
->dat_Format
)
211 fstring
= loc
->loc_ShortTimeFormat
;
215 fstring
= "%H:%M:%S";
219 FormatDate(loc
, fstring
, &datetime
->dat_Stamp
, &hook
);