2 Copyright © 1995-2011, 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 #define YEAR_FORMAT "%y"
26 AROS_UFH3(void, LocDateToStrPutCharFunc
,
27 AROS_UFHA(struct Hook
*, hook
, A0
),
28 AROS_UFHA(struct Locale
*, locale
, A2
),
29 AROS_UFHA(char, c
, A1
))
33 STRPTR
*buf
= (STRPTR
*)hook
->h_Data
;
40 /*****************************************************************************
43 #include <proto/locale.h>
45 AROS_PLH1(LONG
, LocDateToStr
,
48 AROS_LHA(struct DateTime
*, datetime
, D1
),
51 struct DosLibrary
*, DOSBase
, 36, Locale
)
54 See dos.library/DateToStr
57 See dos.library/DateToStr
62 This function is not called by apps directly. Instead
63 dos.library/DateToStr is patched to use this function. This means,
64 that the LocaleBase parameter above actually points to DOSBase. But
65 it may not be renamed, because then no entry for this function is
66 generated in the Locale functable by the corresponding script.
73 dos.library/DateToStr, locale.library/FormatDate.
77 *****************************************************************************/
87 LONG days
, mins
, tick
;
90 days
= datetime
->dat_Stamp
.ds_Days
;
91 mins
= datetime
->dat_Stamp
.ds_Minute
;
92 tick
= datetime
->dat_Stamp
.ds_Tick
;
95 Check if timestamp is correct. Correct timestamps lie
96 between the 1.1.1978 0:00:00 and the 11.7.5881588 23:59:59.
99 ((ULONG
)mins
>= 24 * 60) ||
100 ((ULONG
)tick
>= TICKS_PER_SECOND
* 60))
105 hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(LocDateToStrPutCharFunc
);
110 loc
= (struct Locale
*)IntLB(LocaleBase
)->lb_CurrentLocale
;
112 if (datetime
->dat_StrDay
)
114 buf
= datetime
->dat_StrDay
;
115 name
= GetLocaleStr(loc
, DAY_1
+ (days
% 7));
117 while((*buf
++ = *name
++) != 0);
120 if (datetime
->dat_StrDate
)
122 buf
= datetime
->dat_StrDate
;
124 switch(datetime
->dat_Format
)
127 fstring
= YEAR_FORMAT
"-%b-%d";
131 fstring
= "%m-%d-" YEAR_FORMAT
;
135 fstring
= "%d-%m-" YEAR_FORMAT
;
139 fstring
= loc
->loc_ShortDateFormat
;
143 fstring
= "%d-%b-" YEAR_FORMAT
;
148 if (datetime
->dat_Flags
& DTF_SUBST
)
150 struct DateStamp curr
;
154 curr
.ds_Days
-= datetime
->dat_Stamp
.ds_Days
;
156 if ((curr
.ds_Days
<= 7))
173 strid
= YESTERDAYSTR
;
177 if (curr
.ds_Days
< -1)
180 strid
= DAY_1
+ (days
% 7);
184 name
= GetLocaleStr(loc
, strid
);
186 while((*buf
++ = *name
++) != 0);
188 } /* if ((curr.ds_Days >= -1) && (cur.ds_Days <= 7)) */
190 } /* if (datetime->dat_Flags & DTF_SUBST) */
194 FormatDate(loc
, fstring
, &datetime
->dat_Stamp
, &hook
);
197 } /* if (datetime->dat_StrDate) */
199 if (datetime
->dat_StrTime
)
201 buf
= datetime
->dat_StrTime
;
203 switch(datetime
->dat_Format
)
206 fstring
= loc
->loc_ShortTimeFormat
;
210 fstring
= "%H:%M:%S";
214 FormatDate(loc
, fstring
, &datetime
->dat_Stamp
, &hook
);