2 Copyright © 1995-2011, 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 #define YEAR_FORMAT "%y"
28 static const TEXT long_dos_time_format
[] = "%H:%M:%S";
29 static const TEXT short_dos_time_format
[] = "%H:%M";
31 AROS_UFH3(ULONG
, LocStrToDateGetCharFunc
,
32 AROS_UFHA(struct Hook
*, hook
, A0
),
33 AROS_UFHA(struct Locale
*, locale
, A2
),
34 AROS_UFHA(ULONG
, null
, A1
))
38 STRPTR
*buf
= (STRPTR
*)hook
->h_Data
;
45 /*****************************************************************************
48 #include <proto/locale.h>
50 AROS_PLH1(LONG
, LocStrToDate
,
53 AROS_LHA(struct DateTime
*, datetime
, D1
),
56 struct DosLibrary
*, DOSBase
, 37, Locale
)
59 See dos.library/StrToDate
62 See dos.library/StrToDate
67 This function is not called by apps directly. Instead
68 dos.library/StrToDate() is patched to use this function. This means
69 that the LocaleBase parameter above actually points to DOSBase, so we
70 make use of the global LocaleBase variable. This function is marked as
71 private, thus the headers generator won't mind the different basename
79 dos.library/StrToDate, locale.library/ParseDate.
83 *****************************************************************************/
89 CONST_STRPTR buf
, fstring
, altfstring
;
93 hook
.h_Entry
= (HOOKFUNC
) AROS_ASMSYMNAME(LocStrToDateGetCharFunc
);
98 loc
= (struct Locale
*)IntLB(LocaleBase
)->lb_CurrentLocale
;
100 if (datetime
->dat_StrDate
)
102 struct DateStamp curr
;
104 buf
= datetime
->dat_StrDate
;
108 if (!stricmp(buf
, GetLocaleStr(loc
, YESTERDAYSTR
)))
110 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
- 1;
112 else if (!stricmp(buf
, GetLocaleStr(loc
, TODAYSTR
)))
114 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
;
116 else if (!stricmp(buf
, GetLocaleStr(loc
, TOMORROWSTR
)))
118 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
+ 1;
124 for (i
= 0; i
< 7; i
++)
126 if (!stricmp(buf
, GetLocaleStr(loc
, DAY_1
+ i
)))
137 diffdays
= i
- (days
% 7);
139 if (datetime
->dat_Flags
& DTF_FUTURE
)
147 days
+= 7 + diffdays
;
158 days
+= diffdays
- 7;
161 datetime
->dat_Stamp
.ds_Days
= days
;
172 if (datetime
->dat_Flags
& DTF_FUTURE
)
175 datetime
->dat_Stamp
.ds_Days
= days
;
181 switch (datetime
->dat_Format
)
184 fstring
= YEAR_FORMAT
"-%b-%d";
185 altfstring
= YEAR_FORMAT
"-%m-%d";
189 altfstring
= fstring
= "%m-%d-" YEAR_FORMAT
;
193 altfstring
= fstring
= "%d-%m-" YEAR_FORMAT
;
197 altfstring
= fstring
= loc
->loc_ShortDateFormat
;
200 default: /* FORMAT_DOS */
201 fstring
= "%d-%b-" YEAR_FORMAT
;
202 altfstring
= "%d-%m-" YEAR_FORMAT
;
207 if (ParseDate(loc
, &curr
, fstring
, &hook
))
209 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
;
213 buf
= datetime
->dat_StrDate
;
214 if (ParseDate(loc
, &curr
, altfstring
, &hook
))
216 datetime
->dat_Stamp
.ds_Days
= curr
.ds_Days
;
230 if (retval
&& datetime
->dat_StrTime
)
234 buf
= datetime
->dat_StrTime
;
236 switch (datetime
->dat_Format
)
239 fstring
= loc
->loc_ShortTimeFormat
;
243 if (ParseDate(loc
, NULL
, long_dos_time_format
, &hook
))
244 fstring
= long_dos_time_format
;
246 fstring
= short_dos_time_format
;
247 buf
= datetime
->dat_StrTime
;
251 if (ParseDate(loc
, &ds
, fstring
, &hook
))
253 datetime
->dat_Stamp
.ds_Minute
= ds
.ds_Minute
;
254 datetime
->dat_Stamp
.ds_Tick
= ds
.ds_Tick
;