1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4 * Copyright (c) 2016, International Business Machines Corporation
5 * and others. All Rights Reserved.
6 ********************************************************************/
7 /* C API TEST FOR DATE INTERVAL FORMAT */
9 #include "unicode/utypes.h"
11 #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION
13 #include "unicode/ureldatefmt.h"
14 #include "unicode/unum.h"
15 #include "unicode/udisplaycontext.h"
16 #include "unicode/ustring.h"
21 static void TestRelDateFmt(void);
22 static void TestNumericField(void);
23 static void TestCombineDateTime(void);
24 static void TestFields(void);
26 void addRelativeDateFormatTest(TestNode
** root
);
28 #define TESTCASE(x) addTest(root, &x, "tsformat/crelativedateformattest/" #x)
30 void addRelativeDateFormatTest(TestNode
** root
)
32 TESTCASE(TestRelDateFmt
);
33 TESTCASE(TestNumericField
);
34 TESTCASE(TestCombineDateTime
);
38 static const double offsets
[] = { -5.0, -2.2, -2.0, -1.0, -0.7, -0.0, 0.0, 0.7, 1.0, 2.0, 5.0 };
39 enum { kNumOffsets
= UPRV_LENGTHOF(offsets
) };
47 static const char* en_decDef_long_midSent_sec
[kNumOffsets
*2] = {
49 "5 seconds ago", "5 seconds ago", /* -5 */
50 "2.2 seconds ago", "2.2 seconds ago", /* -2.2 */
51 "2 seconds ago", "2 seconds ago", /* -2 */
52 "1 second ago", "1 second ago", /* -1 */
53 "0.7 seconds ago", "0.7 seconds ago", /* -0.7 */
54 "now", "0 seconds ago", /* -0 */
55 "now", "in 0 seconds", /* 0 */
56 "in 0.7 seconds", "in 0.7 seconds", /* 0.7 */
57 "in 1 second", "in 1 second", /* 1 */
58 "in 2 seconds", "in 2 seconds", /* 2 */
59 "in 5 seconds", "in 5 seconds" /* 5 */
62 static const FieldsDat en_attrDef_long_midSent_sec
[kNumOffsets
*2] = {
63 /* text numeric text numeric */
64 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 seconds ago", "5 seconds ago", -5 */
65 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "2.2 seconds ago", "2.2 seconds ago", -2.2 */
66 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 seconds ago", "2 seconds ago", -2 */
67 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "1 second ago", "1 second ago", -1 */
68 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "0.7 seconds ago", "0.7 seconds ago", -0.7 */
69 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "now", "0 seconds ago", -0 */
70 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "now", "in 0 seconds", 0 */
71 {UDAT_REL_NUMERIC_FIELD
, 3, 6}, {UDAT_REL_NUMERIC_FIELD
, 3, 6}, /* "in 0.7 seconds", "in 0.7 seconds", 0.7 */
72 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 1 second", "in 1 second", 1 */
73 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 seconds", "in 2 seconds", 2 */
74 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 seconds", "in 5 seconds" 5 */
77 static const char* en_decDef_long_midSent_week
[kNumOffsets
*2] = {
79 "5 weeks ago", "5 weeks ago", /* -5 */
80 "2.2 weeks ago", "2.2 weeks ago", /* -2.2 */
81 "2 weeks ago", "2 weeks ago", /* -2 */
82 "last week", "1 week ago", /* -1 */
83 "0.7 weeks ago", "0.7 weeks ago", /* -0.7 */
84 "this week", "0 weeks ago", /* -0 */
85 "this week", "in 0 weeks", /* 0 */
86 "in 0.7 weeks", "in 0.7 weeks", /* 0.7 */
87 "next week", "in 1 week", /* 1 */
88 "in 2 weeks", "in 2 weeks", /* 2 */
89 "in 5 weeks", "in 5 weeks" /* 5 */
92 static const FieldsDat en_attrDef_long_midSent_week
[kNumOffsets
*2] = {
93 /* text numeric text numeric */
94 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 weeks ago", "5 weeks ago", -5 */
95 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "2.2 weeks ago", "2.2 weeks ago", -2.2 */
96 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 weeks ago", "2 weeks ago", -2 */
97 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "last week", "1 week ago", -1 */
98 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "0.7 weeks ago", "0.7 weeks ago", -0.7 */
99 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "this week", "0 weeks ago", -0 */
100 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "this week", "in 0 weeks", 0 */
101 {UDAT_REL_NUMERIC_FIELD
, 3, 6}, {UDAT_REL_NUMERIC_FIELD
, 3, 6}, /* "in 0.7 weeks", "in 0.7 weeks", 0.7 */
102 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "next week", "in 1 week", 1 */
103 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 weeks", "in 2 weeks", 2 */
104 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 weeks", "in 5 weeks" 5 */
107 static const char* en_dec0_long_midSent_week
[kNumOffsets
*2] = {
109 "5 weeks ago", "5 weeks ago", /* -5 */
110 "2 weeks ago", "2 weeks ago", /* -2.2 */
111 "2 weeks ago", "2 weeks ago", /* -2 */
112 "last week", "1 week ago", /* -1 */
113 "0 weeks ago", "0 weeks ago", /* -0.7 */
114 "this week", "0 weeks ago", /* -0 */
115 "this week", "in 0 weeks", /* 0 */
116 "in 0 weeks", "in 0 weeks", /* 0.7 */
117 "next week", "in 1 week", /* 1 */
118 "in 2 weeks", "in 2 weeks", /* 2 */
119 "in 5 weeks", "in 5 weeks" /* 5 */
122 static const FieldsDat en_attr0_long_midSent_week
[kNumOffsets
*2] = {
123 /* text numeric text numeric */
124 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 weeks ago", "5 weeks ago", -5 */
125 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 weeks ago", "2 weeks ago", -2.2 */
126 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 weeks ago", "2 weeks ago", -2 */
127 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "last week", "1 week ago", -1 */
128 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "0 weeks ago", "0 weeks ago", -0.7 */
129 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "this week", "0 weeks ago", -0 */
130 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "this week", "in 0 weeks", 0 */
131 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 0 weeks", "in 0 weeks", 0.7 */
132 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "next week", "in 1 week", 1 */
133 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 weeks", "in 2 weeks", 2 */
134 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 weeks", "in 5 weeks" 5 */
137 static const char* en_decDef_short_midSent_week
[kNumOffsets
*2] = {
139 "5 wk. ago", "5 wk. ago", /* -5 */
140 "2.2 wk. ago", "2.2 wk. ago", /* -2.2 */
141 "2 wk. ago", "2 wk. ago", /* -2 */
142 "last wk.", "1 wk. ago", /* -1 */
143 "0.7 wk. ago", "0.7 wk. ago", /* -0.7 */
144 "this wk.", "0 wk. ago", /* -0 */
145 "this wk.", "in 0 wk.", /* 0 */
146 "in 0.7 wk.", "in 0.7 wk.", /* 0.7 */
147 "next wk.", "in 1 wk.", /* 1 */
148 "in 2 wk.", "in 2 wk.", /* 2 */
149 "in 5 wk.", "in 5 wk." /* 5 */
152 static const FieldsDat en_attrDef_short_midSent_week
[kNumOffsets
*2] = {
153 /* text numeric text numeric */
154 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 wk. ago", "5 wk. ago", -5 */
155 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "2.2 wk. ago", "2.2 wk. ago", -2.2 */
156 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 wk. ago", "2 wk. ago", -2 */
157 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "last wk.", "1 wk. ago", -1 */
158 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "0.7 wk. ago", "0.7 wk. ago", -0.7 */
159 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "this wk.", "0 wk. ago", -0 */
160 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "this wk.", "in 0 wk.", 0 */
161 {UDAT_REL_NUMERIC_FIELD
, 3, 6}, {UDAT_REL_NUMERIC_FIELD
, 3, 6}, /* "in 0.7 wk.", "in 0.7 wk.", 0.7 */
162 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "next wk.", "in 1 wk.", 1 */
163 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 wk.", "in 2 wk.", 2 */
164 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 wk.", "in 5 wk." 5 */
167 static const char* en_decDef_long_midSent_min
[kNumOffsets
*2] = {
169 "5 minutes ago", "5 minutes ago", /* -5 */
170 "2.2 minutes ago", "2.2 minutes ago", /* -2.2 */
171 "2 minutes ago", "2 minutes ago", /* -2 */
172 "1 minute ago", "1 minute ago", /* -1 */
173 "0.7 minutes ago", "0.7 minutes ago", /* -0.7 */
174 "0 minutes ago", "0 minutes ago", /* -0 */
175 "in 0 minutes", "in 0 minutes", /* 0 */
176 "in 0.7 minutes", "in 0.7 minutes", /* 0.7 */
177 "in 1 minute", "in 1 minute", /* 1 */
178 "in 2 minutes", "in 2 minutes", /* 2 */
179 "in 5 minutes", "in 5 minutes" /* 5 */
182 static const FieldsDat en_attrDef_long_midSent_min
[kNumOffsets
*2] = {
183 /* text numeric text numeric */
184 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 minutes ago", "5 minutes ago", -5 */
185 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "2.2 minutes ago", "2.2 minutes ago", -2.2 */
186 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 minutes ago", "2 minutes ago", -2 */
187 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "1 minute ago", "1 minute ago", -1 */
188 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3}, /* "0.7 minutes ago", "0.7 minutes ago", -0.7 */
189 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "0 minutes ago", "0 minutes ago", -0 */
190 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 0 minutes", "in 0 minutes", 0 */
191 {UDAT_REL_NUMERIC_FIELD
, 3, 6}, {UDAT_REL_NUMERIC_FIELD
, 3, 6}, /* "in 0.7 minutes", "in 0.7 minutes", 0.7 */
192 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 1 minute", "in 1 minute", 1 */
193 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 minutes", "in 2 minutes", 2 */
194 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 minutes", "in 5 minutes" 5 */
197 static const char* en_dec0_long_midSent_tues
[kNumOffsets
*2] = {
199 "5 Tuesdays ago", "5 Tuesdays ago", /* -5 */
200 ""/*no data */, ""/*no data */, /* -2.2 */
201 "2 Tuesdays ago", "2 Tuesdays ago", /* -2 */
202 "last Tuesday", "1 Tuesday ago", /* -1 */
203 ""/*no data */, ""/*no data */, /* -0.7 */
204 "this Tuesday", "0 Tuesdays ago", /* -0 */
205 "this Tuesday", "in 0 Tuesdays", /* 0 */
206 ""/*no data */, ""/*no data */, /* 0.7 */
207 "next Tuesday", "in 1 Tuesday", /* 1 */
208 "in 2 Tuesdays", "in 2 Tuesdays", /* 2 */
209 "in 5 Tuesdays", "in 5 Tuesdays", /* 5 */
212 static const FieldsDat en_attr0_long_midSent_tues
[kNumOffsets
*2] = {
213 /* text numeric text numeric */
214 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "5 Tuesdays ago", "5 Tuesdays ago", -5 */
215 { -1, -1, -1}, { -1, -1, -1}, /* "" , "" , -2.2 */
216 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "2 Tuesdays ago", "2 Tuesdays ago", -2 */
217 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "last Tuesday", "1 Tuesday ago", -1 */
218 { -1, -1, -1}, { -1, -1, -1}, /* "" , "" , -0.7 */
219 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1}, /* "this Tuesday", "0 Tuesdays ago", -0 */
220 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "this Tuesday", "in 0 Tuesdays", 0 */
221 { -1, -1, -1}, { -1, -1, -1}, /* "" , "" , 0.7 */
222 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "next Tuesday", "in 1 Tuesday", 1 */
223 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 2 Tuesdays", "in 2 Tuesdays", 2 */
224 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4}, /* "in 5 Tuesdays", "in 5 Tuesdays", 5 */
227 static const char* fr_decDef_long_midSent_day
[kNumOffsets
*2] = {
229 "il y a 5 jours", "il y a 5 jours", /* -5 */
230 "il y a 2,2 jours", "il y a 2,2 jours", /* -2.2 */
231 "avant-hier", "il y a 2 jours", /* -2 */
232 "hier", "il y a 1 jour", /* -1 */
233 "il y a 0,7 jour", "il y a 0,7 jour", /* -0.7 */
234 "aujourd\\u2019hui", "il y a 0 jour", /* -0 */
235 "aujourd\\u2019hui", "dans 0 jour", /* 0 */
236 "dans 0,7 jour", "dans 0,7 jour", /* 0.7 */
237 "demain", "dans 1 jour", /* 1 */
238 "apr\\u00E8s-demain", "dans 2 jours", /* 2 */
239 "dans 5 jours", "dans 5 jours" /* 5 */
242 static const FieldsDat fr_attrDef_long_midSent_day
[kNumOffsets
*2] = {
243 /* text numeric text numeric */
244 {UDAT_REL_NUMERIC_FIELD
, 7, 8}, {UDAT_REL_NUMERIC_FIELD
, 7, 8}, /* "il y a 5 jours", "il y a 5 jours", -5 */
245 {UDAT_REL_NUMERIC_FIELD
, 7, 10}, {UDAT_REL_NUMERIC_FIELD
, 7, 10}, /* "il y a 2,2 jours", "il y a 2,2 jours", -2.2 */
246 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 7, 8}, /* "avant-hier", "il y a 2 jours", -2 */
247 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 7, 8}, /* "hier", "il y a 1 jour", -1 */
248 {UDAT_REL_NUMERIC_FIELD
, 7, 10}, {UDAT_REL_NUMERIC_FIELD
, 7, 10}, /* "il y a 0,7 jour", "il y a 0,7 jour", -0.7 */
249 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 7, 8}, /* "aujourd\\u2019hui", "il y a 0 jour", -0 */
250 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 5, 6}, /* "aujourd\\u2019hui", "dans 0 jour", 0 */
251 {UDAT_REL_NUMERIC_FIELD
, 5, 8}, {UDAT_REL_NUMERIC_FIELD
, 5, 8}, /* "dans 0,7 jour", "dans 0,7 jour", 0.7 */
252 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 5, 6}, /* "demain", "dans 1 jour", 1 */
253 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 5, 6}, /* "apr\\u00E8s-demain", "dans 2 jours", 2 */
254 {UDAT_REL_NUMERIC_FIELD
, 5, 6}, {UDAT_REL_NUMERIC_FIELD
, 5, 6}, /* "dans 5 jours", "dans 5 jours" 5 */
257 static const char* ak_decDef_long_stdAlon_sec
[kNumOffsets
*2] = { // falls back to root
259 "-5 s", "-5 s", /* -5 */
260 "-2.2 s", "-2.2 s", /* -2.2 */
261 "-2 s", "-2 s", /* -2 */
262 "-1 s", "-1 s", /* -1 */
263 "-0.7 s", "-0.7 s", /* -0.7 */
264 "now", "-0 s", /* -0 */
265 "now", "+0 s", /* 0 */
266 "+0.7 s", "+0.7 s", /* 0.7 */
267 "+1 s", "+1 s", /* 1 */
268 "+2 s", "+2 s", /* 2 */
269 "+5 s", "+5 s", /* 5 */
272 static const FieldsDat ak_attrDef_long_stdAlon_sec
[kNumOffsets
*2] = {
273 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
274 {UDAT_REL_NUMERIC_FIELD
, 1, 4}, {UDAT_REL_NUMERIC_FIELD
, 1, 4},
275 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
276 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
277 {UDAT_REL_NUMERIC_FIELD
, 1, 4}, {UDAT_REL_NUMERIC_FIELD
, 1, 4},
278 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
279 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
280 {UDAT_REL_NUMERIC_FIELD
, 1, 4}, {UDAT_REL_NUMERIC_FIELD
, 1, 4},
281 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
282 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
283 {UDAT_REL_NUMERIC_FIELD
, 1, 2}, {UDAT_REL_NUMERIC_FIELD
, 1, 2},
286 static const char* enIN_decDef_short_midSent_weds
[kNumOffsets
*2] = {
288 "5 Wed. ago", "5 Wed. ago", /* -5 */
289 "2.2 Wed. ago", "2.2 Wed. ago", /* -2.2 */
290 "2 Wed. ago", "2 Wed. ago", /* -2 */
291 "last Wed", "1 Wed. ago", /* -1 */
292 "0.7 Wed. ago", "0.7 Wed. ago", /* -0.7 */
293 "this Wed", "0 Wed. ago", /* -0 */
294 "this Wed", "in 0 Wed.", /* 0 */
295 "in 0.7 Wed.", "in 0.7 Wed.", /* 0.7 */
296 "next Wed", "in 1 Wed", /* 1 */ // in 1 Wed. missing in logical group
297 "in 2 Wed.", "in 2 Wed.", /* 2 */
298 "in 5 Wed.", "in 5 Wed." /* 5 */
301 static const FieldsDat enIN_attrDef_short_midSent_weds
[kNumOffsets
*2] = {
302 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1},
303 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3},
304 {UDAT_REL_NUMERIC_FIELD
, 0, 1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1},
305 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1},
306 {UDAT_REL_NUMERIC_FIELD
, 0, 3}, {UDAT_REL_NUMERIC_FIELD
, 0, 3},
307 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 0, 1},
308 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4},
309 {UDAT_REL_NUMERIC_FIELD
, 3, 6}, {UDAT_REL_NUMERIC_FIELD
, 3, 6},
310 { -1, -1, -1}, {UDAT_REL_NUMERIC_FIELD
, 3, 4},
311 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4},
312 {UDAT_REL_NUMERIC_FIELD
, 3, 4}, {UDAT_REL_NUMERIC_FIELD
, 3, 4},
315 static const char* nb_decDef_long_midSent_day
[kNumOffsets
*2] = {
317 "for 5 dager siden", "for 5 dager siden", /* -5 */
318 "for 2,2 dager siden", "for 2,2 dager siden", /* -2.2 */
319 "i forg\\u00E5rs", "for 2 dager siden", /* -2 */
320 "i g\\u00E5r", "for 1 dag siden", /* -1 */
321 "for 0,7 dager siden", "for 0,7 dager siden", /* -0.7 */
322 "i dag", "for 0 dager siden", /* -0 */
323 "i dag", "om 0 dager", /* 0 */
324 "om 0,7 dager", "om 0,7 dager", /* 0.7 */
325 "i morgen", "om 1 dag", /* 1 */
326 "i overmorgen", "om 2 dager", /* 2 */
327 "om 5 dager", "om 5 dager" /* 5 */
330 // Need attrDef for nb
335 int32_t decPlaces
; /* fixed decimal places; -1 to use default num formatter */
336 UDateRelativeDateTimeFormatterStyle width
;
337 UDisplayContext capContext
;
338 URelativeDateTimeUnit unit
;
339 const char ** expectedResults
; /* for the various offsets */
340 const FieldsDat
* expectedAttributes
;
341 } RelDateTimeFormatTestItem
;
343 static const RelDateTimeFormatTestItem fmtTestItems
[] = {
344 { "en", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_SECOND
,
345 en_decDef_long_midSent_sec
, en_attrDef_long_midSent_sec
},
346 { "en", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_WEEK
,
347 en_decDef_long_midSent_week
, en_attrDef_long_midSent_week
},
348 { "en", 0, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_WEEK
,
349 en_dec0_long_midSent_week
, en_attr0_long_midSent_week
},
350 { "en", -1, UDAT_STYLE_SHORT
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_WEEK
,
351 en_decDef_short_midSent_week
, en_attrDef_short_midSent_week
},
352 { "en", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_MINUTE
,
353 en_decDef_long_midSent_min
, en_attrDef_long_midSent_min
},
354 { "en", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_TUESDAY
,
355 en_dec0_long_midSent_tues
, en_attr0_long_midSent_tues
},
356 { "fr", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_DAY
,
357 fr_decDef_long_midSent_day
, fr_attrDef_long_midSent_day
},
358 { "ak", -1, UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_STANDALONE
, UDAT_REL_UNIT_SECOND
,
359 ak_decDef_long_stdAlon_sec
, ak_attrDef_long_stdAlon_sec
},
360 { "en_IN", -1, UDAT_STYLE_SHORT
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, UDAT_REL_UNIT_WEDNESDAY
,
361 enIN_decDef_short_midSent_weds
, enIN_attrDef_short_midSent_weds
},
362 //add suitable entry for nb
363 //{ "nb", -1, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_DAY, nb_decDef_long_midSent_day ...
364 { NULL
, 0, (UDateRelativeDateTimeFormatterStyle
)0, (UDisplayContext
)0, (URelativeDateTimeUnit
)0, NULL
, NULL
} /* terminator */
367 enum { kUBufMax
= 64, kBBufMax
= 256 };
369 static void TestRelDateFmt()
371 const RelDateTimeFormatTestItem
*itemPtr
;
372 log_verbose("\nTesting ureldatefmt_open(), ureldatefmt_format(), ureldatefmt_formatNumeric() with various parameters\n");
373 for (itemPtr
= fmtTestItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
374 URelativeDateTimeFormatter
*reldatefmt
= NULL
;
375 UNumberFormat
* nfToAdopt
= NULL
;
376 UErrorCode status
= U_ZERO_ERROR
;
379 if (itemPtr
->decPlaces
>= 0) {
380 nfToAdopt
= unum_open(UNUM_DECIMAL
, NULL
, 0, itemPtr
->locale
, NULL
, &status
);
381 if ( U_FAILURE(status
) ) {
382 log_data_err("FAIL: unum_open(UNUM_DECIMAL, ...) for locale %s: %s\n", itemPtr
->locale
, myErrorName(status
));
385 unum_setAttribute(nfToAdopt
, UNUM_MIN_FRACTION_DIGITS
, itemPtr
->decPlaces
);
386 unum_setAttribute(nfToAdopt
, UNUM_MAX_FRACTION_DIGITS
, itemPtr
->decPlaces
);
387 unum_setAttribute(nfToAdopt
, UNUM_ROUNDING_MODE
, UNUM_ROUND_DOWN
);
389 reldatefmt
= ureldatefmt_open(itemPtr
->locale
, nfToAdopt
, itemPtr
->width
, itemPtr
->capContext
, &status
);
390 if ( U_FAILURE(status
) ) {
391 log_data_err("FAIL: ureldatefmt_open() for locale %s, decPlaces %d, width %d, capContext %d: %s\n",
392 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
393 myErrorName(status
) );
397 for (iOffset
= 0; iOffset
< kNumOffsets
; iOffset
++) {
398 UChar ubufget
[kUBufMax
];
401 if (itemPtr
->unit
>= UDAT_REL_UNIT_SUNDAY
&& offsets
[iOffset
] != -1.0 && offsets
[iOffset
] != 0.0 && offsets
[iOffset
] != 1.0) {
402 continue; /* we do not currently have data for this */
405 status
= U_ZERO_ERROR
;
406 ulenget
= ureldatefmt_format(reldatefmt
, offsets
[iOffset
], itemPtr
->unit
, ubufget
, kUBufMax
, &status
);
407 if ( U_FAILURE(status
) ) {
408 log_err("FAIL: ureldatefmt_format() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d: %s\n",
409 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
410 offsets
[iOffset
], (int)itemPtr
->unit
, myErrorName(status
) );
412 UChar ubufexp
[kUBufMax
];
413 int32_t ulenexp
= u_unescape(itemPtr
->expectedResults
[iOffset
*2], ubufexp
, kUBufMax
);
414 if (ulenget
!= ulenexp
|| u_strncmp(ubufget
, ubufexp
, ulenexp
) != 0) {
415 char bbufget
[kBBufMax
];
416 u_austrncpy(bbufget
, ubufget
, kUBufMax
);
417 log_err("ERROR: ureldatefmt_format() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d;\n expected %s\n get %s\n",
418 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
419 offsets
[iOffset
], (int)itemPtr
->unit
, itemPtr
->expectedResults
[iOffset
*2], bbufget
);
423 if (itemPtr
->unit
>= UDAT_REL_UNIT_SUNDAY
) {
424 continue; /* we do not currently have numeric-style data for this */
427 status
= U_ZERO_ERROR
;
428 ulenget
= ureldatefmt_formatNumeric(reldatefmt
, offsets
[iOffset
], itemPtr
->unit
, ubufget
, kUBufMax
, &status
);
429 if ( U_FAILURE(status
) ) {
430 log_err("FAIL: ureldatefmt_formatNumeric() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d: %s\n",
431 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
432 offsets
[iOffset
], (int)itemPtr
->unit
, myErrorName(status
) );
434 UChar ubufexp
[kUBufMax
];
435 int32_t ulenexp
= u_unescape(itemPtr
->expectedResults
[iOffset
*2 + 1], ubufexp
, kUBufMax
);
436 if (ulenget
!= ulenexp
|| u_strncmp(ubufget
, ubufexp
, ulenexp
) != 0) {
437 char bbufget
[kBBufMax
];
438 u_austrncpy(bbufget
, ubufget
, kUBufMax
);
439 log_err("ERROR: ureldatefmt_formatNumeric() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d;\n expected %s\n get %s\n",
440 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
441 offsets
[iOffset
], (int)itemPtr
->unit
, itemPtr
->expectedResults
[iOffset
*2 + 1], bbufget
);
446 ureldatefmt_close(reldatefmt
);
450 static void TestNumericField()
452 const RelDateTimeFormatTestItem
*itemPtr
;
453 log_verbose("\nTesting ureldatefmt_open(), ureldatefmt_formatForFields(), ureldatefmt_formatNumericForFields() with various parameters\n");
454 for (itemPtr
= fmtTestItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
455 URelativeDateTimeFormatter
*reldatefmt
= NULL
;
456 UNumberFormat
* nfToAdopt
= NULL
;
457 UErrorCode status
= U_ZERO_ERROR
;
460 if (itemPtr
->decPlaces
>= 0) {
461 nfToAdopt
= unum_open(UNUM_DECIMAL
, NULL
, 0, itemPtr
->locale
, NULL
, &status
);
462 if ( U_FAILURE(status
) ) {
463 log_data_err("FAIL: unum_open(UNUM_DECIMAL, ...) for locale %s: %s\n", itemPtr
->locale
, myErrorName(status
));
466 unum_setAttribute(nfToAdopt
, UNUM_MIN_FRACTION_DIGITS
, itemPtr
->decPlaces
);
467 unum_setAttribute(nfToAdopt
, UNUM_MAX_FRACTION_DIGITS
, itemPtr
->decPlaces
);
468 unum_setAttribute(nfToAdopt
, UNUM_ROUNDING_MODE
, UNUM_ROUND_DOWN
);
470 reldatefmt
= ureldatefmt_open(itemPtr
->locale
, nfToAdopt
, itemPtr
->width
, itemPtr
->capContext
, &status
);
471 if ( U_FAILURE(status
) ) {
472 log_data_err("FAIL: ureldatefmt_open() for locale %s, decPlaces %d, width %d, capContext %d: %s\n",
473 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
474 myErrorName(status
) );
478 for (iOffset
= 0; iOffset
< kNumOffsets
; iOffset
++) {
479 if (itemPtr
->unit
>= UDAT_REL_UNIT_SUNDAY
&& offsets
[iOffset
] != -1.0 && offsets
[iOffset
] != 0.0 && offsets
[iOffset
] != 1.0) {
480 continue; /* we do not currently have data for this */
483 /* Depend on the next one to verify the data */
484 status
= U_ZERO_ERROR
;
485 UFormattedRelativeDateTime
* fv
= ureldatefmt_openResult(&status
);
486 if ( U_FAILURE(status
) ) {
487 log_err("ureldatefmt_openResult fails, status %s\n", u_errorName(status
));
490 ureldatefmt_formatToResult(reldatefmt
, offsets
[iOffset
], itemPtr
->unit
, fv
, &status
);
491 if ( U_FAILURE(status
) ) {
492 log_err("FAIL: ureldatefmt_formatForFields() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d: %s\n",
493 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
494 offsets
[iOffset
], (int)itemPtr
->unit
, myErrorName(status
) );
496 UChar ubufexp
[kUBufMax
];
497 int32_t ulenexp
= u_unescape(itemPtr
->expectedResults
[iOffset
*2], ubufexp
, kUBufMax
);
499 const UChar
* ubufget
= ufmtval_getString(ureldatefmt_resultAsValue(fv
, &status
), &ulenget
, &status
);
500 assertUEquals("String content", ubufexp
, ubufget
);
501 assertIntEquals("String length", ulenexp
, ulenget
);
503 FieldsDat expectedAttr
= itemPtr
->expectedAttributes
[iOffset
*2];
504 UConstrainedFieldPosition
* cfpos
= ucfpos_open(&status
);
505 UBool foundNumeric
= FALSE
;
507 foundNumeric
= ufmtval_nextPosition(ureldatefmt_resultAsValue(fv
, &status
), cfpos
, &status
);
511 if (ucfpos_getCategory(cfpos
, &status
) == UFIELD_CATEGORY_RELATIVE_DATETIME
512 && ucfpos_getField(cfpos
, &status
) == UDAT_REL_NUMERIC_FIELD
) {
516 assertSuccess("Looking for numeric", &status
);
517 int32_t beginPos
, endPos
;
518 ucfpos_getIndexes(cfpos
, &beginPos
, &endPos
, &status
);
519 if (expectedAttr
.field
== -1) {
521 log_err("ureldatefmt_formatForFields as \"%s\"; expect no field, but got %d\n",
522 itemPtr
->expectedResults
[iOffset
*2],
523 ucfpos_getField(cfpos
, &status
));
527 beginPos
!= expectedAttr
.beginPos
||
528 endPos
!= expectedAttr
.endPos
) {
529 log_err("ureldatefmt_formatForFields as \"%s\"; expect field %d range %d-%d, get range %d-%d\n",
530 itemPtr
->expectedResults
[iOffset
*2],
531 expectedAttr
.field
, expectedAttr
.beginPos
, expectedAttr
.endPos
,
538 if (itemPtr
->unit
>= UDAT_REL_UNIT_SUNDAY
) {
539 ureldatefmt_closeResult(fv
);
540 continue; /* we do not currently have numeric-style data for this */
543 /* Depend on the next one to verify the data */
544 status
= U_ZERO_ERROR
;
545 ureldatefmt_formatNumericToResult(reldatefmt
, offsets
[iOffset
], itemPtr
->unit
, fv
, &status
);
546 if ( U_FAILURE(status
) ) {
547 log_err("FAIL: ureldatefmt_formatNumericForFields() for locale %s, decPlaces %d, width %d, capContext %d, offset %.2f, unit %d: %s\n",
548 itemPtr
->locale
, itemPtr
->decPlaces
, (int)itemPtr
->width
, (int)itemPtr
->capContext
,
549 offsets
[iOffset
], (int)itemPtr
->unit
, myErrorName(status
) );
551 UChar ubufexp
[kUBufMax
];
552 int32_t ulenexp
= u_unescape(itemPtr
->expectedResults
[iOffset
*2 + 1], ubufexp
, kUBufMax
);
554 const UChar
* ubufget
= ufmtval_getString(ureldatefmt_resultAsValue(fv
, &status
), &ulenget
, &status
);
555 assertUEquals("String content", ubufexp
, ubufget
);
556 assertIntEquals("String length", ulenexp
, ulenget
);
558 FieldsDat expectedAttr
= itemPtr
->expectedAttributes
[iOffset
*2 + 1];
559 UConstrainedFieldPosition
* cfpos
= ucfpos_open(&status
);
560 UBool foundNumeric
= FALSE
;
562 foundNumeric
= ufmtval_nextPosition(ureldatefmt_resultAsValue(fv
, &status
), cfpos
, &status
);
566 if (ucfpos_getCategory(cfpos
, &status
) == UFIELD_CATEGORY_RELATIVE_DATETIME
567 && ucfpos_getField(cfpos
, &status
) == UDAT_REL_NUMERIC_FIELD
) {
571 assertSuccess("Looking for numeric", &status
);
572 int32_t beginPos
, endPos
;
573 ucfpos_getIndexes(cfpos
, &beginPos
, &endPos
, &status
);
574 if (expectedAttr
.field
== -1) {
576 log_err("ureldatefmt_formatForFields as \"%s\"; expect no field, but got %d rang %d-%d\n",
577 itemPtr
->expectedResults
[iOffset
*2],
578 ucfpos_getField(cfpos
, &status
), beginPos
, endPos
);
582 (beginPos
!= expectedAttr
.beginPos
|| endPos
!= expectedAttr
.endPos
)) {
583 log_err("ureldatefmt_formatForFields as \"%s\"; expect field %d range %d-%d, get field %d range %d-%d\n",
584 itemPtr
->expectedResults
[iOffset
*2 + 1],
585 expectedAttr
.field
, expectedAttr
.beginPos
, expectedAttr
.endPos
,
586 ucfpos_getField(cfpos
, &status
), beginPos
, endPos
);
591 ureldatefmt_closeResult(fv
);
594 ureldatefmt_close(reldatefmt
);
600 UDateRelativeDateTimeFormatterStyle width
;
601 UDisplayContext capContext
;
602 const char * relativeDateString
;
603 const char * timeString
;
604 const char * expectedResult
;
605 } CombineDateTimeTestItem
;
607 static const CombineDateTimeTestItem combTestItems
[] = {
608 { "en", UDAT_STYLE_LONG
, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
, "yesterday", "3:45 PM", "yesterday, 3:45 PM" },
609 { NULL
, (UDateRelativeDateTimeFormatterStyle
)0, (UDisplayContext
)0, NULL
, NULL
, NULL
} /* terminator */
612 static void TestCombineDateTime()
614 const CombineDateTimeTestItem
*itemPtr
;
615 log_verbose("\nTesting ureldatefmt_combineDateAndTime() with various parameters\n");
616 for (itemPtr
= combTestItems
; itemPtr
->locale
!= NULL
; itemPtr
++) {
617 URelativeDateTimeFormatter
*reldatefmt
= NULL
;
618 UErrorCode status
= U_ZERO_ERROR
;
619 UChar ubufreldate
[kUBufMax
];
620 UChar ubuftime
[kUBufMax
];
621 UChar ubufget
[kUBufMax
];
622 int32_t ulenreldate
, ulentime
, ulenget
;
624 reldatefmt
= ureldatefmt_open(itemPtr
->locale
, NULL
, itemPtr
->width
, itemPtr
->capContext
, &status
);
625 if ( U_FAILURE(status
) ) {
626 log_data_err("FAIL: ureldatefmt_open() for locale %s, width %d, capContext %d: %s\n",
627 itemPtr
->locale
, (int)itemPtr
->width
, (int)itemPtr
->capContext
, myErrorName(status
) );
631 ulenreldate
= u_unescape(itemPtr
->relativeDateString
, ubufreldate
, kUBufMax
);
632 ulentime
= u_unescape(itemPtr
->timeString
, ubuftime
, kUBufMax
);
633 ulenget
= ureldatefmt_combineDateAndTime(reldatefmt
, ubufreldate
, ulenreldate
, ubuftime
, ulentime
, ubufget
, kUBufMax
, &status
);
634 if ( U_FAILURE(status
) ) {
635 log_err("FAIL: ureldatefmt_combineDateAndTime() for locale %s, width %d, capContext %d: %s\n",
636 itemPtr
->locale
, (int)itemPtr
->width
, (int)itemPtr
->capContext
, myErrorName(status
) );
638 UChar ubufexp
[kUBufMax
];
639 int32_t ulenexp
= u_unescape(itemPtr
->expectedResult
, ubufexp
, kUBufMax
);
640 if (ulenget
!= ulenexp
|| u_strncmp(ubufget
, ubufexp
, ulenexp
) != 0) {
641 char bbufget
[kBBufMax
];
642 u_austrncpy(bbufget
, ubufget
, kUBufMax
);
643 log_err("ERROR: ureldatefmt_combineDateAndTime() for locale %s, width %d, capContext %d;\n expected %s\n get %s\n",
644 itemPtr
->locale
, (int)itemPtr
->width
, (int)itemPtr
->capContext
, itemPtr
->expectedResult
, bbufget
);
648 status
= U_ZERO_ERROR
;
649 ulenget
= ureldatefmt_combineDateAndTime(reldatefmt
, ubufreldate
, ulenreldate
, ubuftime
, ulentime
, NULL
, 0, &status
);
650 if ( status
!= U_BUFFER_OVERFLOW_ERROR
) {
651 log_err("FAIL: ureldatefmt_combineDateAndTime() preflight for locale %s, width %d, capContext %d: expected U_BUFFER_OVERFLOW_ERROR, got %s\n",
652 itemPtr
->locale
, (int)itemPtr
->width
, (int)itemPtr
->capContext
, myErrorName(status
) );
654 UChar ubufexp
[kUBufMax
];
655 int32_t ulenexp
= u_unescape(itemPtr
->expectedResult
, ubufexp
, kUBufMax
);
656 if (ulenget
!= ulenexp
) {
657 log_err("ERROR: ureldatefmt_combineDateAndTime() preflight for locale %s, width %d, capContext %d;\n expected len %d, get len %d\n",
658 itemPtr
->locale
, (int)itemPtr
->width
, (int)itemPtr
->capContext
, ulenexp
, ulenget
);
662 ureldatefmt_close(reldatefmt
);
666 static void TestFields() {
667 UErrorCode ec
= U_ZERO_ERROR
;
668 URelativeDateTimeFormatter
* fmt
= ureldatefmt_open(
672 UDISPCTX_CAPITALIZATION_NONE
,
674 assertSuccess("Creating RelDTFmt", &ec
);
675 UFormattedRelativeDateTime
* frdt
= ureldatefmt_openResult(&ec
);
676 assertSuccess("Creating FmtVal", &ec
);
678 ureldatefmt_formatNumericToResult(fmt
, -50, UDAT_REL_UNIT_SATURDAY
, frdt
, &ec
);
679 assertSuccess("formatNumeric", &ec
);
681 const UFormattedValue
* fv
= ureldatefmt_resultAsValue(frdt
, &ec
);
682 assertSuccess("Should convert without error", &ec
);
683 static const UFieldPositionWithCategory expectedFieldPositions
[] = {
684 // category, field, begin index, end index
685 {UFIELD_CATEGORY_NUMBER
, UNUM_INTEGER_FIELD
, 0, 2},
686 {UFIELD_CATEGORY_RELATIVE_DATETIME
, UDAT_REL_NUMERIC_FIELD
, 0, 2},
687 {UFIELD_CATEGORY_RELATIVE_DATETIME
, UDAT_REL_LITERAL_FIELD
, 3, 11}};
688 checkMixedFormattedValue(
689 "FormattedRelativeDateTime as FormattedValue (numeric)",
692 expectedFieldPositions
,
693 UPRV_LENGTHOF(expectedFieldPositions
));
696 ureldatefmt_formatToResult(fmt
, -1, UDAT_REL_UNIT_WEEK
, frdt
, &ec
);
697 assertSuccess("format", &ec
);
699 const UFormattedValue
* fv
= ureldatefmt_resultAsValue(frdt
, &ec
);
700 assertSuccess("Should convert without error", &ec
);
701 static const UFieldPositionWithCategory expectedFieldPositions
[] = {
702 // category, field, begin index, end index
703 {UFIELD_CATEGORY_RELATIVE_DATETIME
, UDAT_REL_LITERAL_FIELD
, 0, 8}};
704 checkMixedFormattedValue(
705 "FormattedRelativeDateTime as FormattedValue (relative)",
708 expectedFieldPositions
,
709 UPRV_LENGTHOF(expectedFieldPositions
));
712 ureldatefmt_closeResult(frdt
);
713 ureldatefmt_close(fmt
);
716 #endif /* #if !UCONFIG_NO_FORMATTING && !UCONFIG_NO_BREAK_ITERATION */