]> git.saurik.com Git - apple/icu.git/blame - icuSources/test/intltest/dtfmrgts.cpp
ICU-64260.0.1.tar.gz
[apple/icu.git] / icuSources / test / intltest / dtfmrgts.cpp
CommitLineData
f3c0d7a5
A
1// © 2016 and later: Unicode, Inc. and others.
2// License & terms of use: http://www.unicode.org/copyright.html
b75a7d8f
A
3/********************************************************************
4 * COPYRIGHT:
2ca993e8 5 * Copyright (c) 1997-2016, International Business Machines Corporation and
b75a7d8f
A
6 * others. All Rights Reserved.
7 ********************************************************************/
8
9#include "unicode/utypes.h"
10
11#if !UCONFIG_NO_FORMATTING
b75a7d8f
A
12#include "dtfmrgts.h"
13
14#include "unicode/timezone.h"
15#include "unicode/gregocal.h"
16#include "unicode/smpdtfmt.h"
17#include "unicode/datefmt.h"
18#include "unicode/simpletz.h"
19#include "unicode/resbund.h"
2ca993e8 20#include "cmemory.h"
b75a7d8f
A
21
22// *****************************************************************************
23// class DateFormatRegressionTest
24// *****************************************************************************
25
26#define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
27
28void
29DateFormatRegressionTest::runIndexedTest( int32_t index, UBool exec, const char* &name, char* /*par*/ )
30{
31 // if (exec) logln((UnicodeString)"TestSuite DateFormatRegressionTest");
32 switch (index) {
33 CASE(0,Test4029195)
34 CASE(1,Test4052408)
35 CASE(2,Test4056591)
36 CASE(3,Test4059917)
37 CASE(4,Test4060212)
38 CASE(5,Test4061287)
39 CASE(6,Test4065240)
40 CASE(7,Test4071441)
41 CASE(8,Test4073003)
42 CASE(9,Test4089106)
43 CASE(10,Test4100302)
44 CASE(11,Test4101483)
45 CASE(12,Test4103340)
46 CASE(13,Test4103341)
47 CASE(14,Test4104136)
48 CASE(15,Test4104522)
49 CASE(16,Test4106807)
0f5d89e8 50 CASE(17,Test4108407)
b75a7d8f
A
51 CASE(18,Test4134203)
52 CASE(19,Test4151631)
53 CASE(20,Test4151706)
54 CASE(21,Test4162071)
55 CASE(22,Test4182066)
56 CASE(23,Test4210209)
57 CASE(24,Test714)
58 CASE(25,Test1684)
46f4442e 59 CASE(26,Test5554)
4388f060 60 CASE(27,Test9237)
51004dcb 61 CASE(28,TestParsing)
3d1f044b
A
62 CASE(29,Test12902_yWithGregoCalInThaiLoc)
63 CASE(30,TestT10334)
64 CASE(31,TestT10619)
65 CASE(32,TestT10855)
66 CASE(33,TestT10906)
67 CASE(34,TestT13380)
b75a7d8f
A
68 default: name = ""; break;
69 }
70}
71
72/**
73 * @bug 4029195
74 */
75void DateFormatRegressionTest::Test4029195(void)
76{
77 UErrorCode status = U_ZERO_ERROR;
78
79 UDate today = Calendar::getNow();
80 logln((UnicodeString) "today: " + today);
81
82 SimpleDateFormat *sdf = (SimpleDateFormat*) DateFormat::createDateInstance();
73c04bcf
A
83 if (failure(status, "SimpleDateFormat::createDateInstance")) {
84 return;
85 }
b75a7d8f 86 UnicodeString pat;
73c04bcf
A
87 if(sdf == NULL){
88 dataerrln("Error calling DateFormat::createDateTimeInstance");
89 return;
90 }
91
b75a7d8f
A
92 pat = sdf->toPattern(pat);
93 logln("pattern: " + pat);
94 UnicodeString fmtd;
57a6839d 95
b75a7d8f
A
96 FieldPosition pos(FieldPosition::DONT_CARE);
97 fmtd = sdf->format(today, fmtd, pos);
98 logln("today: " + fmtd);
99
100 sdf->applyPattern("G yyyy DDD");
101 UnicodeString todayS;
102 todayS = sdf->format(today, todayS, pos);
103 logln("today: " + todayS);
104 //try {
105 today = sdf->parse(todayS, status);
106 failure(status, "sdf->parse");
107 logln((UnicodeString)"today date: " + today);
108 /*} catch(Exception e) {
109 logln("Error reparsing date: " + e.getMessage());
110 }*/
111
112 //try {
113 UnicodeString rt;
114 rt = sdf->format(sdf->parse(todayS, status), rt, pos);
115 failure(status, "sdf->parse");
116 logln("round trip: " + rt);
117 if(rt != todayS)
118 errln("Fail: Want " + todayS + " Got " + rt);
119 /*}
120 catch (ParseException e) {
121 errln("Fail: " + e);
122 e.printStackTrace();
123 }*/
124
125 delete sdf;
126}
127
128/**
129 * @bug 4052408
130 */
131void DateFormatRegressionTest::Test4052408(void)
132{
133
134 DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::SHORT,
135 DateFormat::SHORT, Locale::getUS());
73c04bcf
A
136 if (fmt == NULL) {
137 dataerrln("Error calling DateFormat::createDateTimeInstance");
138 return;
139 }
140
b75a7d8f
A
141 UDate dt = date(97, UCAL_MAY, 3, 8, 55);
142 UnicodeString str;
143 str = fmt->format(dt, str);
144 logln(str);
145
51004dcb
A
146 if(str != "5/3/97, 8:55 AM")
147 errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str);
b75a7d8f
A
148
149 UnicodeString expected[] = {
150 (UnicodeString) "", //"ERA_FIELD",
151 (UnicodeString) "97", //"YEAR_FIELD",
152 (UnicodeString) "5", //"MONTH_FIELD",
153 (UnicodeString) "3", //"DATE_FIELD",
154 (UnicodeString) "", //"HOUR_OF_DAY1_FIELD",
155 (UnicodeString) "", //"HOUR_OF_DAY0_FIELD",
156 (UnicodeString) "55", //"MINUTE_FIELD",
157 (UnicodeString) "", //"SECOND_FIELD",
158 (UnicodeString) "", //"MILLISECOND_FIELD",
159 (UnicodeString) "", //"DAY_OF_WEEK_FIELD",
160 (UnicodeString) "", //"DAY_OF_YEAR_FIELD",
161 (UnicodeString) "", //"DAY_OF_WEEK_IN_MONTH_FIELD",
162 (UnicodeString) "", //"WEEK_OF_YEAR_FIELD",
163 (UnicodeString) "", //"WEEK_OF_MONTH_FIELD",
164 (UnicodeString) "AM", //"AM_PM_FIELD",
165 (UnicodeString) "8", //"HOUR1_FIELD",
166 (UnicodeString) "", //"HOUR0_FIELD",
167 (UnicodeString) "" //"TIMEZONE_FIELD"
168 };
169
170 //Hashtable expected;// = new Hashtable();
171 //expected.put(new LongKey(DateFormat.MONTH_FIELD), "5");
172 //expected.put(new LongKey(DateFormat.DATE_FIELD), "3");
173 //expected.put(new LongKey(DateFormat.YEAR_FIELD), "97");
174 //expected.put(new LongKey(DateFormat.HOUR1_FIELD), "8");
175 //expected.put(new LongKey(DateFormat.MINUTE_FIELD), "55");
176 //expected.put(new LongKey(DateFormat.AM_PM_FIELD), "AM");
177
178 //StringBuffer buf = new StringBuffer();
179 UnicodeString fieldNames[] = {
180 (UnicodeString) "ERA_FIELD",
181 (UnicodeString) "YEAR_FIELD",
182 (UnicodeString) "MONTH_FIELD",
183 (UnicodeString) "DATE_FIELD",
184 (UnicodeString) "HOUR_OF_DAY1_FIELD",
185 (UnicodeString) "HOUR_OF_DAY0_FIELD",
186 (UnicodeString) "MINUTE_FIELD",
187 (UnicodeString) "SECOND_FIELD",
188 (UnicodeString) "MILLISECOND_FIELD",
189 (UnicodeString) "DAY_OF_WEEK_FIELD",
190 (UnicodeString) "DAY_OF_YEAR_FIELD",
191 (UnicodeString) "DAY_OF_WEEK_IN_MONTH_FIELD",
192 (UnicodeString) "WEEK_OF_YEAR_FIELD",
193 (UnicodeString) "WEEK_OF_MONTH_FIELD",
194 (UnicodeString) "AM_PM_FIELD",
195 (UnicodeString) "HOUR1_FIELD",
196 (UnicodeString) "HOUR0_FIELD",
197 (UnicodeString) "TIMEZONE_FIELD"
198 };
199
200 UBool pass = TRUE;
201 for(int i = 0; i <= 17; ++i) {
202 FieldPosition pos(i);
203 UnicodeString buf;
204 fmt->format(dt, buf, pos);
205 //char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
206 UnicodeString dst;
207 buf.extractBetween(pos.getBeginIndex(), pos.getEndIndex(), dst);
208 UnicodeString str(dst);
209 logln((UnicodeString)"" + i + (UnicodeString)": " + fieldNames[i] +
210 (UnicodeString)", \"" + str + (UnicodeString)"\", " +
211 pos.getBeginIndex() + (UnicodeString)", " +
212 pos.getEndIndex());
213 UnicodeString exp = expected[i];
214 if((exp.length() == 0 && str.length() == 0) || str == exp)
215 logln(" ok");
216 else {
217 errln(UnicodeString(" expected ") + exp);
218 pass = FALSE;
219 }
220
221 }
222 if( ! pass)
223 errln("Fail: FieldPosition not set right by DateFormat");
224
225 delete fmt;
226}
227
228/**
229 * @bug 4056591
230 * Verify the function of the [s|g]et2DigitYearStart() API.
231 */
232void DateFormatRegressionTest::Test4056591(void)
233{
234 UErrorCode status = U_ZERO_ERROR;
235
236 //try {
237 SimpleDateFormat *fmt = new SimpleDateFormat(UnicodeString("yyMMdd"), Locale::getUS(), status);
729e4ab9
A
238 if (failure(status, "new SimpleDateFormat", TRUE)) {
239 delete fmt;
240 return;
241 }
b75a7d8f
A
242 UDate start = date(1809-1900, UCAL_DECEMBER, 25);
243 fmt->set2DigitYearStart(start, status);
244 failure(status, "fmt->setTwoDigitStartDate");
245 if( (fmt->get2DigitYearStart(status) != start) || failure(status, "get2DigitStartDate"))
246 errln("get2DigitYearStart broken");
247 UDate dates [] = {
248 date(1809-1900, UCAL_DECEMBER, 25),
249 date(1909-1900, UCAL_DECEMBER, 24),
250 date(1809-1900, UCAL_DECEMBER, 26),
251 date(1861-1900, UCAL_DECEMBER, 25),
252 };
253
254 UnicodeString strings [] = {
255 (UnicodeString) "091225",
256 (UnicodeString) "091224",
257 (UnicodeString) "091226",
258 (UnicodeString) "611225"
259 };
260
261 /*Object[] DATA = {
262 "091225", new Date(1809-1900, Calendar.DECEMBER, 25),
263 "091224", new Date(1909-1900, Calendar.DECEMBER, 24),
264 "091226", new Date(1809-1900, Calendar.DECEMBER, 26),
265 "611225", new Date(1861-1900, Calendar.DECEMBER, 25),
266 };*/
267
268 for(int i = 0; i < 4; i++) {
269 UnicodeString s = strings[i];
270 UDate exp = dates[i];
271 UDate got = fmt->parse(s, status);
272 failure(status, "fmt->parse");
273 logln(s + " -> " + got + "; exp " + exp);
274 if(got != exp)
275 errln("set2DigitYearStart broken");
276 }
277 /*}
278 catch (ParseException e) {
279 errln("Fail: " + e);
280 e.printStackTrace();
281 }*/
282
283 delete fmt;
284}
285
286/**
287 * @bug 4059917
288 */
289void DateFormatRegressionTest::Test4059917(void)
290{
291 UErrorCode status = U_ZERO_ERROR;
292
293 SimpleDateFormat *fmt;
294 UnicodeString myDate;
295
296 fmt = new SimpleDateFormat( UnicodeString("yyyy/MM/dd"), status );
729e4ab9 297 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
298 myDate = "1997/01/01";
299 aux917( fmt, myDate );
300
301 delete fmt;
302 fmt = NULL;
303
304 fmt = new SimpleDateFormat( UnicodeString("yyyyMMdd"), status );
73c04bcf 305 if(failure(status, "new SimpleDateFormat")) return;
b75a7d8f
A
306 myDate = "19970101";
307 aux917( fmt, myDate );
308
309 delete fmt;
310}
311
312void DateFormatRegressionTest::aux917( SimpleDateFormat *fmt, UnicodeString& str ) {
313 //try {
314 UnicodeString pat;
315 pat = fmt->toPattern(pat);
316 logln( "==================" );
317 logln( "testIt: pattern=" + pat +
318 " string=" + str );
319
320
321 Formattable o;
322 //Object o;
323 ParsePosition pos(0);
324 fmt->parseObject( str, o, pos );
325 //logln( UnicodeString("Parsed object: ") + o );
326
327 UErrorCode status = U_ZERO_ERROR;
328 UnicodeString formatted;
329 FieldPosition poss(FieldPosition::DONT_CARE);
330 formatted = fmt->format( o, formatted, poss, status );
331 failure(status, "fmt->format");
332 logln( "Formatted string: " + formatted );
333 if( formatted != str)
334 errln("Fail: Want " + str + " Got " + formatted);
335 /*}
336 catch (ParseException e) {
337 errln("Fail: " + e);
338 e.printStackTrace();
339 }*/
340}
341
342/**
343 * @bug 4060212
344 */
345void DateFormatRegressionTest::Test4060212(void)
346{
347 UnicodeString dateString = "1995-040.05:01:29";
348
349 logln( "dateString= " + dateString );
350 logln("Using yyyy-DDD.hh:mm:ss");
351 UErrorCode status = U_ZERO_ERROR;
352 SimpleDateFormat *formatter = new SimpleDateFormat(UnicodeString("yyyy-DDD.hh:mm:ss"), status);
729e4ab9 353 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
354 ParsePosition pos(0);
355 UDate myDate = formatter->parse( dateString, pos );
356 UnicodeString myString;
357 DateFormat *fmt = DateFormat::createDateTimeInstance( DateFormat::FULL,
358 DateFormat::LONG);
73c04bcf
A
359 if (fmt == NULL) {
360 dataerrln("Error calling DateFormat::createDateTimeInstance");
361 delete formatter;
362 return;
363 }
364
b75a7d8f
A
365 myString = fmt->format( myDate, myString);
366 logln( myString );
367
368 Calendar *cal = new GregorianCalendar(status);
369 failure(status, "new GregorianCalendar");
370 cal->setTime(myDate, status);
371 failure(status, "cal->setTime");
372 if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get"))
373 errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) +
374 " Want 40");
375
46f4442e 376 // this is an odd usage of "ddd" and it doesn't
4388f060 377 // work now that date values are range checked per #3579.
b75a7d8f
A
378 logln("Using yyyy-ddd.hh:mm:ss");
379 delete formatter;
380 formatter = NULL;
381 formatter = new SimpleDateFormat(UnicodeString("yyyy-ddd.hh:mm:ss"), status);
73c04bcf 382 if(failure(status, "new SimpleDateFormat")) return;
b75a7d8f
A
383 pos.setIndex(0);
384 myDate = formatter->parse( dateString, pos );
385 myString = fmt->format( myDate, myString );
386 logln( myString );
387 cal->setTime(myDate, status);
388 failure(status, "cal->setTime");
389 if ((cal->get(UCAL_DAY_OF_YEAR, status) != 40) || failure(status, "cal->get"))
390 errln((UnicodeString) "Fail: Got " + cal->get(UCAL_DAY_OF_YEAR, status) +
391 " Want 40");
392
393 delete formatter;
394 delete fmt;
395 delete cal;
396}
397
398/**
399 * @bug 4061287
400 */
401void DateFormatRegressionTest::Test4061287(void)
402{
403 UErrorCode status = U_ZERO_ERROR;
404
405 SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("dd/MM/yyyy"), status);
729e4ab9
A
406 if (U_FAILURE(status)) {
407 dataerrln("Fail new SimpleDateFormat: %s", u_errorName(status));
408 delete df;
409 return;
b75a7d8f
A
410 }
411 failure(status, "new SimpleDateFormat");
412 //try {
4388f060
A
413 logln(UnicodeString("") + df->parse("35/01/1971", status));
414 failure(status, "df->parse(\"35/01/1971\")");
b75a7d8f
A
415 //logln(df.parse("35/01/1971").toString());
416 //}
417 /*catch (ParseException e) {
418 errln("Fail: " + e);
419 e.printStackTrace();
420 }*/
421 df->setLenient(FALSE);
422 UBool ok = FALSE;
423 //try {
4388f060 424 logln(UnicodeString("") + df->parse("35/01/1971", status));
b75a7d8f
A
425 if(U_FAILURE(status))
426 ok = TRUE;
427 //logln(df.parse("35/01/1971").toString());
428 //} catch (ParseException e) {ok=TRUE;}
429 if(!ok)
430 errln("Fail: Lenient not working");
431 delete df;
432}
433
434/**
435 * @bug 4065240
436 */
437void DateFormatRegressionTest::Test4065240(void)
438{
439 UDate curDate;
440 DateFormat *shortdate, *fulldate;
441 UnicodeString strShortDate, strFullDate;
442 Locale saveLocale = Locale::getDefault();
443 TimeZone *saveZone = TimeZone::createDefault();
444
445 UErrorCode status = U_ZERO_ERROR;
446 //try {
447 Locale *curLocale = new Locale("de","DE");
448 Locale::setDefault(*curLocale, status);
449 failure(status, "Locale::setDefault");
450 // {sfb} adoptDefault instead of setDefault
451 //TimeZone::setDefault(TimeZone::createTimeZone("EST"));
452 TimeZone::adoptDefault(TimeZone::createTimeZone("EST"));
453 curDate = date(98, 0, 1);
454 shortdate = DateFormat::createDateInstance(DateFormat::SHORT);
73c04bcf
A
455 if (shortdate == NULL){
456 dataerrln("Error calling DateFormat::createDateInstance");
457 return;
458 }
459
b75a7d8f 460 fulldate = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::LONG);
73c04bcf
A
461 if (fulldate == NULL){
462 dataerrln("Error calling DateFormat::createDateTimeInstance");
463 return;
464 }
b75a7d8f
A
465 strShortDate = "The current date (short form) is ";
466 UnicodeString temp;
467 temp = shortdate->format(curDate, temp);
468 strShortDate += temp;
469 strFullDate = "The current date (long form) is ";
470 UnicodeString temp2;
471 fulldate->format(curDate, temp2);
472 strFullDate += temp2;
473
474 logln(strShortDate);
475 logln(strFullDate);
476
477 // {sfb} What to do with resource bundle stuff?????
478
479 // Check to see if the resource is present; if not, we can't test
480 ResourceBundle *bundle = new ResourceBundle(
374ca955 481 NULL, *curLocale, status);
b75a7d8f
A
482 failure(status, "new ResourceBundle");
483 //(UnicodeString) "java.text.resources.DateFormatZoneData", curLocale);
484
485 // {sfb} API change to ResourceBundle -- add getLocale()
486 /*if (bundle->getLocale().getLanguage(temp) == UnicodeString("de")) {
487 // UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
488 if (!strFullDate.endsWith(UnicodeString("GMT-05:00")))
489 errln("Fail: Want GMT-05:00");
490 }
491 else {
492 logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
493 logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
494 }*/
495 //}
496 //finally {
497 Locale::setDefault(saveLocale, status);
498 failure(status, "Locale::setDefault");
499 TimeZone::setDefault(*saveZone);
500 //}
b75a7d8f
A
501 delete shortdate;
502 delete fulldate;
503 delete saveZone;
504 delete curLocale;
505 delete bundle;
506}
507
508/*
509 DateFormat.equals is too narrowly defined. As a result, MessageFormat
510 does not work correctly. DateFormat.equals needs to be written so
511 that the Calendar sub-object is not compared using Calendar.equals,
512 but rather compared for equivalency. This may necessitate adding a
513 (package private) method to Calendar to test for equivalency.
514
515 Currently this bug breaks MessageFormat.toPattern
516 */
517/**
518 * @bug 4071441
519 */
520void DateFormatRegressionTest::Test4071441(void)
521{
522 DateFormat *fmtA = DateFormat::createInstance();
523 DateFormat *fmtB = DateFormat::createInstance();
73c04bcf
A
524
525 if (fmtA == NULL || fmtB == NULL){
526 dataerrln("Error calling DateFormat::createInstance");
527 delete fmtA;
528 delete fmtB;
529 return;
530 }
531
b75a7d8f
A
532 // {sfb} Is it OK to cast away const here?
533 Calendar *calA = (Calendar*) fmtA->getCalendar();
534 Calendar *calB = (Calendar*) fmtB->getCalendar();
535 if(!calA || !calB) {
536 errln("Couldn't get proper calendars, exiting");
537 delete fmtA;
538 delete fmtB;
539 return;
540 }
541 UDate epoch = date(0, 0, 0);
542 UDate xmas = date(61, UCAL_DECEMBER, 25);
543
544 UErrorCode status = U_ZERO_ERROR;
545 calA->setTime(epoch, status);
546 failure(status, "calA->setTime");
547 calB->setTime(epoch, status);
548 failure(status, "calB->setTime");
549 if (*calA != *calB)
550 errln("Fail: Can't complete test; Calendar instances unequal");
551 if (*fmtA != *fmtB)
552 errln("Fail: DateFormat unequal when Calendars equal");
553 calB->setTime(xmas, status);
554 failure(status, "calB->setTime");
555 if (*calA == *calB)
556 errln("Fail: Can't complete test; Calendar instances equal");
557 if (*fmtA != *fmtB)
558 errln("Fail: DateFormat unequal when Calendars equivalent");
559
560 logln("DateFormat.equals ok");
561
562 delete fmtA;
563 delete fmtB;
564}
565
566/* The java.text.DateFormat.parse(String) method expects for the
567 US locale a string formatted according to mm/dd/yy and parses it
568 correctly.
569
46f4442e 570 When given a string mm/dd/yyyy [sic] it only parses up to the first
b75a7d8f
A
571 two y's, typically resulting in a date in the year 1919.
572
573 Please extend the parsing method(s) to handle strings with
574 four-digit year values (probably also applicable to various
575 other locales. */
576/**
577 * @bug 4073003
578 */
579void DateFormatRegressionTest::Test4073003(void)
580{
581 //try {
582 UErrorCode ec = U_ZERO_ERROR;
46f4442e 583 SimpleDateFormat fmt("MM/dd/yy", Locale::getUK(), ec);
b75a7d8f 584 if (U_FAILURE(ec)) {
729e4ab9 585 dataerrln("FAIL: SimpleDateFormat constructor - %s", u_errorName(ec));
b75a7d8f
A
586 return;
587 }
588 UnicodeString tests [] = {
589 (UnicodeString) "12/25/61",
590 (UnicodeString) "12/25/1961",
591 (UnicodeString) "4/3/2010",
592 (UnicodeString) "4/3/10"
593 };
594 UErrorCode status = U_ZERO_ERROR;
595 for(int i= 0; i < 4; i+=2) {
596 UDate d = fmt.parse(tests[i], status);
597 failure(status, "fmt.parse");
598 UDate dd = fmt.parse(tests[i+1], status);
599 failure(status, "fmt.parse");
600 UnicodeString s;
601 s = fmt.format(d, s);
602 UnicodeString ss;
603 ss = fmt.format(dd, ss);
604 if (d != dd)
605 errln((UnicodeString) "Fail: " + d + " != " + dd);
606 if (s != ss)
607 errln((UnicodeString)"Fail: " + s + " != " + ss);
608 logln("Ok: " + s + " " + d);
609 }
610}
611
612/**
613 * @bug 4089106
614 */
615void DateFormatRegressionTest::Test4089106(void)
616{
617 TimeZone *def = TimeZone::createDefault();
618 //try {
619 TimeZone *z = new SimpleTimeZone((int)(1.25 * 3600000), "FAKEZONE");
620 TimeZone::setDefault(*z);
621 UErrorCode status = U_ZERO_ERROR;
622 SimpleDateFormat *f = new SimpleDateFormat(status);
623 if(U_FAILURE(status)) {
729e4ab9 624 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
b75a7d8f
A
625 delete f;
626 delete def;
627 delete z;
628 return;
629 }
630 failure(status, "new SimpleDateFormat");
631 if (f->getTimeZone()!= *z)
632 errln("Fail: SimpleTimeZone should use TimeZone.getDefault()");
633
634 //}
635 //finally {
636 TimeZone::setDefault(*def);
637 //}
638
639 delete z;
640 delete f;
641 delete def;
642}
643
644/**
645 * @bug 4100302
646 */
647
648// {sfb} not applicable in C++??
649
650void DateFormatRegressionTest::Test4100302(void)
651{
652/* Locale locales [] = {
653 Locale::CANADA,
654 Locale::CANADA_FRENCH,
655 Locale::CHINA,
656 Locale::CHINESE,
657 Locale::ENGLISH,
658 Locale::FRANCE,
659 Locale::FRENCH,
660 Locale::GERMAN,
661 Locale::GERMANY,
662 Locale::ITALIAN,
663 Locale::ITALY,
664 Locale::JAPAN,
665 Locale::JAPANESE,
666 Locale::KOREA,
667 Locale::KOREAN,
668 Locale::PRC,
669 Locale::SIMPLIFIED_CHINESE,
670 Locale::TAIWAN,
671 Locale::TRADITIONAL_CHINESE,
672 Locale::UK,
673 Locale::US
674 };
675 //try {
676 UBool pass = TRUE;
677 for(int i = 0; i < 21; i++) {
678
679 Format *format = DateFormat::createDateTimeInstance(DateFormat::FULL,
680 DateFormat::FULL, locales[i]);
681 byte[] bytes;
682
683 ByteArrayOutputStream baos = new ByteArrayOutputStream();
684 ObjectOutputStream oos = new ObjectOutputStream(baos);
685
686 oos.writeObject(format);
687 oos.flush();
688
689 baos.close();
690 bytes = baos.toByteArray();
691
692 ObjectInputStream ois =
693 new ObjectInputStream(new ByteArrayInputStream(bytes));
694
695 if (!format.equals(ois.readObject())) {
696 pass = FALSE;
697 logln("DateFormat instance for locale " +
698 locales[i] + " is incorrectly serialized/deserialized.");
699 } else {
700 logln("DateFormat instance for locale " +
701 locales[i] + " is OKAY.");
702 }
703 }
704 if (!pass) errln("Fail: DateFormat serialization/equality bug");
705 }
706 catch (IOException e) {
707 errln("Fail: " + e);
708 e.printStackTrace();
709 }
710 catch (ClassNotFoundException e) {
711 errln("Fail: " + e);
712 e.printStackTrace();
713 }
714*/}
715
716/**
717 * @bug 4101483
718 */
719void DateFormatRegressionTest::Test4101483(void)
720{
721 UErrorCode status = U_ZERO_ERROR;
722 SimpleDateFormat *sdf = new SimpleDateFormat(UnicodeString("z"), Locale::getUS(), status);
729e4ab9 723 if (failure(status, "new SimpleDateFormat", TRUE)) return;
374ca955 724 FieldPosition fp(UDAT_TIMEZONE_FIELD);
b75a7d8f
A
725 //Date d = date(9234567890L);
726 UDate d = 9234567890.0;
727 //StringBuffer buf = new StringBuffer("");
728 UnicodeString buf;
729 sdf->format(d, buf, fp);
730 //logln(sdf.format(d, buf, fp).toString());
731 logln(dateToString(d) + " => " + buf);
51004dcb
A
732 logln(UnicodeString("beginIndex = ") + fp.getBeginIndex());
733 logln(UnicodeString("endIndex = ") + fp.getEndIndex());
b75a7d8f
A
734 if (fp.getBeginIndex() == fp.getEndIndex())
735 errln("Fail: Empty field");
736
737 delete sdf;
738}
739
740/**
741 * @bug 4103340
742 * @bug 4138203
743 * This bug really only works in Locale.US, since that's what the locale
744 * used for Date.toString() is. Bug 4138203 reports that it fails on Korean
745 * NT; it would actually have failed on any non-US locale. Now it should
746 * work on all locales.
747 */
748void DateFormatRegressionTest::Test4103340(void)
749{
750 UErrorCode status = U_ZERO_ERROR;
751
752 // choose a date that is the FIRST of some month
753 // and some arbitrary time
754 UDate d = date(97, 3, 1, 1, 1, 1);
755 SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("MMMM"), Locale::getUS(), status);
729e4ab9 756 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
757
758 UnicodeString s;
759 s = dateToString(d, s);
760 UnicodeString s2;
761 FieldPosition pos(FieldPosition::DONT_CARE);
762 s2 = df->format(d, s2, pos);
763 logln("Date=" + s);
764 logln("DF=" + s2);
765 UnicodeString substr;
766 s2.extract(0,2, substr);
767 if (s.indexOf(substr) == -1)
768 errln("Months should match");
769
770 delete df;
771}
772
773/**
774 * @bug 4103341
775 */
776void DateFormatRegressionTest::Test4103341(void)
777{
778 TimeZone *saveZone =TimeZone::createDefault();
779 //try {
780
781 // {sfb} changed from setDefault to adoptDefault
782 TimeZone::adoptDefault(TimeZone::createTimeZone("CST"));
783 UErrorCode status = U_ZERO_ERROR;
784 SimpleDateFormat *simple = new SimpleDateFormat(UnicodeString("MM/dd/yyyy HH:mm"), status);
785 if(U_FAILURE(status)) {
729e4ab9 786 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
b75a7d8f
A
787 delete simple;
788 return;
789 }
790 failure(status, "new SimpleDateFormat");
791 TimeZone *temp = TimeZone::createDefault();
792 if(simple->getTimeZone() != *temp)
793 errln("Fail: SimpleDateFormat not using default zone");
794 //}
795 //finally {
796 TimeZone::adoptDefault(saveZone);
797 //}
798
799 delete temp;
800 delete simple;
801}
802
803/**
804 * @bug 4104136
805 */
806void DateFormatRegressionTest::Test4104136(void)
807{
808 UErrorCode status = U_ZERO_ERROR;
809 SimpleDateFormat *sdf = new SimpleDateFormat(status);
810 if(U_FAILURE(status)) {
729e4ab9 811 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
b75a7d8f
A
812 delete sdf;
813 return;
814 }
73c04bcf 815 if(failure(status, "new SimpleDateFormat")) return;
b75a7d8f
A
816 UnicodeString pattern = "'time' hh:mm";
817 sdf->applyPattern(pattern);
818 logln("pattern: \"" + pattern + "\"");
819
820 UnicodeString strings [] = {
821 (UnicodeString)"time 10:30",
822 (UnicodeString) "time 10:x",
823 (UnicodeString) "time 10x"
824 };
825
826 ParsePosition ppos [] = {
827 ParsePosition(10),
828 ParsePosition(0),
829 ParsePosition(0)
830 };
831
832 UDate dates [] = {
833 date(70, UCAL_JANUARY, 1, 10, 30),
834 -1,
835 -1
836 };
837
838 /*Object[] DATA = {
839 "time 10:30", new ParsePosition(10), new Date(70, Calendar.JANUARY, 1, 10, 30),
840 "time 10:x", new ParsePosition(0), null,
841 "time 10x", new ParsePosition(0), null,
842 };*/
843
844 for(int i = 0; i < 3; i++) {
845 UnicodeString text = strings[i];
846 ParsePosition finish = ppos[i];
847 UDate exp = dates[i];
848
849 ParsePosition pos(0);
850 UDate d = sdf->parse(text, pos);
851 logln(" text: \"" + text + "\"");
852 logln(" index: %d", pos.getIndex());
853 logln((UnicodeString) " result: " + d);
854 if(pos.getIndex() != finish.getIndex())
51004dcb 855 errln(UnicodeString("Fail: Expected pos ") + finish.getIndex());
b75a7d8f
A
856 if (! ((d == 0 && exp == -1) || (d == exp)))
857 errln((UnicodeString) "Fail: Expected result " + exp);
858 }
859
860 delete sdf;
861}
862
863/**
864 * @bug 4104522
865 * CANNOT REPRODUCE
866 * According to the bug report, this test should throw a
867 * StringIndexOutOfBoundsException during the second parse. However,
868 * this is not seen.
869 */
870void DateFormatRegressionTest::Test4104522(void)
871{
872 UErrorCode status = U_ZERO_ERROR;
873
874 SimpleDateFormat *sdf = new SimpleDateFormat(status);
875 if(U_FAILURE(status)) {
729e4ab9 876 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
b75a7d8f
A
877 delete sdf;
878 return;
879 }
880 failure(status, "new SimpleDateFormat");
881 UnicodeString pattern = "'time' hh:mm";
882 sdf->applyPattern(pattern);
883 logln("pattern: \"" + pattern + "\"");
884
885 // works correctly
886 ParsePosition pp(0);
887 UnicodeString text = "time ";
888 UDate dt = sdf->parse(text, pp);
889 logln(" text: \"" + text + "\"" +
890 " date: " + dt);
891
892 // works wrong
893 pp.setIndex(0);
894 text = "time";
895 dt = sdf->parse(text, pp);
896 logln(" text: \"" + text + "\"" +
897 " date: " + dt);
898
899 delete sdf;
900}
901
902/**
903 * @bug 4106807
904 */
905void DateFormatRegressionTest::Test4106807(void)
906{
907 UDate dt;
908 DateFormat *df = DateFormat::createDateTimeInstance();
909
910 UErrorCode status = U_ZERO_ERROR;
911 SimpleDateFormat *sdfs [] = {
912 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss"), status),
913 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'Z'"), status),
914 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss''"), status),
915 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'a''a'"), status),
916 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss %"), status)
917 };
918 if(U_FAILURE(status)) {
729e4ab9 919 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status));
b75a7d8f
A
920 delete sdfs[0];
921 delete sdfs[1];
922 delete sdfs[2];
923 delete sdfs[3];
924 delete sdfs[4];
925 return;
926 }
927
928 failure(status, "new SimpleDateFormat");
929
930 UnicodeString strings [] = {
931 (UnicodeString) "19980211140000",
932 (UnicodeString) "19980211140000",
933 (UnicodeString) "19980211140000",
934 (UnicodeString) "19980211140000a",
935 (UnicodeString) "19980211140000 "
936 };
937
938 /*Object[] data = {
939 new SimpleDateFormat("yyyyMMddHHmmss"), "19980211140000",
940 new SimpleDateFormat("yyyyMMddHHmmss'Z'"), "19980211140000",
941 new SimpleDateFormat("yyyyMMddHHmmss''"), "19980211140000",
942 new SimpleDateFormat("yyyyMMddHHmmss'a''a'"), "19980211140000a",
943 new SimpleDateFormat("yyyyMMddHHmmss %"), "19980211140000 ",
944 };*/
945 GregorianCalendar *gc = new GregorianCalendar(status);
946 failure(status, "new GregorianCalendar");
947 TimeZone *timeZone = TimeZone::createDefault();
948
949 TimeZone *gmt = timeZone->clone();
950
951 gmt->setRawOffset(0);
952
953 for(int32_t i = 0; i < 5; i++) {
954 SimpleDateFormat *format = sdfs[i];
955 UnicodeString dateString = strings[i];
956 //try {
957 format->setTimeZone(*gmt);
958 dt = format->parse(dateString, status);
959 // {sfb} some of these parses will fail purposely
960 if(U_FAILURE(status))
961 break;
962 status = U_ZERO_ERROR;
963 UnicodeString fmtd;
964 FieldPosition pos(FieldPosition::DONT_CARE);
965 fmtd = df->format(dt, fmtd, pos);
966 logln(fmtd);
967 //logln(df->format(dt));
968 gc->setTime(dt, status);
969 failure(status, "gc->getTime");
970 logln(UnicodeString("") + gc->get(UCAL_ZONE_OFFSET, status));
971 failure(status, "gc->get");
972 UnicodeString s;
973 s = format->format(dt, s, pos);
974 logln(s);
975 /*}
976 catch (ParseException e) {
977 logln("No way Jose");
978 }*/
979 }
980
981 delete timeZone;
982 delete df;
983 for(int32_t j = 0; j < 5; j++)
984 delete sdfs [j];
985 delete gc;
986 delete gmt;
987}
988
989/*
990 Synopsis: Chinese time zone CTT is not recogonized correctly.
991 Description: Platform Chinese Windows 95 - ** Time zone set to CST **
992 */
993/**
994 * @bug 4108407
995 */
996
997// {sfb} what to do with this one ??
998void DateFormatRegressionTest::Test4108407(void)
999{
1000 /*long l = System.currentTimeMillis();
1001 logln("user.timezone = " + System.getProperty("user.timezone", "?"));
1002 logln("Time Zone :" +
1003 DateFormat.getDateInstance().getTimeZone().getID());
1004 logln("Default format :" +
1005 DateFormat.getDateInstance().format(new Date(l)));
1006 logln("Full format :" +
1007 DateFormat.getDateInstance(DateFormat.FULL).format(new
1008 Date(l)));
1009 logln("*** Set host TZ to CST ***");
1010 logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");*/
1011}
1012
1013/**
1014 * @bug 4134203
1015 * SimpleDateFormat won't parse "GMT"
1016 */
1017void DateFormatRegressionTest::Test4134203(void)
1018{
1019 UErrorCode status = U_ZERO_ERROR;
1020 UnicodeString dateFormat = "MM/dd/yy HH:mm:ss zzz";
1021 SimpleDateFormat *fmt = new SimpleDateFormat(dateFormat, status);
729e4ab9 1022 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
1023 ParsePosition p0(0);
1024 UDate d = fmt->parse("01/22/92 04:52:00 GMT", p0);
1025 logln(dateToString(d));
1026 if(p0 == ParsePosition(0))
1027 errln("Fail: failed to parse 'GMT'");
1028 // In the failure case an exception is thrown by parse();
1029 // if no exception is thrown, the test passes.
1030
1031 delete fmt;
1032}
1033
1034/**
1035 * @bug 4151631
1036 * SimpleDateFormat incorrect handling of 2 single quotes in format()
1037 */
1038void DateFormatRegressionTest::Test4151631(void)
1039{
1040 UnicodeString pattern = "'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
1041 logln("pattern=" + pattern);
1042 UErrorCode status = U_ZERO_ERROR;
1043 SimpleDateFormat *format = new SimpleDateFormat(pattern, Locale::getUS(), status);
729e4ab9 1044 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
1045 UnicodeString result;
1046 FieldPosition pos(FieldPosition::DONT_CARE);
1047 result = format->format(date(1998-1900, UCAL_JUNE, 30, 13, 30, 0), result, pos);
1048 if (result != "TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')") {
1049 errln("Fail: result=" + result);
1050 }
1051 else {
1052 logln("Pass: result=" + result);
1053 }
1054
1055 delete format;
1056}
1057
1058/**
1059 * @bug 4151706
1060 * 'z' at end of date format throws index exception in SimpleDateFormat
1061 * CANNOT REPRODUCE THIS BUG ON 1.2FCS
1062 */
1063void DateFormatRegressionTest::Test4151706(void)
1064{
1065 UnicodeString dateString("Thursday, 31-Dec-98 23:00:00 GMT");
1066 UErrorCode status = U_ZERO_ERROR;
1067 SimpleDateFormat fmt(UnicodeString("EEEE, dd-MMM-yy HH:mm:ss z"), Locale::getUS(), status);
729e4ab9 1068 if (failure(status, "new SimpleDateFormat", TRUE)) return;
b75a7d8f
A
1069 //try {
1070 UDate d = fmt.parse(dateString, status);
1071 failure(status, "fmt->parse");
1072 // {sfb} what about next two lines?
1073 //if (d.getTime() != Date.UTC(1998-1900, Calendar.DECEMBER, 31, 23, 0, 0))
1074 // errln("Incorrect value: " + d);
1075 /*} catch (Exception e) {
1076 errln("Fail: " + e);
1077 }*/
1078 UnicodeString temp;
f3c0d7a5 1079 FieldPosition pos(FieldPosition::DONT_CARE);
b75a7d8f
A
1080 logln(dateString + " -> " + fmt.format(d, temp, pos));
1081}
1082
1083/**
1084 * @bug 4162071
1085 * Cannot reproduce this bug under 1.2 FCS -- it may be a convoluted duplicate
1086 * of some other bug that has been fixed.
1087 */
1088void
1089DateFormatRegressionTest::Test4162071(void)
1090{
1091 UnicodeString dateString("Thu, 30-Jul-1999 11:51:14 GMT");
1092 UnicodeString format("EEE', 'dd-MMM-yyyy HH:mm:ss z"); // RFC 822/1123
1093 UErrorCode status = U_ZERO_ERROR;
1094 SimpleDateFormat df(format, Locale::getUS(), status);
73c04bcf 1095 if(U_FAILURE(status)) {
729e4ab9 1096 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
73c04bcf
A
1097 return;
1098 }
b75a7d8f
A
1099
1100 //try {
1101 UDate x = df.parse(dateString, status);
1102 if(U_SUCCESS(status))
1103 logln("Parse format \"" + format + "\" ok");
1104 else
1105 errln("Parse format \"" + format + "\" failed.");
1106 UnicodeString temp;
f3c0d7a5 1107 FieldPosition pos(FieldPosition::DONT_CARE);
b75a7d8f
A
1108 logln(dateString + " -> " + df.format(x, temp, pos));
1109 //} catch (Exception e) {
1110 // errln("Parse format \"" + format + "\" failed.");
1111 //}
1112}
1113
1114/**
1115 * DateFormat shouldn't parse year "-1" as a two-digit year (e.g., "-1" -> 1999).
1116 */
1117void DateFormatRegressionTest::Test4182066(void) {
1118 UErrorCode status = U_ZERO_ERROR;
1119 SimpleDateFormat fmt("MM/dd/yy", Locale::getUS(), status);
1120 SimpleDateFormat dispFmt("MMM dd yyyy GG", Locale::getUS(), status);
1121 if (U_FAILURE(status)) {
729e4ab9 1122 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
b75a7d8f
A
1123 return;
1124 }
1125
1126 /* We expect 2-digit year formats to put 2-digit years in the right
1127 * window. Out of range years, that is, anything less than "00" or
1128 * greater than "99", are treated as literal years. So "1/2/3456"
1129 * becomes 3456 AD. Likewise, "1/2/-3" becomes -3 AD == 2 BC.
1130 */
1131 const char* STRINGS[] = {
1132 "02/29/00",
1133 "01/23/01",
1134 "04/05/-1",
1135 "01/23/-9",
1136 "11/12/1314",
1137 "10/31/1",
1138 "09/12/+1",
1139 "09/12/001",
1140 };
2ca993e8 1141 int32_t STRINGS_COUNT = UPRV_LENGTHOF(STRINGS);
b75a7d8f
A
1142 UDate FAIL_DATE = (UDate) 0;
1143 UDate DATES[] = {
1144 date(2000-1900, UCAL_FEBRUARY, 29),
1145 date(2001-1900, UCAL_JANUARY, 23),
1146 date( -1-1900, UCAL_APRIL, 5),
1147 date( -9-1900, UCAL_JANUARY, 23),
1148 date(1314-1900, UCAL_NOVEMBER, 12),
1149 date( 1-1900, UCAL_OCTOBER, 31),
1150 FAIL_DATE, // "+1" isn't recognized by US NumberFormat
1151 date( 1-1900, UCAL_SEPTEMBER,12),
1152 };
1153
1154 UnicodeString out;
1155 UBool pass = TRUE;
1156 for (int32_t i=0; i<STRINGS_COUNT; ++i) {
1157 UnicodeString str(STRINGS[i]);
1158 UDate expected = DATES[i];
1159 status = U_ZERO_ERROR;
1160 UDate actual = fmt.parse(str, status);
1161 if (U_FAILURE(status)) {
1162 actual = FAIL_DATE;
1163 }
1164 UnicodeString actStr;
1165 if (actual == FAIL_DATE) {
1166 actStr.append("null");
1167 } else {
1168 // Yuck: See j25
1169 ((DateFormat*)&dispFmt)->format(actual, actStr);
1170 }
1171
1172 if (expected == actual) {
1173 out.append(str + " => " + actStr + "\n");
1174 } else {
1175 UnicodeString expStr;
1176 if (expected == FAIL_DATE) {
1177 expStr.append("null");
1178 } else {
1179 // Yuck: See j25
1180 ((DateFormat*)&dispFmt)->format(expected, expStr);
1181 }
1182 out.append("FAIL: " + str + " => " + actStr
1183 + ", expected " + expStr + "\n");
1184 pass = FALSE;
1185 }
1186 }
1187 if (pass) {
1188 log(out);
1189 } else {
1190 err(out);
1191 }
1192}
1193
1194/**
1195 * j32 {JDK Bug 4210209 4209272}
1196 * DateFormat cannot parse Feb 29 2000 when setLenient(false)
1197 */
1198void
1199DateFormatRegressionTest::Test4210209(void) {
1200 UErrorCode status = U_ZERO_ERROR;
1201 UnicodeString pattern("MMM d, yyyy");
1202 SimpleDateFormat sfmt(pattern, Locale::getUS(), status);
1203 SimpleDateFormat sdisp("MMM dd yyyy GG", Locale::getUS(), status);
1204 DateFormat& fmt = *(DateFormat*)&sfmt; // Yuck: See j25
1205 DateFormat& disp = *(DateFormat*)&sdisp; // Yuck: See j25
1206 if (U_FAILURE(status)) {
729e4ab9 1207 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status));
b75a7d8f
A
1208 return;
1209 }
1210 Calendar* calx = (Calendar*)fmt.getCalendar(); // cast away const!
1211 calx->setLenient(FALSE);
1212 UDate d = date(2000-1900, UCAL_FEBRUARY, 29);
1213 UnicodeString s, ss;
1214 fmt.format(d, s);
1215 logln(disp.format(d, ss.remove()) + " f> " + pattern +
1216 " => \"" + s + "\"");
1217 ParsePosition pos(0);
1218 d = fmt.parse(s, pos);
1219 logln(UnicodeString("\"") + s + "\" p> " + pattern +
1220 " => " + disp.format(d, ss.remove()));
1221 logln(UnicodeString("Parse pos = ") + pos.getIndex() +
1222 ", error pos = " + pos.getErrorIndex());
1223 if (pos.getErrorIndex() != -1) {
1224 errln(UnicodeString("FAIL: Error index should be -1"));
1225 }
1226
1227 // The underlying bug is in GregorianCalendar. If the following lines
1228 // succeed, the bug is fixed. If the bug isn't fixed, they will throw
1229 // an exception.
1230 GregorianCalendar cal(status);
1231 if (U_FAILURE(status)) {
1232 errln("FAIL: Unable to create Calendar");
1233 return;
1234 }
1235 cal.clear();
1236 cal.setLenient(FALSE);
1237 cal.set(2000, UCAL_FEBRUARY, 29); // This should work!
1238 logln(UnicodeString("Attempt to set Calendar to Feb 29 2000: ") +
1239 disp.format(cal.getTime(status), ss.remove()));
1240 if (U_FAILURE(status)) {
1241 errln("FAIL: Unable to set Calendar to Feb 29 2000");
1242 }
1243}
1244
1245void DateFormatRegressionTest::Test714(void)
1246{
1247 //try {
1248 UDate d(978103543000.);
1249 DateFormat *fmt = DateFormat::createDateTimeInstance(DateFormat::NONE,
1250 DateFormat::MEDIUM,
1251 Locale::getUS());
73c04bcf
A
1252 if (fmt == NULL) {
1253 dataerrln("Error calling DateFormat::createDateTimeInstance");
1254 return;
1255 }
1256
b75a7d8f
A
1257 UnicodeString s;
1258 UnicodeString tests =
1259 (UnicodeString) "7:25:43 AM" ;
1260 UErrorCode status = U_ZERO_ERROR;
1261 fmt->format (d,s);
1262 if(U_FAILURE(status))
1263 {
1264 errln((UnicodeString) "Fail, errmsg " + u_errorName(status));
1265 return;
1266 }
1267
1268 if(s != tests)
1269 {
1270 errln((UnicodeString) "Fail: " + s + " != " + tests);
1271 }
1272 else
1273 {
1274 logln("OK: " + s + " == " + tests);
1275 }
1276
1277 delete fmt;
1278}
1279
1280class Test1684Data {
1281public:
1282 int32_t year;
1283 int32_t month;
1284 int32_t date;
1285 int32_t womyear;
1286 int32_t wommon;
1287 int32_t wom;
1288 int32_t dow;
1289 UnicodeString data;
1290 UnicodeString normalized;
1291
1292 Test1684Data(int32_t xyear, int32_t xmonth, int32_t xdate,
1293 int32_t xwomyear, int32_t xwommon, int32_t xwom, int32_t xdow,
1294 const char *xdata, const char *xnormalized) :
1295 year(xyear),
1296 month(xmonth-1),
1297 date(xdate),
1298 womyear(xwomyear),
1299 wommon(xwommon-1),
1300 wom(xwom),
1301 dow(xdow),
1302 data(xdata,""),
1303 normalized((xnormalized==NULL)?xdata:xnormalized,"")
1304 { }
1305};
1306
1307void DateFormatRegressionTest::Test1684(void)
1308{
1309 // July 2001 August 2001 January 2002
1310 // Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1311 // 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4 5
1312 // 8 9 10 11 12 13 14 5 6 7 8 9 10 11 6 7 8 9 10 11 12
1313 // 15 16 17 18 19 20 21 12 13 14 15 16 17 18 13 14 15 16 17 18 19
1314 // 22 23 24 25 26 27 28 19 20 21 22 23 24 25 20 21 22 23 24 25 26
1315 // 29 30 31 26 27 28 29 30 31 27 28 29 30 31
1316 Test1684Data *tests[] = {
1317 new Test1684Data(2001, 8, 6, 2001,8,2,UCAL_MONDAY, "2001 08 02 Mon", NULL),
1318 new Test1684Data(2001, 8, 7, 2001,8,2,UCAL_TUESDAY, "2001 08 02 Tue", NULL),
1319 new Test1684Data(2001, 8, 5,/*12,*/ 2001,8,2,UCAL_SUNDAY, "2001 08 02 Sun", NULL),
1320 new Test1684Data(2001, 8,6, /*7, 30,*/ 2001,7,6,UCAL_MONDAY, "2001 07 06 Mon", "2001 08 02 Mon"),
1321 new Test1684Data(2001, 8,7, /*7, 31,*/ 2001,7,6,UCAL_TUESDAY, "2001 07 06 Tue", "2001 08 02 Tue"),
1322 new Test1684Data(2001, 8, 5, 2001,7,6,UCAL_SUNDAY, "2001 07 06 Sun", "2001 08 02 Sun"),
1323 new Test1684Data(2001, 7, 30, 2001,8,1,UCAL_MONDAY, "2001 08 01 Mon", "2001 07 05 Mon"),
1324 new Test1684Data(2001, 7, 31, 2001,8,1,UCAL_TUESDAY, "2001 08 01 Tue", "2001 07 05 Tue"),
1325 new Test1684Data(2001, 7,29, /*8, 5,*/ 2001,8,1,UCAL_SUNDAY, "2001 08 01 Sun", "2001 07 05 Sun"),
1326 new Test1684Data(2001, 12, 31, 2001,12,6,UCAL_MONDAY, "2001 12 06 Mon", NULL),
1327 new Test1684Data(2002, 1, 1, 2002,1,1,UCAL_TUESDAY, "2002 01 01 Tue", NULL),
1328 new Test1684Data(2002, 1, 2, 2002,1,1,UCAL_WEDNESDAY, "2002 01 01 Wed", NULL),
1329 new Test1684Data(2002, 1, 3, 2002,1,1,UCAL_THURSDAY, "2002 01 01 Thu", NULL),
1330 new Test1684Data(2002, 1, 4, 2002,1,1,UCAL_FRIDAY, "2002 01 01 Fri", NULL),
1331 new Test1684Data(2002, 1, 5, 2002,1,1,UCAL_SATURDAY, "2002 01 01 Sat", NULL),
1332 new Test1684Data(2001,12,30, /*2002, 1, 6,*/ 2002,1,1,UCAL_SUNDAY, "2002 01 01 Sun", "2001 12 06 Sun")
1333 };
1334
2ca993e8 1335#define kTest1684Count UPRV_LENGTHOF(tests)
b75a7d8f
A
1336
1337 int32_t pass = 0, error = 0, warning = 0;
1338 int32_t i;
1339
1340 UErrorCode status = U_ZERO_ERROR;
1341 UnicodeString pattern("yyyy MM WW EEE","");
1342 Calendar *cal = new GregorianCalendar(status);
1343 SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
73c04bcf
A
1344 if (U_FAILURE(status)) {
1345 dataerrln("Error constructing SimpleDateFormat");
1346 for(i=0;i<kTest1684Count;i++) {
1347 delete tests[i];
1348 }
1349 delete cal;
1350 delete sdf;
1351 return;
1352 }
b75a7d8f
A
1353 cal->setFirstDayOfWeek(UCAL_SUNDAY);
1354 cal->setMinimalDaysInFirstWeek(1);
1355
1356 sdf->adoptCalendar(cal);
1357
1358 cal = sdf->getCalendar()->clone(); // sdf may have deleted calendar
1359
1360 if(!cal || !sdf || U_FAILURE(status)) {
1361 errln(UnicodeString("Error setting up test: ") + u_errorName(status));
1362 }
1363
1364 for (i = 0; i < kTest1684Count; ++i) {
1365 Test1684Data &test = *(tests[i]);
1366 logln(UnicodeString("#") + i + UnicodeString("\n-----\nTesting round trip of ") + test.year +
1367 " " + (test.month + 1) +
1368 " " + test.date +
1369 " (written as) " + test.data);
1370
1371 cal->clear();
1372 cal->set(test.year, test.month, test.date);
1373 UDate ms = cal->getTime(status);
1374
1375 cal->clear();
1376 cal->set(UCAL_YEAR, test.womyear);
1377 cal->set(UCAL_MONTH, test.wommon);
1378 cal->set(UCAL_WEEK_OF_MONTH, test.wom);
1379 cal->set(UCAL_DAY_OF_WEEK, test.dow);
1380 UDate ms2 = cal->getTime(status);
1381
1382 if (ms2 != ms) {
1383 errln((UnicodeString)"\nError: GregorianUCAL_DOM gave " + ms +
1384 "\n GregorianUCAL_WOM gave " + ms2);
1385 error++;
1386 } else {
1387 pass++;
1388 }
1389
1390 ms2 = sdf->parse(test.data, status);
1391 if(U_FAILURE(status)) {
1392 errln("parse exception: " + UnicodeString(u_errorName(status)));
1393 }
1394
1395 if (ms2!=ms) {
1396 errln((UnicodeString)"\nError: GregorianCalendar gave " + ms +
1397 "\n SimpleDateFormat.parse gave " + ms2);
1398 error++;
1399 } else {
1400 pass++;
1401 }
1402
1403 UnicodeString result;
1404 sdf->format(ms, result);
1405 if (result != test.normalized) {
1406 errln("\nWarning: format of '" + test.data + "' gave" +
1407 "\n '" + result + "'" +
1408 "\n expected '" + test.normalized + "'");
1409 warning++;
1410 } else {
1411 pass++;
1412 }
1413
1414 UDate ms3;
1415 ms3 = sdf->parse(result, status);
1416 if(U_FAILURE(status)) {
1417 errln("parse exception 2: " + (UnicodeString)u_errorName(status));
1418 }
1419
1420 if (ms3!=ms) {
1421 error++;
1422 errln((UnicodeString)"\nError: Re-parse of '" + result + "' gave time of " +
1423 "\n " + ms3 +
1424 "\n not " + ms);
1425 } else {
1426 pass++;
1427 }
1428 }
1429
1430 UnicodeString info
1431 = UnicodeString("Passed: ") + pass + ", Warnings: " + warning + ", Errors: " + error;
1432 if (error > 0) {
1433 errln(info);
1434 } else {
1435 logln(info);
1436 }
73c04bcf 1437
b75a7d8f
A
1438 for(i=0;i<kTest1684Count;i++) {
1439 delete tests[i];
1440 }
1441 delete cal;
1442 delete sdf;
1443}
1444
46f4442e
A
1445void DateFormatRegressionTest::Test5554(void)
1446{
1447 UErrorCode status = U_ZERO_ERROR;
1448 UnicodeString pattern("Z","");
1449 UnicodeString newfoundland("Canada/Newfoundland", "");
1450 TimeZone *zone = TimeZone::createTimeZone(newfoundland);
1451 Calendar *cal = new GregorianCalendar(zone, status);
1452 SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
1453 if (U_FAILURE(status)) {
1454 dataerrln("Error constructing SimpleDateFormat");
1455 delete cal;
1456 delete sdf;
1457 return;
1458 }
1459 cal->set(2007, 1, 14);
1460 UDate date = cal->getTime(status);
1461 if (U_FAILURE(status)) {
1462 errln("Error getting time to format");
1463 return;
1464 };
1465 sdf->adoptCalendar(cal);
1466 UnicodeString result;
1467 UnicodeString correct("-0330", "");
1468 sdf->format(date, result);
1469 if (result != correct) {
1470 errln("\nError: Newfoundland Z of Jan 14, 2007 gave '" + result + "', expected '" + correct + "'");
1471 }
1472 delete sdf;
1473}
1474
4388f060
A
1475void DateFormatRegressionTest::Test9237(void)
1476{
1477 UErrorCode status = U_ZERO_ERROR;
1478 UnicodeString pattern("VVVV");
1479
1480 SimpleDateFormat fmt(pattern, status); // default locale
1481 SimpleDateFormat fmtDE(pattern, Locale("de_DE"), status);
1482 if (U_FAILURE(status)) {
1483 dataerrln("Error constructing SimpleDateFormat");
1484 return;
1485 }
1486
1487 // copy constructor
1488 SimpleDateFormat fmtCopyDE(fmtDE);
1489 UnicodeString resDE, resCopyDE;
1490
1491 fmtDE.format(0.0, resDE);
1492 fmtCopyDE.format(0.0, resCopyDE);
1493
1494 if (resDE != resCopyDE) {
1495 errln(UnicodeString("Error: different result by the copied instance - org:") + resDE + " copy:" + resCopyDE);
1496 }
1497
1498 // test for assignment operator
1499 fmt = fmtDE;
1500
1501 UnicodeString resAssigned;
1502 fmt.format(0.0, resAssigned);
1503
1504 if (resDE != resAssigned) {
1505 errln(UnicodeString("Error: different results by the assigned instance - org:") + resDE + " assigned:" + resAssigned);
1506 }
1507}
1508
51004dcb
A
1509void DateFormatRegressionTest::TestParsing(void) {
1510 UErrorCode status = U_ZERO_ERROR;
1511 UnicodeString pattern("EEE-WW-MMMM-yyyy");
1512 UnicodeString text("mon-02-march-2011");
1513 int32_t expectedDay = 7;
1514
1515 SimpleDateFormat format(pattern, status);
1516 if (U_FAILURE(status)) {
1517 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
1518 return;
1519 }
1520
1521 Calendar *cal = new GregorianCalendar(status);
1522 if (cal == NULL || U_FAILURE(status)) {
1523 errln("Unable to create calendar - %s", u_errorName(status));
1524 return;
1525 }
1526
1527 ParsePosition pos(0);
1528 format.parse(text, *cal, pos);
1529
1530 if (cal->get(UCAL_DAY_OF_MONTH, status) != expectedDay) {
1531 errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern + "\" for text: \"" + text + "\"");
1532 }
1533
1534 delete cal;
1535}
1536
3d1f044b
A
1537void DateFormatRegressionTest::Test12902_yWithGregoCalInThaiLoc(void) {
1538 UErrorCode status = U_ZERO_ERROR;
1539 UDate testDate = 43200000.0; // 1970-Jan-01 12:00 GMT
1540 const char* skeleton = "y";
1541 // Note that in locale "th", the availableFormats for skeleton "y" differ by calendar:
1542 // for buddhist (default calendar): y{"G y"}
1543 // for gregorian: y{"y"}
1544 const char* expectFormat = "1970"; // format for skeleton y in Thai locale with Gregorian calendar
1545 UnicodeString getFmtStr;
1546
1547 const TimeZone* gmtZone = TimeZone::getGMT();
1548 LocalPointer<GregorianCalendar> pureGregoCal(new GregorianCalendar(*gmtZone, Locale::getEnglish(), status));
1549 if (U_FAILURE(status)) {
1550 dataerrln("Fail in new GregorianCalendar(GMT, en): %s", u_errorName(status));
1551 return;
1552 }
1553 LocalPointer<DateFormat> df1(DateFormat::createInstanceForSkeleton(pureGregoCal.orphan(), skeleton, "th", status));
1554 if (U_FAILURE(status)) {
1555 dataerrln("Fail in DateFormat::createInstanceForSkeleton for th with Grego cal: %s", u_errorName(status));
1556 return;
1557 }
1558 status = U_ZERO_ERROR;
1559 getFmtStr.remove();
1560 getFmtStr = df1->format(testDate, getFmtStr);
1561 if (U_FAILURE(status)) {
1562 errln("Fail in DateFormat::format for th with Grego cal: %s", u_errorName(status));
1563 } else if (getFmtStr != expectFormat) {
1564 char getFormat[32];
1565 getFmtStr.extract(0, getFmtStr.length(), getFormat, 32);
1566 errln("Error in DateFormat::format for th with Grego cal, expect: %s, get: %s", expectFormat, getFormat);
1567 }
1568
1569 LocalPointer<DateFormat> df2(DateFormat::createInstanceForSkeleton(skeleton, "th-u-ca-gregory", status));
1570 if (U_FAILURE(status)) {
1571 dataerrln("Fail in DateFormat::createInstanceForSkeleton for th-u-ca-gregory: %s", u_errorName(status));
1572 return;
1573 }
1574 status = U_ZERO_ERROR;
1575 getFmtStr.remove();
1576 getFmtStr = df2->format(testDate, getFmtStr);
1577 if (U_FAILURE(status)) {
1578 errln("Fail in DateFormat::format for th-u-ca-gregory: %s", u_errorName(status));
1579 } else if (getFmtStr != expectFormat) {
1580 char getFormat[32];
1581 getFmtStr.extract(0, getFmtStr.length(), getFormat, 32);
1582 errln("Error in DateFormat::format for th with Grego cal, expect: %s, get: %s", expectFormat, getFormat);
1583 }
1584}
1585
57a6839d
A
1586void DateFormatRegressionTest::TestT10334(void) {
1587 UErrorCode status = U_ZERO_ERROR;
1588 UnicodeString pattern("'--: 'EEE-WW-MMMM-yyyy");
1589 UnicodeString text("--mon-02-march-2011");
1590 SimpleDateFormat format(pattern, status);
1591
b331163b
A
1592 logln("pattern["+pattern+"] text["+text+"]");
1593
57a6839d
A
1594 if (U_FAILURE(status)) {
1595 dataerrln("Fail creating SimpleDateFormat object - %s", u_errorName(status));
1596 return;
1597 }
1598
2ca993e8 1599 format.setBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, FALSE, status);
57a6839d
A
1600 format.parse(text, status);
1601 if (!U_FAILURE(status)) {
1602 errln("parse partial match did NOT fail in strict mode - %s", u_errorName(status));
1603 }
1604
1605 status = U_ZERO_ERROR;
2ca993e8 1606 format.setBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, TRUE, status);
57a6839d
A
1607 format.parse(text, status);
1608 if (U_FAILURE(status)) {
1609 errln("parse partial match failure in lenient mode - %s", u_errorName(status));
1610 }
1611
1612 status = U_ZERO_ERROR;
1613 pattern = UnicodeString("YYYY MM dd");
1614 text = UnicodeString("2013 12 10");
1615 format.applyPattern(pattern);
1616 UDate referenceDate = format.parse(text, status);
1617
f3c0d7a5 1618 FieldPosition fp(FieldPosition::DONT_CARE);
57a6839d
A
1619 UnicodeString formattedString("");
1620 pattern = UnicodeString("YYYY LL dd ee cc qq QQ");
1621 format.applyPattern(pattern);
1622 format.format(referenceDate, formattedString, fp, status);
1623 logln("ref date: " + formattedString);
1624
1625
1626 char patternArray[] = "YYYY LLL dd eee ccc qqq QQQ";
1627 pattern = UnicodeString(patternArray);
1628 text = UnicodeString("2013 12 10 03 3 04 04");
1629 status = U_ZERO_ERROR;
1630 format.setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, TRUE, status);
1631 format.applyPattern(pattern);
1632 ParsePosition pp(0);
1633 format.parse(text, pp);
1634 if (pp.getErrorIndex() != -1) {
1635 errln("numeric parse error");
1636 }
1637
1638 status = U_ZERO_ERROR;
1639 format.setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, FALSE, status);
1640 format.parse(text, status);
1641 if (!U_FAILURE(status)) {
1642 errln("numeric parse did NOT fail in strict mode", u_errorName(status));
1643 }
1644
1645}
1646
1647
1648typedef struct {
1649 const char * locale;
1650 UBool leniency;
1651 UnicodeString parseString;
1652 UnicodeString pattern;
1653 UnicodeString expectedResult; // null indicates expected error
1654} TestDateFormatLeniencyItem;
1655
1656
1657void DateFormatRegressionTest::TestT10619(void) {
1658 const UDate july022008 = 1215000001979.0;
1659 const TestDateFormatLeniencyItem items[] = {
57a6839d
A
1660 //locale leniency parse String pattern expected result
1661 { "en", true, UnicodeString("2008-07 02"), UnicodeString("yyyy-LLLL dd"), UnicodeString("2008-July 02") },
b331163b
A
1662 { "en", false, UnicodeString("2008-07 03"), UnicodeString("yyyy-LLLL dd"), UnicodeString("") },
1663 { "en", true, UnicodeString("2008-Jan. 04"), UnicodeString("yyyy-LLL dd"), UnicodeString("2008-Jan 04") },
1664 { "en", false, UnicodeString("2008-Jan. 05"), UnicodeString("yyyy-LLL dd"), UnicodeString("") },
1665 { "en", true, UnicodeString("2008-Jan--06"), UnicodeString("yyyy-MMM -- dd"), UnicodeString("2008-Jan 06") },
1666 { "en", false, UnicodeString("2008-Jan--07"), UnicodeString("yyyy-MMM -- dd"), UnicodeString("") },
1667 { "en", true, UnicodeString("6 Jan 08 2008"), UnicodeString("eee MMM dd yyyy"), UnicodeString("Sat Jan 08 2008") },
1668 { "en", false, UnicodeString("6 Jan 09 2008"), UnicodeString("eee MMM dd yyyy"), UnicodeString("") },
57a6839d
A
1669 // terminator
1670 { NULL, true, UnicodeString(""), UnicodeString(""), UnicodeString("") }
1671 };
1672 UErrorCode status = U_ZERO_ERROR;
1673 Calendar* cal = Calendar::createInstance(status);
1674 if (U_FAILURE(status)) {
1675 dataerrln(UnicodeString("FAIL: Unable to create Calendar for default timezone and locale."));
1676 } else {
1677 cal->setTime(july022008, status);
1678 const TestDateFormatLeniencyItem * itemPtr;
1679 for (itemPtr = items; itemPtr->locale != NULL; itemPtr++ ) {
1680
1681 Locale locale = Locale::createFromName(itemPtr->locale);
1682 status = U_ZERO_ERROR;
1683 ParsePosition pos(0);
1684 SimpleDateFormat * sdmft = new SimpleDateFormat(itemPtr->pattern, locale, status);
1685 if (U_FAILURE(status)) {
1686 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status));
1687 continue;
1688 }
b331163b 1689 logln("parsing " + itemPtr->parseString);
57a6839d 1690 sdmft->setLenient(itemPtr->leniency);
b331163b
A
1691 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_WHITESPACE, itemPtr->leniency, status);
1692 sdmft->setBooleanAttribute(UDAT_PARSE_ALLOW_NUMERIC, itemPtr->leniency, status);
2ca993e8 1693 sdmft->setBooleanAttribute(UDAT_PARSE_PARTIAL_LITERAL_MATCH, itemPtr->leniency, status);
b331163b 1694 sdmft->parse(itemPtr->parseString, pos);
57a6839d
A
1695
1696 delete sdmft;
1697 if(pos.getErrorIndex() > -1) {
1698 if(itemPtr->expectedResult.length() != 0) {
1699 errln("error: unexpected error - " + itemPtr->parseString + " - error index " + pos.getErrorIndex() +
1700 " - leniency " + itemPtr->leniency);
1701 continue;
1702 } else {
1703 continue;
1704 }
1705 }
1706 }
1707 }
1708 delete cal;
1709
1710}
1711
b331163b
A
1712
1713typedef struct {
1714 UnicodeString text;
1715 UnicodeString pattern;
1716 int initialParsePos;
1717} T10855Data;
1718
1719void DateFormatRegressionTest::TestT10855(void) {
1720 // NOTE: these should NOT parse
1721 const T10855Data items[] = {
1722 //parse String pattern initial parse pos
1723// { UnicodeString("September 30, 1998"), UnicodeString("MM-dd-yyyy"), 0}, // for Apple, this can succeed
1724 { UnicodeString("123-73-1950"), UnicodeString("MM-dd-yyyy"), -1},
1725 { UnicodeString("12-23-1950"), UnicodeString("MM-dd-yyyy"), -1},
1726 // terminator
1727 { UnicodeString(""), UnicodeString(""), 0}
1728 };
1729 UErrorCode status = U_ZERO_ERROR;
1730
1731 int x = 0;
1732 while(items[x].pattern.length() > 0)
1733 {
1734 status = U_ZERO_ERROR;
1735 logln("Date to parse: \""+items[x].text+"\"");
1736 logln("Starting Index: %d", items[x].initialParsePos);
1737
1738 SimpleDateFormat dateFmt(items[x].pattern, status);
1739 if(U_FAILURE(status)) {
1740 errcheckln(status, "Failed dateFmt: %s", u_errorName(status));
1741 ++x;
1742 continue;
1743 }
1744 status = U_ZERO_ERROR;
1745
1746 dateFmt.setLenient(false);
1747 dateFmt.setTimeZone(*TimeZone::getGMT());
1748
1749 ParsePosition position(items[x].initialParsePos);
1750 logln("set position is now: %d", position.getIndex());
1751 UDate d = dateFmt.parse(items[x].text, position);
1752 if (position.getErrorIndex() != -1 || position.getIndex() == items[x].initialParsePos) {
1753 logln("Parse Failed. ErrorIndex is %d - Index is %d", position.getErrorIndex(), position.getIndex());
1754 } else {
1755 errln("Parse Succeeded...should have failed. Index is %d - ErrorIndex is %d", position.getIndex(), position.getErrorIndex());
1756 }
1757 logln("Parsed date returns %d\n", d);
1758
1759 ++x;
1760 }
1761}
1762
1763void DateFormatRegressionTest::TestT10906(void) {
1764
1765 UErrorCode status = U_ZERO_ERROR;
1766 UnicodeString pattern = "MM-dd-yyyy";
1767 UnicodeString text = "06-10-2014";
1768 SimpleDateFormat format(pattern, status);
1769 int32_t errorIdx = 0;
1770 ParsePosition pp(-1);
1771 format.parse(text, pp);
1772 errorIdx = pp.getErrorIndex();
1773 if (errorIdx == -1) {
1774 errln("failed to report invalid (negative) starting parse position");
1775 }
1776}
1777
0f5d89e8
A
1778void DateFormatRegressionTest::TestT13380(void) {
1779 UErrorCode errorCode = U_ZERO_ERROR;
1780 LocalPointer<DateFormat> enFmt(DateFormat::createDateInstance(DateFormat::kShort, Locale("en")), errorCode);
1781 if (U_FAILURE(errorCode)) {
1782 errln("failure creating 'en' DateFormat");
1783 }
1784
1785 errorCode = U_ZERO_ERROR;
1786 LocalPointer<DateFormat> tgFmt(DateFormat::createDateInstance(DateFormat::kShort, Locale("tg")), errorCode);
1787 if (U_FAILURE(errorCode)) {
1788 errln("failure creating 'tg' DateFormat");
1789 }
1790}
1791
b75a7d8f
A
1792#endif /* #if !UCONFIG_NO_FORMATTING */
1793
1794//eof