]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/intltest/dtifmtts.cpp
2 /********************************************************************
4 * Copyright (c) 1997-2008, International Business Machines Corporation and
5 * others. All Rights Reserved.
6 ********************************************************************/
8 #include "unicode/utypes.h"
10 #if !UCONFIG_NO_FORMATTING
13 //TODO: define it in compiler flag
14 //#define DTIFMTTS_DEBUG 1
24 #include "unicode/gregocal.h"
25 #include "unicode/dtintrv.h"
26 #include "unicode/dtitvinf.h"
27 #include "unicode/dtitvfmt.h"
32 //#define PRINTMESG(msg) { std::cout << "(" << __FILE__ << ":" << __LINE__ << ") " << msg << "\n"; }
33 #define PRINTMESG(msg) { std::cout << msg; }
36 #define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
41 void DateIntervalFormatTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ ) {
42 if (exec
) logln("TestSuite DateIntervalFormat");
45 TESTCASE(1, testFormat
);
46 TESTCASE(2, testFormatUserDII
);
47 TESTCASE(3, testStress
);
48 default: name
= ""; break;
53 * Test various generic API methods of DateIntervalFormat for API coverage.
55 void DateIntervalFormatTest::testAPI() {
57 /* ====== Test create interval instance with default locale and skeleton
59 UErrorCode status
= U_ZERO_ERROR
;
60 logln("Testing DateIntervalFormat create instance with default locale and skeleton");
62 DateIntervalFormat
* dtitvfmt
= DateIntervalFormat::createInstance(UDAT_YEAR_MONTH_DAY
, status
);
63 if(U_FAILURE(status
)) {
64 dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + default locale) - exitting");
71 /* ====== Test create interval instance with given locale and skeleton
73 status
= U_ZERO_ERROR
;
74 logln("Testing DateIntervalFormat create instance with given locale and skeleton");
76 dtitvfmt
= DateIntervalFormat::createInstance(UDAT_YEAR_MONTH_DAY
, Locale::getJapanese(), status
);
77 if(U_FAILURE(status
)) {
78 dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + locale) - exitting");
85 /* ====== Test create interval instance with dateIntervalInfo and skeleton
87 status
= U_ZERO_ERROR
;
88 logln("Testing DateIntervalFormat create instance with dateIntervalInfo and skeleton");
90 DateIntervalInfo
* dtitvinf
= new DateIntervalInfo(Locale::getSimplifiedChinese(), status
);
92 dtitvfmt
= DateIntervalFormat::createInstance("EEEdMMMyhms", *dtitvinf
, status
);
95 if(U_FAILURE(status
)) {
96 dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + DateIntervalInfo + default locale) - exitting");
103 /* ====== Test create interval instance with dateIntervalInfo and skeleton
105 status
= U_ZERO_ERROR
;
106 logln("Testing DateIntervalFormat create instance with dateIntervalInfo and skeleton");
108 dtitvinf
= new DateIntervalInfo(Locale::getSimplifiedChinese(), status
);
110 dtitvfmt
= DateIntervalFormat::createInstance("EEEdMMMyhms", Locale::getSimplifiedChinese(), *dtitvinf
, status
);
112 if(U_FAILURE(status
)) {
113 dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + DateIntervalInfo + locale) - exitting");
116 // not deleted, test clone
119 // ====== Test clone()
120 status
= U_ZERO_ERROR
;
121 logln("Testing DateIntervalFormat clone");
123 DateIntervalFormat
* another
= (DateIntervalFormat
*)dtitvfmt
->clone();
124 if ( (*another
) != (*dtitvfmt
) ) {
125 dataerrln("ERROR: clone failed");
129 // ====== Test getDateIntervalInfo, setDateIntervalInfo, adoptDateIntervalInfo
130 status
= U_ZERO_ERROR
;
131 logln("Testing DateIntervalFormat getDateIntervalInfo");
132 const DateIntervalInfo
* inf
= another
->getDateIntervalInfo();
133 dtitvfmt
->setDateIntervalInfo(*inf
, status
);
134 const DateIntervalInfo
* anotherInf
= dtitvfmt
->getDateIntervalInfo();
135 if ( (*inf
) != (*anotherInf
) || U_FAILURE(status
) ) {
136 dataerrln("ERROR: getDateIntervalInfo/setDateIntervalInfo failed");
140 status = U_ZERO_ERROR;
141 DateIntervalInfo* nonConstInf = inf->clone();
142 dtitvfmt->adoptDateIntervalInfo(nonConstInf, status);
143 anotherInf = dtitvfmt->getDateIntervalInfo();
144 if ( (*inf) != (*anotherInf) || U_FAILURE(status) ) {
145 dataerrln("ERROR: adoptDateIntervalInfo failed");
149 // ====== Test getDateFormat, setDateFormat, adoptDateFormat
151 status
= U_ZERO_ERROR
;
152 logln("Testing DateIntervalFormat getDateFormat");
153 const DateFormat
* fmt
= another
->getDateFormat();
155 dtitvfmt->setDateFormat(*fmt, status);
156 const DateFormat* anotherFmt = dtitvfmt->getDateFormat();
157 if ( (*fmt) != (*anotherFmt) || U_FAILURE(status) ) {
158 dataerrln("ERROR: getDateFormat/setDateFormat failed");
161 status = U_ZERO_ERROR;
162 DateFormat* nonConstFmt = (DateFormat*)fmt->clone();
163 dtitvfmt->adoptDateFormat(nonConstFmt, status);
164 anotherFmt = dtitvfmt->getDateFormat();
165 if ( (*fmt) != (*anotherFmt) || U_FAILURE(status) ) {
166 dataerrln("ERROR: adoptDateFormat failed");
171 // ======= Test getStaticClassID()
173 logln("Testing getStaticClassID()");
176 if(dtitvfmt
->getDynamicClassID() != DateIntervalFormat::getStaticClassID()) {
177 errln("ERROR: getDynamicClassID() didn't return the expected value");
182 // ====== test constructor/copy constructor and assignment
183 /* they are protected, no test
184 logln("Testing DateIntervalFormat constructor and assigment operator");
185 status = U_ZERO_ERROR;
187 DateFormat* constFmt = (constFmt*)dtitvfmt->getDateFormat()->clone();
188 inf = dtitvfmt->getDateIntervalInfo()->clone();
191 DateIntervalFormat* dtifmt = new DateIntervalFormat(fmt, inf, status);
192 if(U_FAILURE(status)) {
193 dataerrln("ERROR: Could not create DateIntervalFormat (default) - exitting");
197 DateIntervalFormat* dtifmt2 = new(dtifmt);
198 if ( (*dtifmt) != (*dtifmt2) ) {
199 dataerrln("ERROR: Could not create DateIntervalFormat (default) - exitting");
203 DateIntervalFormat dtifmt3 = (*dtifmt);
204 if ( (*dtifmt) != dtifmt3 ) {
205 dataerrln("ERROR: Could not create DateIntervalFormat (default) - exitting");
215 //===== test format and parse ==================
216 Formattable formattable
;
217 formattable
.setInt64(10);
219 FieldPosition pos
= 0;
220 status
= U_ZERO_ERROR
;
221 dtitvfmt
->format(formattable
, res
, pos
, status
);
222 if ( status
!= U_ILLEGAL_ARGUMENT_ERROR
) {
223 dataerrln("ERROR: format non-date-interval object should set U_ILLEGAL_ARGUMENT_ERROR - exitting");
227 DateInterval
* dtitv
= new DateInterval(3600*24*365, 3600*24*366);
228 formattable
.adoptObject(dtitv
);
231 status
= U_ZERO_ERROR
;
232 dtitvfmt
->format(formattable
, res
, pos
, status
);
233 if ( U_FAILURE(status
) ) {
234 dataerrln("ERROR: format date interval failed - exitting");
238 const DateFormat
* dfmt
= dtitvfmt
->getDateFormat();
239 Calendar
* fromCal
= dfmt
->getCalendar()->clone();
240 Calendar
* toCal
= dfmt
->getCalendar()->clone();
243 status
= U_ZERO_ERROR
;
244 dtitvfmt
->format(*fromCal
, *toCal
, res
, pos
, status
);
245 if ( U_FAILURE(status
) ) {
246 dataerrln("ERROR: format date interval failed - exitting");
253 Formattable fmttable
;
254 status
= U_ZERO_ERROR
;
255 // TODO: why do I need cast?
256 ((Format
*)dtitvfmt
)->parseObject(res
, fmttable
, status
);
257 if ( status
!= U_INVALID_FORMAT_ERROR
) {
258 dataerrln("ERROR: parse should set U_INVALID_FORMAT_ERROR - exitting");
265 //====== test format in testFormat()
273 void DateIntervalFormatTest::testFormat() {
274 // first item is date pattern
275 // followed by a group of locale/from_data/to_data/skeleton/interval_data
276 const char* DATA
[] = {
277 "yyyy MM dd HH:mm:ss",
278 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "MMMM", "October 2007 \\u2013 October 2008",
279 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "MMM", "Oct 2007 \\u2013 Oct 2008",
280 // test skeleton with both date and time
281 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMyhm", "Nov 10, 2007 10:10 AM \\u2013 Nov 20, 2007 10:10 AM",
283 "en", "2007 11 10 10:10:10", "2007 11 10 11:10:10", "dMMMyhm", "Nov 10, 2007 10:10\\u201311:10 AM",
285 "en", "2007 11 10 10:10:10", "2007 11 10 11:10:10", "hms", "10:10:10 AM \\u2013 11:10:10 AM",
287 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEEEdMMMMy", "Wednesday, October 10, 2007 \\u2013 Friday, October 10, 2008",
289 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMMMy", "October 10, 2007 \\u2013 October 10, 2008",
291 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMMM", "October 10, 2007 \\u2013 October 10, 2008",
293 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "MMMMy", "October 2007 \\u2013 October 2008",
295 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEEEdMMMM", "Wednesday, October 10, 2007 \\u2013 Friday, October 10, 2008",
297 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdMMMy", "Wed, Oct 10, 2007 \\u2013 Fri, Oct 10, 2008",
299 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMMy", "Oct 10, 2007 \\u2013 Oct 10, 2008",
301 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMM", "Oct 10, 2007 \\u2013 Oct 10, 2008",
303 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "MMMy", "Oct 2007 \\u2013 Oct 2008",
305 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdMMM", "Wed, Oct 10, 2007 \\u2013 Fri, Oct 10, 2008",
307 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdMy", "Wed, 10/10/07 \\u2013 Fri, 10/10/08",
309 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMy", "10/10/07 \\u2013 10/10/08",
311 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dM", "10/10/07 \\u2013 10/10/08",
313 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "My", "10/07 \\u2013 10/08",
315 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdM", "Wed, 10/10/07 \\u2013 Fri, 10/10/08",
317 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "d", "10/10/07 \\u2013 10/10/08",
319 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "Ed", "10 Wed \\u2013 10 Fri",
321 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "y", "2007\\u20132008",
323 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "M", "10/07 \\u2013 10/08",
327 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hm", "10/10/2007 10:10 AM \\u2013 10/10/2008 10:10 AM",
329 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hmv", "10/10/2007 10:10 AM PT \\u2013 10/10/2008 10:10 AM PT",
331 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hmz", "10/10/2007 10:10 AM PDT \\u2013 10/10/2008 10:10 AM PDT",
333 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "h", "10/10/2007 10 \\u2013 10/10/2008 10",
335 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hv", "10/10/2007 PT (Hour: 10) \\u2013 10/10/2008 PT (Hour: 10)",
337 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hz", "10/10/2007 PDT (Hour: 10) \\u2013 10/10/2008 PDT (Hour: 10)",
339 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEddMMyyyy", "Wed, 10/10/07 \\u2013 Fri, 10/10/08",
341 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EddMMy", "Wed, 10/10/07 \\u2013 Fri, 10/10/08",
343 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hhmm", "10/10/2007 10:10 AM \\u2013 10/10/2008 10:10 AM",
345 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hhmmzz", "10/10/2007 10:10 AM PDT \\u2013 10/10/2008 10:10 AM PDT",
347 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hms", "10/10/2007 10:10:10 AM \\u2013 10/10/2008 10:10:10 AM",
349 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMMMMy", "O 10, 2007 \\u2013 O 10, 2008",
351 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEEEEdM", "W, 10/10/07 \\u2013 F, 10/10/08",
353 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEEEdMMMMy", "Wednesday, October 10 \\u2013 Saturday, November 10, 2007",
355 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMMMy", "October 10 \\u2013 November 10, 2007",
357 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMMM", "October 10 \\u2013 November 10",
359 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMMMy", "October\\u2013November 2007",
361 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEEEdMMMM", "Wednesday, October 10 \\u2013 Saturday, November 10",
363 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EdMMMy", "Wed, Oct 10 \\u2013 Sat, Nov 10, 2007",
365 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMMy", "Oct 10 \\u2013 Nov 10, 2007",
367 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMM", "Oct 10 \\u2013 Nov 10",
369 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMMy", "Oct\\u2013Nov 2007",
371 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EdMMM", "Wed, Oct 10 \\u2013 Sat, Nov 10",
373 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EdMy", "Wed, 10/10/07 \\u2013 Sat, 11/10/07",
375 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMy", "10/10/07 \\u2013 11/10/07",
378 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "My", "10/07 \\u2013 11/07",
380 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EdM", "Wed, 10/10 \\u2013 Sat, 11/10",
382 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "d", "10/10 \\u2013 11/10",
384 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "Ed", "10 Wed \\u2013 10 Sat",
386 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "y", "2007",
388 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "M", "10\\u201311",
390 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMM", "Oct\\u2013Nov",
392 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMMM", "October-November",
394 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hm", "10/10/2007 10:10 AM \\u2013 11/10/2007 10:10 AM",
396 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hmv", "10/10/2007 10:10 AM PT \\u2013 11/10/2007 10:10 AM PT",
398 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hmz", "10/10/2007 10:10 AM PDT \\u2013 11/10/2007 10:10 AM PST",
400 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "h", "10/10/2007 10 \\u2013 11/10/2007 10",
402 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hv", "10/10/2007 PT (Hour: 10) \\u2013 11/10/2007 PT (Hour: 10)",
404 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hz", "10/10/2007 PDT (Hour: 10) \\u2013 11/10/2007 PST (Hour: 10)",
406 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEddMMyyyy", "Wed, 10/10/07 \\u2013 Sat, 11/10/07",
408 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EddMMy", "Wed, 10/10/07 \\u2013 Sat, 11/10/07",
411 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hhmmzz", "10/10/2007 10:10 AM PDT \\u2013 11/10/2007 10:10 AM PST",
413 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hms", "10/10/2007 10:10:10 AM \\u2013 11/10/2007 10:10:10 AM",
415 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMMMMy", "O 10 \\u2013 N 10, 2007",
417 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEEEEdM", "W, 10/10 \\u2013 S, 11/10",
419 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMMMy", "Saturday, November 10 \\u2013 Tuesday, November 20, 2007",
421 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMMy", "November 10\\u201320, 2007",
423 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMM", "November 10\\u201320",
426 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMMM", "Saturday, November 10 \\u2013 Tuesday, November 20",
428 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdMMMy", "Sat, Nov 10 \\u2013 Tue, Nov 20, 2007",
430 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMy", "Nov 10\\u201320, 2007",
432 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMM", "Nov 10\\u201320",
434 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMMy", "Nov 2007",
436 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdMMM", "Sat, Nov 10 \\u2013 Tue, Nov 20",
438 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdMy", "Sat, 11/10/07 \\u2013 Tue, 11/20/07",
440 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMy", "11/10/07 \\u2013 11/20/07",
442 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dM", "11/10 \\u2013 11/20",
444 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "My", "11/2007",
446 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdM", "Sat, 11/10 \\u2013 Tue, 11/20",
448 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "d", "10\\u201320",
450 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "Ed", "10 Sat \\u2013 20 Tue",
452 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "y", "2007",
454 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "M", "11",
456 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMM", "Nov",
458 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMMM", "November",
460 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hm", "11/10/2007 10:10 AM \\u2013 11/20/2007 10:10 AM",
462 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hmv", "11/10/2007 10:10 AM PT \\u2013 11/20/2007 10:10 AM PT",
464 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hmz", "11/10/2007 10:10 AM PST \\u2013 11/20/2007 10:10 AM PST",
466 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "h", "11/10/2007 10 \\u2013 11/20/2007 10",
468 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hv", "11/10/2007 PT (Hour: 10) \\u2013 11/20/2007 PT (Hour: 10)",
470 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hz", "11/10/2007 PST (Hour: 10) \\u2013 11/20/2007 PST (Hour: 10)",
472 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEddMMyyyy", "Sat, 11/10/07 \\u2013 Tue, 11/20/07",
474 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EddMMy", "Sat, 11/10/07 \\u2013 Tue, 11/20/07",
476 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hhmm", "11/10/2007 10:10 AM \\u2013 11/20/2007 10:10 AM",
478 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hhmmzz", "11/10/2007 10:10 AM PST \\u2013 11/20/2007 10:10 AM PST",
480 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hms", "11/10/2007 10:10:10 AM \\u2013 11/20/2007 10:10:10 AM",
482 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMMMy", "N 10\\u201320, 2007",
484 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEEdM", "S, 11/10 \\u2013 T, 11/20",
486 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMMMy", "Wednesday, January 10, 2007",
488 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMMMy", "January 10, 2007",
490 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMMM", "January 10",
492 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "MMMMy", "January 2007",
494 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMMM", "Wednesday, January 10",
496 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EdMMMy", "Wed, Jan 10, 2007",
498 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMMy", "Jan 10, 2007",
500 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMM", "Jan 10",
502 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "MMMy", "Jan 2007",
504 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EdMMM", "Wed, Jan 10",
507 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMy", "1/10/2007",
509 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dM", "1/10",
511 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "My", "1/2007",
513 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EdM", "Wed, 1/10",
515 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "d", "10",
517 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "Ed", "10 Wed",
519 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "y", "2007",
521 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "M", "1",
523 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "MMM", "Jan",
525 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "MMMM", "January",
527 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hm", "10:00 AM \\u2013 2:10 PM",
529 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hmv", "10:00 AM \\u2013 2:10 PM PT",
531 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hmz", "10:00 AM \\u2013 2:10 PM PST",
533 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "h", "10 AM \\u2013 2 PM",
536 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hz", "10 AM \\u2013 2 PM PST",
538 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEddMMyyyy", "Wed, 01/10/2007",
540 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EddMMy", "Wed, 01/10/2007",
542 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hhmm", "10:00 AM \\u2013 2:10 PM",
544 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hhmmzz", "10:00 AM \\u2013 2:10 PM PST",
546 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hms", "10:00:10 AM \\u2013 2:10:10 PM",
548 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMMMMy", "J 10, 2007",
550 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEEdM", "W, 1/10",
551 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMMMMy", "January 10, 2007",
553 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMMMM", "January 10",
555 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "MMMMy", "January 2007",
557 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EEEEdMMMM", "Wednesday, January 10",
559 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EdMMMy", "Wed, Jan 10, 2007",
561 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMMMy", "Jan 10, 2007",
563 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMMM", "Jan 10",
566 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EdMMM", "Wed, Jan 10",
568 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EdMy", "Wed, 1/10/2007",
570 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMy", "1/10/2007",
573 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "My", "1/2007",
575 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EdM", "Wed, 1/10",
577 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "d", "10",
580 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "y", "2007",
582 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "M", "1",
586 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hm", "10:00\\u201310:20 AM",
589 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hmz", "10:00\\u201310:20 AM PST",
592 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hv", "PT (Hour: 10)",
596 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EddMMy", "Wed, 01/10/2007",
598 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hhmm", "10:00\\u201310:20 AM",
600 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hhmmzz", "10:00\\u201310:20 AM PST",
603 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "dMMMMMy", "J 10, 2007",
606 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EEEEdMMMMy", "Wednesday, January 10, 2007",
608 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "dMMMMy", "January 10, 2007",
611 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "MMMMy", "January 2007",
613 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EEEEdMMMM", "Wednesday, January 10",
616 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "dMMMy", "Jan 10, 2007",
618 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "dMMM", "Jan 10",
621 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EdMMM", "Wed, Jan 10",
623 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EdMy", "Wed, 1/10/2007",
625 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "dMy", "1/10/2007",
628 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "My", "1/2007",
630 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EdM", "Wed, 1/10",
632 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "d", "10",
635 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "y", "2007",
637 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "M", "1",
640 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "MMMM", "January",
642 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hm", "10:10 AM",
645 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hmz", "10:10 AM PST",
647 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "h", "10",
649 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hv", "PT (Hour: 10)",
652 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EEddMMyyyy", "Wed, 01/10/2007",
655 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hhmm", "10:10 AM",
657 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hhmmzz", "10:10 AM PST",
660 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "dMMMMMy", "J 10, 2007",
662 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EEEEEdM", "W, 1/10",
664 "zh", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEEEdMMMMy", "2007\\u5e7410\\u670810\\u65e5\\u661f\\u671f\\u4e09\\u81f32008\\u5e7410\\u670810\\u65e5\\u661f\\u671f\\u4e94",
667 "zh", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMMMy", "2007\\u5e7410\\u670810\\u65e5\\u81f311\\u670810\\u65e5",
670 "zh", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMMMy", "2007\\u5e7410\\u6708\\u81f311\\u6708",
673 "zh", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hmv", "2007\\u5e7410\\u670810\\u65e5 \\u4e0a\\u534810:10 \\u7f8e\\u56fd (\\u6d1b\\u6749\\u77f6)\\u20132007\\u5e7411\\u670810\\u65e5 \\u4e0a\\u534810:10 \\u7f8e\\u56fd (\\u6d1b\\u6749\\u77f6)",
675 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMMMy", "2007\\u5e7411\\u670810\\u65e5\\u661f\\u671f\\u516d\\u81f320\\u65e5\\u661f\\u671f\\u4e8c",
678 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMM", "11\\u670810\\u65e5\\u81f320\\u65e5",
680 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMMMy", "2007\\u5E7411\\u6708", // (fixed expected result per ticket:6626:)
682 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMMM", "11\\u670810\\u65e5\\u661f\\u671f\\u516d\\u81f320\\u65e5\\u661f\\u671f\\u4e8c",
685 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdMy", "07-11-10\\u5468\\u516d\\u81f307-11-20\\u5468\\u4e8c",
688 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dM", "11-10\\u81f311-20",
690 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "My", "2007-11",
692 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdM", "11-10\\u5468\\u516d\\u81f311-20\\u5468\\u4e8c",
695 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "y", "2007\\u5E74", // (fixed expected result per ticket:6626:)
697 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "M", "11",
699 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMM", "\\u5341\\u4E00\\u6708", // (fixed expected result per ticket:6626: and others)
702 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hmz", "2007\\u5e7411\\u670810\\u65e5 \\u4e0a\\u534810:10 \\u683c\\u6797\\u5c3c\\u6cbb\\u6807\\u51c6\\u65f6\\u95f4-0800\\u20132007\\u5e7411\\u670820\\u65e5 \\u4e0a\\u534810:10 \\u683c\\u6797\\u5c3c\\u6cbb\\u6807\\u51c6\\u65f6\\u95f4-0800",
704 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "h", "2007\\u5e7411\\u670810\\u65e5 10\\u65F6\\u20132007\\u5e7411\\u670820\\u65e5 10\\u65F6", // (fixed expected result per ticket:6626:)
706 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMMMy", "2007\\u5e741\\u670810\\u65e5\\u661f\\u671f\\u4e09", // (fixed expected result per ticket:6626:)
708 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hm", "\\u4e0a\\u534810:00\\u81f3\\u4e0b\\u53482:10",
711 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hmz", "\\u4e0a\\u534810:00\\u81f3\\u4e0b\\u53482:10\\u683c\\u6797\\u5c3c\\u6cbb\\u6807\\u51c6\\u65f6\\u95f4-0800",
713 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "h", "\\u4e0a\\u534810\\u81f3\\u4e0b\\u53482\\u65f6",
715 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "hv", "\\u4e0a\\u534810\\u81f3\\u4e0b\\u53482\\u65f6\\u7f8e\\u56fd (\\u6d1b\\u6749\\u77f6)",
719 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hm", "\\u4e0a\\u534810:00\\u81f310:20",
721 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hmv", "\\u4e0a\\u534810:00\\u81f310:20\\u7f8e\\u56fd (\\u6d1b\\u6749\\u77f6)",
724 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hz", "\\u683c\\u6797\\u5c3c\\u6cbb\\u6807\\u51c6\\u65f6\\u95f4-0800 (\\u5c0f\\u65f6: 10\\u65F6)", // (fixed expected result per ticket:6626:)
727 "zh", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hm", "\\u4e0a\\u534810:10",
729 "zh", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "h", "10\\u65F6", // (fixed expected result per ticket:6626:)
731 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EEEEdMMMy", "Mittwoch, 10. Okt 2007 - Freitag, 10. Okt 2008",
734 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMMM", "10. Okt 2007 - 10. Okt 2008",
736 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "MMMy", "Okt 2007 - Okt 2008",
739 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdMy", "Mi., 10.10.07 - Fr., 10.10.08",
741 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "dMy", "10.10.07 - 10.10.08",
744 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "My", "10.07 - 10.08",
746 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "EdM", "Mi., 10.10.07 - Fr., 10.10.08",
749 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "y", "2007-2008",
751 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "M", "10.07 - 10.08",
754 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "hm", "10.10.2007 10:10 vorm. - 10.10.2008 10:10 vorm.",
756 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEEEdMMMy", "Mittwoch, 10. Okt - Samstag, 10. Nov 2007",
759 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dMMM", "10. Okt - 10. Nov",
761 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMMy", "Okt-Nov 2007",
763 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "EEEEdMMM", "Mittwoch, 10. Okt - Samstag, 10. Nov",
766 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "dM", "10.10. - 10.11.",
768 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "My", "10.07 - 11.07",
771 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "d", "10.10. - 10.11.",
773 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "y", "2007",
776 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "MMM", "Okt-Nov",
779 "de", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "hms", "10.10.2007 10:10:10 vorm. - 10.11.2007 10:10:10 vorm.",
781 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMMy", "Samstag, 10. - Dienstag, 20. Nov 2007",
783 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dMMMy", "10.-20. Nov 2007",
786 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "MMMy", "Nov 2007",
788 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EEEEdMMM", "Samstag, 10. - Dienstag, 20. Nov",
790 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "EdMy", "Sa., 10.11.07 - Di., 20.11.07",
793 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "dM", "10.11. - 20.11.",
795 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "My", "2007-11",
798 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "d", "10.-20.",
800 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "y", "2007",
803 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "hmv", "10.11.2007 10:10 vorm. Vereinigte Staaten (Los Angeles) - 20.11.2007 10:10 vorm. Vereinigte Staaten (Los Angeles)",
805 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMMy", "Mittwoch, 10. Jan 2007",
808 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "dMMM", "10. Jan",
810 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "MMMy", "Jan 2007",
812 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "EEEEdMMM", "Mittwoch 10. Jan",
815 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "h", "10-14",
817 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "EEEEdMMM", "Mittwoch 10. Jan",
820 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hmv", "10:00-10:20 Vereinigte Staaten (Los Angeles)",
822 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hmz", "10:00-10:20 GMT-08:00",
824 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "h", "10",
827 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "hz", "GMT-08:00 (Stunde: 10)",
829 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "EEEEdMMMy", "Mittwoch, 10. Jan 2007",
832 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hmv", "10:10 vorm. Vereinigte Staaten (Los Angeles)",
834 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hmz", "10:10 vorm. GMT-08:00",
837 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hv", "Vereinigte Staaten (Los Angeles) (Stunde: 10)",
839 "de", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "hz", "GMT-08:00 (Stunde: 10)",
841 expect(DATA
, ARRAY_SIZE(DATA
));
845 void DateIntervalFormatTest::expect(const char** data
, int32_t data_length
) {
847 UErrorCode ec
= U_ZERO_ERROR
;
848 UnicodeString str
, str2
;
849 const char* pattern
= data
[0];
852 #ifdef DTIFMTTS_DEBUG
855 sprintf(mesg
, "locale: %s\n", locName
);
859 while (i
<data_length
) {
860 const char* locName
= data
[i
++];
862 SimpleDateFormat
ref(pattern
, loc
, ec
);
863 if (!assertSuccess("construct SimpleDateFormat in expect", ec
)) return;
865 const char* datestr
= data
[i
++];
866 const char* datestr_2
= data
[i
++];
867 #ifdef DTIFMTTS_DEBUG
868 sprintf(mesg
, "original date: %s - %s\n", datestr
, datestr_2
);
871 UDate date
= ref
.parse(ctou(datestr
), ec
);
872 if (!assertSuccess("parse 1st data in expect", ec
)) return;
873 UDate date_2
= ref
.parse(ctou(datestr_2
), ec
);
874 if (!assertSuccess("parse 2nd data in expect", ec
)) return;
875 DateInterval
dtitv(date
, date_2
);
877 const UnicodeString
& oneSkeleton
= data
[i
++];
879 DateIntervalFormat
* dtitvfmt
= DateIntervalFormat::createInstance(oneSkeleton
, loc
, ec
);
880 if (!assertSuccess("createInstance(skeleton) in expect", ec
)) return;
882 dtitvfmt
->format(&dtitv
, str
.remove(), pos
, ec
);
883 if (!assertSuccess("format in expect", ec
)) return;
884 assertEquals((UnicodeString
)"\"" + locName
+ "\\" + oneSkeleton
+ "\\" + datestr
+ "\\" + datestr_2
+ "\"", ctou(data
[i
++]), str
);
888 #ifdef DTIFMTTS_DEBUG
889 str
.extract(0, str
.length(), result
, "UTF-8");
890 sprintf(mesg
, "interval date: %s\n", result
);
893 std::cout
<< "\"" << locName
<< "\", "
894 << "\"" << datestr
<< "\", "
895 << "\"" << datestr_2
<< "\", ";
896 printUnicodeString(oneSkeleton
);
897 printUnicodeString(str
);
906 * Test format using user defined DateIntervalInfo
908 void DateIntervalFormatTest::testFormatUserDII() {
909 // first item is date pattern
910 const char* DATA
[] = {
911 "yyyy MM dd HH:mm:ss",
912 "en", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "Oct 10, 2007 --- Oct 10, 2008",
914 "en", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 Oct 10 - Nov 2007",
916 "en", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "Nov 10, 2007 --- Nov 20, 2007",
918 "en", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "Jan 10, 2007",
920 "en", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "Jan 10, 2007",
922 "en", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "Jan 10, 2007",
924 "zh", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "2007\\u5e7410\\u670810\\u65e5 --- 2008\\u5e7410\\u670810\\u65e5",
926 "zh", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 10\\u6708 10 - 11\\u6708 2007",
928 "zh", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "2007\\u5e7411\\u670810\\u65e5 --- 2007\\u5e7411\\u670820\\u65e5",
930 "zh", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket:6626:)
932 "zh", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket:6626:)
934 "zh", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "2007\\u5e741\\u670810\\u65e5", // (fixed expected result per ticket:6626:)
936 "de", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "10. Okt 2007 --- 10. Okt 2008",
939 "de", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "10. Nov 2007 --- 20. Nov 2007",
941 "de", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "10. Jan 2007",
943 "de", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "10. Jan 2007",
946 "es", "2007 10 10 10:10:10", "2008 10 10 10:10:10", "10 de oct de 2007 --- 10 de oct de 2008",
948 "es", "2007 10 10 10:10:10", "2007 11 10 10:10:10", "2007 oct 10 - nov 2007",
950 "es", "2007 11 10 10:10:10", "2007 11 20 10:10:10", "10 de nov de 2007 --- 20 de nov de 2007",
952 "es", "2007 01 10 10:00:10", "2007 01 10 14:10:10", "10 de ene de 2007",
954 "es", "2007 01 10 10:00:10", "2007 01 10 10:20:10", "10 de ene de 2007",
956 "es", "2007 01 10 10:10:10", "2007 01 10 10:10:20", "10 de ene de 2007",
958 expectUserDII(DATA
, ARRAY_SIZE(DATA
));
962 void DateIntervalFormatTest::expectUserDII(const char** data
,
963 int32_t data_length
) {
966 UErrorCode ec
= U_ZERO_ERROR
;
967 const char* pattern
= data
[0];
970 while ( i
< data_length
) {
971 const char* locName
= data
[i
++];
973 SimpleDateFormat
ref(pattern
, loc
, ec
);
974 if (!assertSuccess("construct SimpleDateFormat in expectUserDII", ec
)) return;
975 const char* datestr
= data
[i
++];
976 const char* datestr_2
= data
[i
++];
977 UDate date
= ref
.parse(ctou(datestr
), ec
);
978 if (!assertSuccess("parse in expectUserDII", ec
)) return;
979 UDate date_2
= ref
.parse(ctou(datestr_2
), ec
);
980 if (!assertSuccess("parse in expectUserDII", ec
)) return;
981 DateInterval
dtitv(date
, date_2
);
984 // test user created DateIntervalInfo
985 DateIntervalInfo
* dtitvinf
= new DateIntervalInfo(ec
);
986 dtitvinf
->setFallbackIntervalPattern("{0} --- {1}", ec
);
987 dtitvinf
->setIntervalPattern(UDAT_YEAR_ABBR_MONTH_DAY
, UCAL_MONTH
, "yyyy MMM d - MMM y",ec
);
988 if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec
)) return;
989 dtitvinf
->setIntervalPattern(UDAT_YEAR_ABBR_MONTH_DAY
, UCAL_HOUR_OF_DAY
, "yyyy MMM d HH:mm - HH:mm", ec
);
990 if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec
)) return;
991 DateIntervalFormat
* dtitvfmt
= DateIntervalFormat::createInstance(UDAT_YEAR_ABBR_MONTH_DAY
, loc
, *dtitvinf
, ec
);
993 if (!assertSuccess("createInstance(skeleton,dtitvinf) in expectUserDII", ec
)) return;
995 dtitvfmt
->format(&dtitv
, str
.remove(), pos
, ec
);
996 if (!assertSuccess("format in expectUserDII", ec
)) return;
997 assertEquals((UnicodeString
)"\"" + locName
+ "\\" + datestr
+ "\\" + datestr_2
+ "\"", ctou(data
[i
++]), str
);
998 #ifdef DTIFMTTS_DEBUG
1001 PRINTMESG("interval format using user defined DateIntervalInfo\n");
1002 str
.extract(0, str
.length(), result
, "UTF-8");
1003 sprintf(mesg
, "interval date: %s\n", result
);
1011 void DateIntervalFormatTest::testStress() {
1013 logln("Quick mode: Skipping test");
1016 const char* DATA
[] = {
1017 "yyyy MM dd HH:mm:ss",
1018 "2007 10 10 10:10:10", "2008 10 10 10:10:10",
1019 "2007 10 10 10:10:10", "2007 11 10 10:10:10",
1020 "2007 11 10 10:10:10", "2007 11 20 10:10:10",
1021 "2007 01 10 10:00:10", "2007 01 10 14:10:10",
1022 "2007 01 10 10:00:10", "2007 01 10 10:20:10",
1023 "2007 01 10 10:10:10", "2007 01 10 10:10:20",
1026 const char* testLocale
[][3] = {
1068 uint32_t localeIndex
;
1069 for ( localeIndex
= 0; localeIndex
< ARRAY_SIZE(testLocale
); ++localeIndex
) {
1071 uprv_strcpy(locName
, testLocale
[localeIndex
][0]);
1072 uprv_strcat(locName
, testLocale
[localeIndex
][1]);
1073 stress(DATA
, ARRAY_SIZE(DATA
), Locale(testLocale
[localeIndex
][0], testLocale
[localeIndex
][1], testLocale
[localeIndex
][2]), locName
);
1078 void DateIntervalFormatTest::stress(const char** data
, int32_t data_length
,
1079 const Locale
& loc
, const char* locName
) {
1080 UnicodeString skeleton
[] = {
1108 "EEddMMyyyy", // following could be normalized
1112 "hms", // following could not be normalized
1118 UErrorCode ec
= U_ZERO_ERROR
;
1119 UnicodeString str
, str2
;
1120 SimpleDateFormat
ref(data
[i
++], loc
, ec
);
1121 if (!assertSuccess("construct SimpleDateFormat", ec
)) return;
1123 #ifdef DTIFMTTS_DEBUG
1126 sprintf(mesg
, "locale: %s\n", locName
);
1130 while (i
<data_length
) {
1133 const char* datestr
= data
[i
++];
1134 const char* datestr_2
= data
[i
++];
1135 #ifdef DTIFMTTS_DEBUG
1136 sprintf(mesg
, "original date: %s - %s\n", datestr
, datestr_2
);
1139 UDate date
= ref
.parse(ctou(datestr
), ec
);
1140 if (!assertSuccess("parse", ec
)) return;
1141 UDate date_2
= ref
.parse(ctou(datestr_2
), ec
);
1142 if (!assertSuccess("parse", ec
)) return;
1143 DateInterval
dtitv(date
, date_2
);
1145 for ( uint32_t skeletonIndex
= 0;
1146 skeletonIndex
< ARRAY_SIZE(skeleton
);
1148 const UnicodeString
& oneSkeleton
= skeleton
[skeletonIndex
];
1149 DateIntervalFormat
* dtitvfmt
= DateIntervalFormat::createInstance(oneSkeleton
, loc
, ec
);
1150 if (!assertSuccess("createInstance(skeleton)", ec
)) return;
1152 // reset the calendar to be Gregorian calendar for "th"
1153 if ( uprv_strcmp(locName, "th") == 0 ) {
1154 GregorianCalendar* gregCal = new GregorianCalendar(loc, ec);
1155 if (!assertSuccess("GregorianCalendar()", ec)) return;
1156 const DateFormat* dformat = dtitvfmt->getDateFormat();
1157 DateFormat* newOne = (DateFormat*)dformat->clone();
1158 newOne->adoptCalendar(gregCal);
1159 //dtitvfmt->adoptDateFormat(newOne, ec);
1160 dtitvfmt->setDateFormat(*newOne, ec);
1162 if (!assertSuccess("adoptDateFormat()", ec)) return;
1165 FieldPosition pos
=0;
1166 dtitvfmt
->format(&dtitv
, str
.remove(), pos
, ec
);
1167 if (!assertSuccess("format", ec
)) return;
1168 #ifdef DTIFMTTS_DEBUG
1169 oneSkeleton
.extract(0, oneSkeleton
.length(), result
, "UTF-8");
1170 sprintf(mesg
, "interval by skeleton: %s\n", result
);
1172 str
.extract(0, str
.length(), result
, "UTF-8");
1173 sprintf(mesg
, "interval date: %s\n", result
);
1179 // test user created DateIntervalInfo
1181 DateIntervalInfo
* dtitvinf
= new DateIntervalInfo(ec
);
1182 dtitvinf
->setFallbackIntervalPattern("{0} --- {1}", ec
);
1183 dtitvinf
->setIntervalPattern(UDAT_YEAR_ABBR_MONTH_DAY
, UCAL_MONTH
, "yyyy MMM d - MMM y",ec
);
1184 if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec
)) return;
1185 dtitvinf
->setIntervalPattern(UDAT_YEAR_ABBR_MONTH_DAY
, UCAL_HOUR_OF_DAY
, "yyyy MMM d HH:mm - HH:mm", ec
);
1186 if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec
)) return;
1187 DateIntervalFormat
* dtitvfmt
= DateIntervalFormat::createInstance(UDAT_YEAR_ABBR_MONTH_DAY
, loc
, *dtitvinf
, ec
);
1189 if (!assertSuccess("createInstance(skeleton,dtitvinf)", ec
)) return;
1190 FieldPosition pos
=0;
1191 dtitvfmt
->format(&dtitv
, str
.remove(), pos
, ec
);
1192 if ( uprv_strcmp(locName
, "th") ) {
1193 if (!assertSuccess("format", ec
)) return;
1194 #ifdef DTIFMTTS_DEBUG
1195 PRINTMESG("interval format using user defined DateIntervalInfo\n");
1196 str
.extract(0, str
.length(), result
, "UTF-8");
1197 sprintf(mesg
, "interval date: %s\n", result
);
1201 // for "th", the default calendar is Budhist,
1203 assertTrue("Default calendar for \"th\" is Budhist", ec
== U_ILLEGAL_ARGUMENT_ERROR
);
1210 #endif /* #if !UCONFIG_NO_FORMATTING */