2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: LocStrToDate - locale.library's private replacement
6 of dos.library/StrToDate 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>
22 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
23 #define YEAR_FORMAT "%y"
25 #define YEAR_FORMAT "%Y"
32 AROS_UFH3(ULONG
, LocStrToDateGetCharFunc
,
33 AROS_UFHA(struct Hook
*, hook
, A0
),
34 AROS_UFHA(struct Locale
*, locale
, A2
),
35 AROS_UFHA(ULONG
, null
, A1
))
39 STRPTR
*buf
= (STRPTR
*)hook
->h_Data
;
46 /*****************************************************************************
49 #include <proto/locale.h>
51 AROS_PLH1(LONG
, LocStrToDate
,
54 AROS_LHA(struct DateTime
*, datetime
, D1
),
57 struct DosLibrary
*, DOSBase
, 37, Locale
)
60 See dos.library/StrToDate
63 See dos.library/StrToDate
68 This function is not called by apps directly. Instead dos.library/DosGet-
69 LocalizedString is patched to use this function. This means, that the
70 LocaleBase parameter above actually points to DOSBase, so we make use of
71 the global LocaleBase variable. This function is marked as private,
72 thus the headers generator won't mind the different basename in the header.
79 dos.library/StrToDate, locale.library/ParseDate.
85 *****************************************************************************/
95 hook
.h_Entry
= (HOOKFUNC
)AROS_ASMSYMNAME(LocStrToDateGetCharFunc
);
100 loc
= (struct Locale
*)IntLB(LocaleBase
)->lb_CurrentLocale
;
102 if (datetime
->dat_StrDate
)
104 struct DateStamp curr
;
106 buf
= datetime
->dat_StrDate
;
110 if (!strnicmp(buf
, GetLocaleStr(loc
, YESTERDAYSTR
), strlen(GetLocaleStr(loc
, YESTERDAYSTR
))))
112 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
- 1;
114 else if (!strnicmp(buf
, GetLocaleStr(loc
, TODAYSTR
), strlen(GetLocaleStr(loc
, TODAYSTR
))))
116 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
;
118 else if (!strnicmp(buf
, GetLocaleStr(loc
, TOMORROWSTR
), strlen(GetLocaleStr(loc
, TOMORROWSTR
))))
120 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
+ 1;
126 for(i
= 0; i
< 7; i
++)
128 if (!strnicmp(buf
, GetLocaleStr(loc
, DAY_1
+ i
), strlen(GetLocaleStr(loc
, DAY_1
+ i
))))
139 diffdays
= i
- (days
% 7);
141 if (datetime
->dat_Flags
& DTF_FUTURE
)
149 days
+= 7 + diffdays
;
160 days
+= diffdays
- 7;
163 datetime
->dat_Stamp
.ds_Days
= days
;
174 if (datetime
->dat_Flags
& DTF_FUTURE
)
177 datetime
->dat_Stamp
.ds_Days
= days
;
183 switch(datetime
->dat_Format
)
186 fstring
= YEAR_FORMAT
"-%b-%d";
190 fstring
= "%m-%d-" YEAR_FORMAT
;
194 fstring
= "%d-%m-" YEAR_FORMAT
;
198 fstring
= loc
->loc_ShortDateFormat
;
201 default: /* FORMAT_DOS */
202 fstring
= "%d-%b-" YEAR_FORMAT
;
207 if (ParseDate(loc
, &curr
, fstring
, &hook
))
209 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
;
220 } /* if (datetime->dat_StrDate) */
223 if (retval
&& datetime
->dat_StrTime
)
227 buf
= datetime
->dat_StrTime
;
229 switch(datetime
->dat_Format
)
232 fstring
= loc
->loc_ShortTimeFormat
;
236 fstring
= "%H:%M:%S";
240 if (ParseDate(loc
, &ds
, fstring
, &hook
))
242 datetime
->dat_Stamp
.ds_Minute
= ds
.ds_Minute
;
243 datetime
->dat_Stamp
.ds_Tick
= ds
.ds_Tick
;