add casts to zune macros to silence some warnings
[tangerine.git] / workbench / libs / locale / locdatetostr.c
blobc06afb3a5361f2d94a42428133230ab87c56459c
1 /*
2 Copyright © 1995-2004, 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 #if (AROS_FLAVOUR & AROS_FLAVOUR_BINCOMPAT)
21 #define YEAR_FORMAT "%y"
22 #else
23 #define YEAR_FORMAT "%Y"
24 #endif
26 #ifndef FORMAT_DEF
27 #define FORMAT_DEF 4
28 #endif
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))
35 AROS_USERFUNC_INIT
37 STRPTR *buf = (STRPTR *)hook->h_Data;
39 *(*buf)++ = c;
41 AROS_USERFUNC_EXIT
44 /*****************************************************************************
46 NAME */
47 #include <proto/locale.h>
49 AROS_PLH1(LONG, LocDateToStr,
51 /* SYNOPSIS */
52 AROS_LHA(struct DateTime *, datetime, D1),
54 /* LOCATION */
55 struct DosLibrary *, DOSBase, 36, Locale)
57 /* FUNCTION
58 See dos.library/DateToStr
60 INPUTS
61 See dos.library/DateToStr
63 RESULT
65 NOTES
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
70 corresponding script!
72 EXAMPLE
74 BUGS
76 SEE ALSO
77 dos.library/DateToStr, locale.library/FormatDate.
79 INTERNALS
81 HISTORY
83 *****************************************************************************/
85 AROS_LIBFUNC_INIT
87 struct Locale *loc;
88 struct Hook hook;
90 STRPTR buf, fstring;
91 const UBYTE * name;
93 LONG days, mins, tick;
95 /* Read time. */
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.
104 if((days < 0) ||
105 ((ULONG)mins >= 24 * 60) ||
106 ((ULONG)tick >= TICKS_PER_SECOND * 60))
108 return DOSFALSE;
111 hook.h_Entry = (HOOKFUNC)AROS_ASMSYMNAME(LocDateToStrPutCharFunc);
112 hook.h_Data = &buf;
114 REPLACEMENT_LOCK;
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)
133 case FORMAT_INT:
134 fstring = YEAR_FORMAT "-%b-%d";
135 break;
137 case FORMAT_USA:
138 fstring = "%m-%d-" YEAR_FORMAT;
139 break;
141 case FORMAT_CDN:
142 fstring = "%d-%m-" YEAR_FORMAT;
143 break;
145 case FORMAT_DEF:
146 fstring = loc->loc_ShortDateFormat;
147 break;
149 default:
150 fstring = "%d-%b-" YEAR_FORMAT;
151 break;
155 if (datetime->dat_Flags & DTF_SUBST)
157 struct DateStamp curr;
159 DateStamp(&curr);
161 curr.ds_Days -= datetime->dat_Stamp.ds_Days;
163 if ((curr.ds_Days >= -1) && (curr.ds_Days <= 7))
165 LONG strid;
167 fstring = "";
169 switch(curr.ds_Days)
171 case -1:
172 strid = TOMORROWSTR;
173 break;
175 case 0:
176 strid = TODAYSTR;
177 break;
179 case 1:
180 strid = YESTERDAYSTR;
181 break;
183 default:
184 strid = DAY_1 + (days % 7);
185 break;
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) */
197 if (*fstring)
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)
210 case FORMAT_DEF:
211 fstring = loc->loc_ShortTimeFormat;
212 break;
214 default:
215 fstring = "%H:%M:%S";
216 break;
219 FormatDate(loc, fstring, &datetime->dat_Stamp, &hook);
222 REPLACEMENT_UNLOCK;
224 return TRUE;
226 AROS_LIBFUNC_EXIT
228 } /* LocDateToStr */