grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / locale / locdatetostr.c
blob2893e4935df50489afbbf41597098c185732985f
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: LocDateToStr - locale.library's private replacement
6 of dos.library/DateToStr function. IPrefs will install
7 the patch.
9 Lang: english
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"
22 #ifndef FORMAT_DEF
23 #define FORMAT_DEF 4
24 #endif
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))
31 AROS_USERFUNC_INIT
33 STRPTR *buf = (STRPTR *)hook->h_Data;
35 *(*buf)++ = c;
37 AROS_USERFUNC_EXIT
40 /*****************************************************************************
42 NAME */
43 #include <proto/locale.h>
45 AROS_PLH1(LONG, LocDateToStr,
47 /* SYNOPSIS */
48 AROS_LHA(struct DateTime *, datetime, D1),
50 /* LOCATION */
51 struct DosLibrary *, DOSBase, 36, Locale)
53 /* FUNCTION
54 See dos.library/DateToStr
56 INPUTS
57 See dos.library/DateToStr
59 RESULT
61 NOTES
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.
68 EXAMPLE
70 BUGS
72 SEE ALSO
73 dos.library/DateToStr, locale.library/FormatDate.
75 INTERNALS
77 *****************************************************************************/
79 AROS_LIBFUNC_INIT
81 struct Locale *loc;
82 struct Hook hook;
84 STRPTR buf, fstring;
85 const UBYTE * name;
87 LONG days, mins, tick;
89 /* Read time. */
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.
98 if((days < 0) ||
99 ((ULONG)mins >= 24 * 60) ||
100 ((ULONG)tick >= TICKS_PER_SECOND * 60))
102 return DOSFALSE;
105 hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocDateToStrPutCharFunc);
106 hook.h_Data = &buf;
108 REPLACEMENT_LOCK;
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)
126 case FORMAT_INT:
127 fstring = YEAR_FORMAT "-%b-%d";
128 break;
130 case FORMAT_USA:
131 fstring = "%m-%d-" YEAR_FORMAT;
132 break;
134 case FORMAT_CDN:
135 fstring = "%d-%m-" YEAR_FORMAT;
136 break;
138 case FORMAT_DEF:
139 fstring = loc->loc_ShortDateFormat;
140 break;
142 default:
143 fstring = "%d-%b-" YEAR_FORMAT;
144 break;
148 if (datetime->dat_Flags & DTF_SUBST)
150 struct DateStamp curr;
152 DateStamp(&curr);
154 curr.ds_Days -= datetime->dat_Stamp.ds_Days;
156 if ((curr.ds_Days <= 7))
158 LONG strid;
160 fstring = "";
162 switch(curr.ds_Days)
164 case -1:
165 strid = TOMORROWSTR;
166 break;
168 case 0:
169 strid = TODAYSTR;
170 break;
172 case 1:
173 strid = YESTERDAYSTR;
174 break;
176 default:
177 if (curr.ds_Days < -1)
178 strid = FUTURESTR;
179 else
180 strid = DAY_1 + (days % 7);
181 break;
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) */
192 if (*fstring)
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)
205 case FORMAT_DEF:
206 fstring = loc->loc_ShortTimeFormat;
207 break;
209 default:
210 fstring = "%H:%M:%S";
211 break;
214 FormatDate(loc, fstring, &datetime->dat_Stamp, &hook);
217 REPLACEMENT_UNLOCK;
219 return TRUE;
221 AROS_LIBFUNC_EXIT
223 } /* LocDateToStr */