1 /********************************************************************
3 * Copyright (c) 1997-2012, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 ********************************************************************/
7 #include "unicode/utypes.h"
9 #if !UCONFIG_NO_FORMATTING
13 #include "unicode/timezone.h"
14 #include "unicode/gregocal.h"
15 #include "unicode/smpdtfmt.h"
16 #include "unicode/datefmt.h"
17 #include "unicode/simpletz.h"
18 #include "unicode/resbund.h"
20 // *****************************************************************************
21 // class DateFormatRegressionTest
22 // *****************************************************************************
24 #define CASE(id,test) case id: name = #test; if (exec) { logln(#test "---"); logln((UnicodeString)""); test(); } break;
27 DateFormatRegressionTest::runIndexedTest( int32_t index
, UBool exec
, const char* &name
, char* /*par*/ )
29 // if (exec) logln((UnicodeString)"TestSuite DateFormatRegressionTest");
60 default: name
= ""; break;
67 void DateFormatRegressionTest::Test4029195(void)
69 UErrorCode status
= U_ZERO_ERROR
;
71 UDate today
= Calendar::getNow();
72 logln((UnicodeString
) "today: " + today
);
74 SimpleDateFormat
*sdf
= (SimpleDateFormat
*) DateFormat::createDateInstance();
75 if (failure(status
, "SimpleDateFormat::createDateInstance")) {
80 dataerrln("Error calling DateFormat::createDateTimeInstance");
84 pat
= sdf
->toPattern(pat
);
85 logln("pattern: " + pat
);
87 FieldPosition
pos(FieldPosition::DONT_CARE
);
88 fmtd
= sdf
->format(today
, fmtd
, pos
);
89 logln("today: " + fmtd
);
91 sdf
->applyPattern("G yyyy DDD");
93 todayS
= sdf
->format(today
, todayS
, pos
);
94 logln("today: " + todayS
);
96 today
= sdf
->parse(todayS
, status
);
97 failure(status
, "sdf->parse");
98 logln((UnicodeString
)"today date: " + today
);
99 /*} catch(Exception e) {
100 logln("Error reparsing date: " + e.getMessage());
105 rt
= sdf
->format(sdf
->parse(todayS
, status
), rt
, pos
);
106 failure(status
, "sdf->parse");
107 logln("round trip: " + rt
);
109 errln("Fail: Want " + todayS
+ " Got " + rt
);
111 catch (ParseException e) {
122 void DateFormatRegressionTest::Test4052408(void)
125 DateFormat
*fmt
= DateFormat::createDateTimeInstance(DateFormat::SHORT
,
126 DateFormat::SHORT
, Locale::getUS());
128 dataerrln("Error calling DateFormat::createDateTimeInstance");
132 UDate dt
= date(97, UCAL_MAY
, 3, 8, 55);
134 str
= fmt
->format(dt
, str
);
137 if(str
!= "5/3/97, 8:55 AM")
138 errln("Fail: Test broken; Want 5/3/97, 8:55 AM Got " + str
);
140 UnicodeString expected
[] = {
141 (UnicodeString
) "", //"ERA_FIELD",
142 (UnicodeString
) "97", //"YEAR_FIELD",
143 (UnicodeString
) "5", //"MONTH_FIELD",
144 (UnicodeString
) "3", //"DATE_FIELD",
145 (UnicodeString
) "", //"HOUR_OF_DAY1_FIELD",
146 (UnicodeString
) "", //"HOUR_OF_DAY0_FIELD",
147 (UnicodeString
) "55", //"MINUTE_FIELD",
148 (UnicodeString
) "", //"SECOND_FIELD",
149 (UnicodeString
) "", //"MILLISECOND_FIELD",
150 (UnicodeString
) "", //"DAY_OF_WEEK_FIELD",
151 (UnicodeString
) "", //"DAY_OF_YEAR_FIELD",
152 (UnicodeString
) "", //"DAY_OF_WEEK_IN_MONTH_FIELD",
153 (UnicodeString
) "", //"WEEK_OF_YEAR_FIELD",
154 (UnicodeString
) "", //"WEEK_OF_MONTH_FIELD",
155 (UnicodeString
) "AM", //"AM_PM_FIELD",
156 (UnicodeString
) "8", //"HOUR1_FIELD",
157 (UnicodeString
) "", //"HOUR0_FIELD",
158 (UnicodeString
) "" //"TIMEZONE_FIELD"
161 //Hashtable expected;// = new Hashtable();
162 //expected.put(new LongKey(DateFormat.MONTH_FIELD), "5");
163 //expected.put(new LongKey(DateFormat.DATE_FIELD), "3");
164 //expected.put(new LongKey(DateFormat.YEAR_FIELD), "97");
165 //expected.put(new LongKey(DateFormat.HOUR1_FIELD), "8");
166 //expected.put(new LongKey(DateFormat.MINUTE_FIELD), "55");
167 //expected.put(new LongKey(DateFormat.AM_PM_FIELD), "AM");
169 //StringBuffer buf = new StringBuffer();
170 UnicodeString fieldNames
[] = {
171 (UnicodeString
) "ERA_FIELD",
172 (UnicodeString
) "YEAR_FIELD",
173 (UnicodeString
) "MONTH_FIELD",
174 (UnicodeString
) "DATE_FIELD",
175 (UnicodeString
) "HOUR_OF_DAY1_FIELD",
176 (UnicodeString
) "HOUR_OF_DAY0_FIELD",
177 (UnicodeString
) "MINUTE_FIELD",
178 (UnicodeString
) "SECOND_FIELD",
179 (UnicodeString
) "MILLISECOND_FIELD",
180 (UnicodeString
) "DAY_OF_WEEK_FIELD",
181 (UnicodeString
) "DAY_OF_YEAR_FIELD",
182 (UnicodeString
) "DAY_OF_WEEK_IN_MONTH_FIELD",
183 (UnicodeString
) "WEEK_OF_YEAR_FIELD",
184 (UnicodeString
) "WEEK_OF_MONTH_FIELD",
185 (UnicodeString
) "AM_PM_FIELD",
186 (UnicodeString
) "HOUR1_FIELD",
187 (UnicodeString
) "HOUR0_FIELD",
188 (UnicodeString
) "TIMEZONE_FIELD"
192 for(int i
= 0; i
<= 17; ++i
) {
193 FieldPosition
pos(i
);
195 fmt
->format(dt
, buf
, pos
);
196 //char[] dst = new char[pos.getEndIndex() - pos.getBeginIndex()];
198 buf
.extractBetween(pos
.getBeginIndex(), pos
.getEndIndex(), dst
);
199 UnicodeString
str(dst
);
200 logln((UnicodeString
)"" + i
+ (UnicodeString
)": " + fieldNames
[i
] +
201 (UnicodeString
)", \"" + str
+ (UnicodeString
)"\", " +
202 pos
.getBeginIndex() + (UnicodeString
)", " +
204 UnicodeString exp
= expected
[i
];
205 if((exp
.length() == 0 && str
.length() == 0) || str
== exp
)
208 errln(UnicodeString(" expected ") + exp
);
214 errln("Fail: FieldPosition not set right by DateFormat");
221 * Verify the function of the [s|g]et2DigitYearStart() API.
223 void DateFormatRegressionTest::Test4056591(void)
225 UErrorCode status
= U_ZERO_ERROR
;
228 SimpleDateFormat
*fmt
= new SimpleDateFormat(UnicodeString("yyMMdd"), Locale::getUS(), status
);
229 if (failure(status
, "new SimpleDateFormat", TRUE
)) {
233 UDate start
= date(1809-1900, UCAL_DECEMBER
, 25);
234 fmt
->set2DigitYearStart(start
, status
);
235 failure(status
, "fmt->setTwoDigitStartDate");
236 if( (fmt
->get2DigitYearStart(status
) != start
) || failure(status
, "get2DigitStartDate"))
237 errln("get2DigitYearStart broken");
239 date(1809-1900, UCAL_DECEMBER
, 25),
240 date(1909-1900, UCAL_DECEMBER
, 24),
241 date(1809-1900, UCAL_DECEMBER
, 26),
242 date(1861-1900, UCAL_DECEMBER
, 25),
245 UnicodeString strings
[] = {
246 (UnicodeString
) "091225",
247 (UnicodeString
) "091224",
248 (UnicodeString
) "091226",
249 (UnicodeString
) "611225"
253 "091225", new Date(1809-1900, Calendar.DECEMBER, 25),
254 "091224", new Date(1909-1900, Calendar.DECEMBER, 24),
255 "091226", new Date(1809-1900, Calendar.DECEMBER, 26),
256 "611225", new Date(1861-1900, Calendar.DECEMBER, 25),
259 for(int i
= 0; i
< 4; i
++) {
260 UnicodeString s
= strings
[i
];
261 UDate exp
= dates
[i
];
262 UDate got
= fmt
->parse(s
, status
);
263 failure(status
, "fmt->parse");
264 logln(s
+ " -> " + got
+ "; exp " + exp
);
266 errln("set2DigitYearStart broken");
269 catch (ParseException e) {
280 void DateFormatRegressionTest::Test4059917(void)
282 UErrorCode status
= U_ZERO_ERROR
;
284 SimpleDateFormat
*fmt
;
285 UnicodeString myDate
;
287 fmt
= new SimpleDateFormat( UnicodeString("yyyy/MM/dd"), status
);
288 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
289 myDate
= "1997/01/01";
290 aux917( fmt
, myDate
);
295 fmt
= new SimpleDateFormat( UnicodeString("yyyyMMdd"), status
);
296 if(failure(status
, "new SimpleDateFormat")) return;
298 aux917( fmt
, myDate
);
303 void DateFormatRegressionTest::aux917( SimpleDateFormat
*fmt
, UnicodeString
& str
) {
306 pat
= fmt
->toPattern(pat
);
307 logln( "==================" );
308 logln( "testIt: pattern=" + pat
+
314 ParsePosition
pos(0);
315 fmt
->parseObject( str
, o
, pos
);
316 //logln( UnicodeString("Parsed object: ") + o );
318 UErrorCode status
= U_ZERO_ERROR
;
319 UnicodeString formatted
;
320 FieldPosition
poss(FieldPosition::DONT_CARE
);
321 formatted
= fmt
->format( o
, formatted
, poss
, status
);
322 failure(status
, "fmt->format");
323 logln( "Formatted string: " + formatted
);
324 if( formatted
!= str
)
325 errln("Fail: Want " + str
+ " Got " + formatted
);
327 catch (ParseException e) {
336 void DateFormatRegressionTest::Test4060212(void)
338 UnicodeString dateString
= "1995-040.05:01:29";
340 logln( "dateString= " + dateString
);
341 logln("Using yyyy-DDD.hh:mm:ss");
342 UErrorCode status
= U_ZERO_ERROR
;
343 SimpleDateFormat
*formatter
= new SimpleDateFormat(UnicodeString("yyyy-DDD.hh:mm:ss"), status
);
344 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
345 ParsePosition
pos(0);
346 UDate myDate
= formatter
->parse( dateString
, pos
);
347 UnicodeString myString
;
348 DateFormat
*fmt
= DateFormat::createDateTimeInstance( DateFormat::FULL
,
351 dataerrln("Error calling DateFormat::createDateTimeInstance");
356 myString
= fmt
->format( myDate
, myString
);
359 Calendar
*cal
= new GregorianCalendar(status
);
360 failure(status
, "new GregorianCalendar");
361 cal
->setTime(myDate
, status
);
362 failure(status
, "cal->setTime");
363 if ((cal
->get(UCAL_DAY_OF_YEAR
, status
) != 40) || failure(status
, "cal->get"))
364 errln((UnicodeString
) "Fail: Got " + cal
->get(UCAL_DAY_OF_YEAR
, status
) +
367 // this is an odd usage of "ddd" and it doesn't
368 // work now that date values are range checked per #3579.
369 logln("Using yyyy-ddd.hh:mm:ss");
372 formatter
= new SimpleDateFormat(UnicodeString("yyyy-ddd.hh:mm:ss"), status
);
373 if(failure(status
, "new SimpleDateFormat")) return;
375 myDate
= formatter
->parse( dateString
, pos
);
376 myString
= fmt
->format( myDate
, myString
);
378 cal
->setTime(myDate
, status
);
379 failure(status
, "cal->setTime");
380 if ((cal
->get(UCAL_DAY_OF_YEAR
, status
) != 40) || failure(status
, "cal->get"))
381 errln((UnicodeString
) "Fail: Got " + cal
->get(UCAL_DAY_OF_YEAR
, status
) +
392 void DateFormatRegressionTest::Test4061287(void)
394 UErrorCode status
= U_ZERO_ERROR
;
396 SimpleDateFormat
*df
= new SimpleDateFormat(UnicodeString("dd/MM/yyyy"), status
);
397 if (U_FAILURE(status
)) {
398 dataerrln("Fail new SimpleDateFormat: %s", u_errorName(status
));
402 failure(status
, "new SimpleDateFormat");
404 logln(UnicodeString("") + df
->parse("35/01/1971", status
));
405 failure(status
, "df->parse(\"35/01/1971\")");
406 //logln(df.parse("35/01/1971").toString());
408 /*catch (ParseException e) {
412 df
->setLenient(FALSE
);
415 logln(UnicodeString("") + df
->parse("35/01/1971", status
));
416 if(U_FAILURE(status
))
418 //logln(df.parse("35/01/1971").toString());
419 //} catch (ParseException e) {ok=TRUE;}
421 errln("Fail: Lenient not working");
428 void DateFormatRegressionTest::Test4065240(void)
431 DateFormat
*shortdate
, *fulldate
;
432 UnicodeString strShortDate
, strFullDate
;
433 Locale saveLocale
= Locale::getDefault();
434 TimeZone
*saveZone
= TimeZone::createDefault();
436 UErrorCode status
= U_ZERO_ERROR
;
438 Locale
*curLocale
= new Locale("de","DE");
439 Locale::setDefault(*curLocale
, status
);
440 failure(status
, "Locale::setDefault");
441 // {sfb} adoptDefault instead of setDefault
442 //TimeZone::setDefault(TimeZone::createTimeZone("EST"));
443 TimeZone::adoptDefault(TimeZone::createTimeZone("EST"));
444 curDate
= date(98, 0, 1);
445 shortdate
= DateFormat::createDateInstance(DateFormat::SHORT
);
446 if (shortdate
== NULL
){
447 dataerrln("Error calling DateFormat::createDateInstance");
451 fulldate
= DateFormat::createDateTimeInstance(DateFormat::LONG
, DateFormat::LONG
);
452 if (fulldate
== NULL
){
453 dataerrln("Error calling DateFormat::createDateTimeInstance");
456 strShortDate
= "The current date (short form) is ";
458 temp
= shortdate
->format(curDate
, temp
);
459 strShortDate
+= temp
;
460 strFullDate
= "The current date (long form) is ";
462 fulldate
->format(curDate
, temp2
);
463 strFullDate
+= temp2
;
468 // {sfb} What to do with resource bundle stuff?????
470 // Check to see if the resource is present; if not, we can't test
471 ResourceBundle
*bundle
= new ResourceBundle(
472 NULL
, *curLocale
, status
);
473 failure(status
, "new ResourceBundle");
474 //(UnicodeString) "java.text.resources.DateFormatZoneData", curLocale);
476 // {sfb} API change to ResourceBundle -- add getLocale()
477 /*if (bundle->getLocale().getLanguage(temp) == UnicodeString("de")) {
478 // UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
479 if (!strFullDate.endsWith(UnicodeString("GMT-05:00")))
480 errln("Fail: Want GMT-05:00");
483 logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
484 logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
488 Locale::setDefault(saveLocale
, status
);
489 failure(status
, "Locale::setDefault");
490 TimeZone::setDefault(*saveZone
);
500 DateFormat.equals is too narrowly defined. As a result, MessageFormat
501 does not work correctly. DateFormat.equals needs to be written so
502 that the Calendar sub-object is not compared using Calendar.equals,
503 but rather compared for equivalency. This may necessitate adding a
504 (package private) method to Calendar to test for equivalency.
506 Currently this bug breaks MessageFormat.toPattern
511 void DateFormatRegressionTest::Test4071441(void)
513 DateFormat
*fmtA
= DateFormat::createInstance();
514 DateFormat
*fmtB
= DateFormat::createInstance();
516 if (fmtA
== NULL
|| fmtB
== NULL
){
517 dataerrln("Error calling DateFormat::createInstance");
523 // {sfb} Is it OK to cast away const here?
524 Calendar
*calA
= (Calendar
*) fmtA
->getCalendar();
525 Calendar
*calB
= (Calendar
*) fmtB
->getCalendar();
527 errln("Couldn't get proper calendars, exiting");
532 UDate epoch
= date(0, 0, 0);
533 UDate xmas
= date(61, UCAL_DECEMBER
, 25);
535 UErrorCode status
= U_ZERO_ERROR
;
536 calA
->setTime(epoch
, status
);
537 failure(status
, "calA->setTime");
538 calB
->setTime(epoch
, status
);
539 failure(status
, "calB->setTime");
541 errln("Fail: Can't complete test; Calendar instances unequal");
543 errln("Fail: DateFormat unequal when Calendars equal");
544 calB
->setTime(xmas
, status
);
545 failure(status
, "calB->setTime");
547 errln("Fail: Can't complete test; Calendar instances equal");
549 errln("Fail: DateFormat unequal when Calendars equivalent");
551 logln("DateFormat.equals ok");
557 /* The java.text.DateFormat.parse(String) method expects for the
558 US locale a string formatted according to mm/dd/yy and parses it
561 When given a string mm/dd/yyyy [sic] it only parses up to the first
562 two y's, typically resulting in a date in the year 1919.
564 Please extend the parsing method(s) to handle strings with
565 four-digit year values (probably also applicable to various
570 void DateFormatRegressionTest::Test4073003(void)
573 UErrorCode ec
= U_ZERO_ERROR
;
574 SimpleDateFormat
fmt("MM/dd/yy", Locale::getUK(), ec
);
576 dataerrln("FAIL: SimpleDateFormat constructor - %s", u_errorName(ec
));
579 UnicodeString tests
[] = {
580 (UnicodeString
) "12/25/61",
581 (UnicodeString
) "12/25/1961",
582 (UnicodeString
) "4/3/2010",
583 (UnicodeString
) "4/3/10"
585 UErrorCode status
= U_ZERO_ERROR
;
586 for(int i
= 0; i
< 4; i
+=2) {
587 UDate d
= fmt
.parse(tests
[i
], status
);
588 failure(status
, "fmt.parse");
589 UDate dd
= fmt
.parse(tests
[i
+1], status
);
590 failure(status
, "fmt.parse");
592 s
= fmt
.format(d
, s
);
594 ss
= fmt
.format(dd
, ss
);
596 errln((UnicodeString
) "Fail: " + d
+ " != " + dd
);
598 errln((UnicodeString
)"Fail: " + s
+ " != " + ss
);
599 logln("Ok: " + s
+ " " + d
);
606 void DateFormatRegressionTest::Test4089106(void)
608 TimeZone
*def
= TimeZone::createDefault();
610 TimeZone
*z
= new SimpleTimeZone((int)(1.25 * 3600000), "FAKEZONE");
611 TimeZone::setDefault(*z
);
612 UErrorCode status
= U_ZERO_ERROR
;
613 SimpleDateFormat
*f
= new SimpleDateFormat(status
);
614 if(U_FAILURE(status
)) {
615 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status
));
621 failure(status
, "new SimpleDateFormat");
622 if (f
->getTimeZone()!= *z
)
623 errln("Fail: SimpleTimeZone should use TimeZone.getDefault()");
627 TimeZone::setDefault(*def
);
639 // {sfb} not applicable in C++??
641 void DateFormatRegressionTest::Test4100302(void)
643 /* Locale locales [] = {
645 Locale::CANADA_FRENCH,
660 Locale::SIMPLIFIED_CHINESE,
662 Locale::TRADITIONAL_CHINESE,
668 for(int i = 0; i < 21; i++) {
670 Format *format = DateFormat::createDateTimeInstance(DateFormat::FULL,
671 DateFormat::FULL, locales[i]);
674 ByteArrayOutputStream baos = new ByteArrayOutputStream();
675 ObjectOutputStream oos = new ObjectOutputStream(baos);
677 oos.writeObject(format);
681 bytes = baos.toByteArray();
683 ObjectInputStream ois =
684 new ObjectInputStream(new ByteArrayInputStream(bytes));
686 if (!format.equals(ois.readObject())) {
688 logln("DateFormat instance for locale " +
689 locales[i] + " is incorrectly serialized/deserialized.");
691 logln("DateFormat instance for locale " +
692 locales[i] + " is OKAY.");
695 if (!pass) errln("Fail: DateFormat serialization/equality bug");
697 catch (IOException e) {
701 catch (ClassNotFoundException e) {
710 void DateFormatRegressionTest::Test4101483(void)
712 UErrorCode status
= U_ZERO_ERROR
;
713 SimpleDateFormat
*sdf
= new SimpleDateFormat(UnicodeString("z"), Locale::getUS(), status
);
714 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
715 FieldPosition
fp(UDAT_TIMEZONE_FIELD
);
716 //Date d = date(9234567890L);
717 UDate d
= 9234567890.0;
718 //StringBuffer buf = new StringBuffer("");
720 sdf
->format(d
, buf
, fp
);
721 //logln(sdf.format(d, buf, fp).toString());
722 logln(dateToString(d
) + " => " + buf
);
723 logln(UnicodeString("beginIndex = ") + fp
.getBeginIndex());
724 logln(UnicodeString("endIndex = ") + fp
.getEndIndex());
725 if (fp
.getBeginIndex() == fp
.getEndIndex())
726 errln("Fail: Empty field");
734 * This bug really only works in Locale.US, since that's what the locale
735 * used for Date.toString() is. Bug 4138203 reports that it fails on Korean
736 * NT; it would actually have failed on any non-US locale. Now it should
737 * work on all locales.
739 void DateFormatRegressionTest::Test4103340(void)
741 UErrorCode status
= U_ZERO_ERROR
;
743 // choose a date that is the FIRST of some month
744 // and some arbitrary time
745 UDate d
= date(97, 3, 1, 1, 1, 1);
746 SimpleDateFormat
*df
= new SimpleDateFormat(UnicodeString("MMMM"), Locale::getUS(), status
);
747 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
750 s
= dateToString(d
, s
);
752 FieldPosition
pos(FieldPosition::DONT_CARE
);
753 s2
= df
->format(d
, s2
, pos
);
756 UnicodeString substr
;
757 s2
.extract(0,2, substr
);
758 if (s
.indexOf(substr
) == -1)
759 errln("Months should match");
767 void DateFormatRegressionTest::Test4103341(void)
769 TimeZone
*saveZone
=TimeZone::createDefault();
772 // {sfb} changed from setDefault to adoptDefault
773 TimeZone::adoptDefault(TimeZone::createTimeZone("CST"));
774 UErrorCode status
= U_ZERO_ERROR
;
775 SimpleDateFormat
*simple
= new SimpleDateFormat(UnicodeString("MM/dd/yyyy HH:mm"), status
);
776 if(U_FAILURE(status
)) {
777 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status
));
781 failure(status
, "new SimpleDateFormat");
782 TimeZone
*temp
= TimeZone::createDefault();
783 if(simple
->getTimeZone() != *temp
)
784 errln("Fail: SimpleDateFormat not using default zone");
787 TimeZone::adoptDefault(saveZone
);
797 void DateFormatRegressionTest::Test4104136(void)
799 UErrorCode status
= U_ZERO_ERROR
;
800 SimpleDateFormat
*sdf
= new SimpleDateFormat(status
);
801 if(U_FAILURE(status
)) {
802 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status
));
806 if(failure(status
, "new SimpleDateFormat")) return;
807 UnicodeString pattern
= "'time' hh:mm";
808 sdf
->applyPattern(pattern
);
809 logln("pattern: \"" + pattern
+ "\"");
811 UnicodeString strings
[] = {
812 (UnicodeString
)"time 10:30",
813 (UnicodeString
) "time 10:x",
814 (UnicodeString
) "time 10x"
817 ParsePosition ppos
[] = {
824 date(70, UCAL_JANUARY
, 1, 10, 30),
830 "time 10:30", new ParsePosition(10), new Date(70, Calendar.JANUARY, 1, 10, 30),
831 "time 10:x", new ParsePosition(0), null,
832 "time 10x", new ParsePosition(0), null,
835 for(int i
= 0; i
< 3; i
++) {
836 UnicodeString text
= strings
[i
];
837 ParsePosition finish
= ppos
[i
];
838 UDate exp
= dates
[i
];
840 ParsePosition
pos(0);
841 UDate d
= sdf
->parse(text
, pos
);
842 logln(" text: \"" + text
+ "\"");
843 logln(" index: %d", pos
.getIndex());
844 logln((UnicodeString
) " result: " + d
);
845 if(pos
.getIndex() != finish
.getIndex())
846 errln(UnicodeString("Fail: Expected pos ") + finish
.getIndex());
847 if (! ((d
== 0 && exp
== -1) || (d
== exp
)))
848 errln((UnicodeString
) "Fail: Expected result " + exp
);
857 * According to the bug report, this test should throw a
858 * StringIndexOutOfBoundsException during the second parse. However,
861 void DateFormatRegressionTest::Test4104522(void)
863 UErrorCode status
= U_ZERO_ERROR
;
865 SimpleDateFormat
*sdf
= new SimpleDateFormat(status
);
866 if(U_FAILURE(status
)) {
867 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status
));
871 failure(status
, "new SimpleDateFormat");
872 UnicodeString pattern
= "'time' hh:mm";
873 sdf
->applyPattern(pattern
);
874 logln("pattern: \"" + pattern
+ "\"");
878 UnicodeString text
= "time ";
879 UDate dt
= sdf
->parse(text
, pp
);
880 logln(" text: \"" + text
+ "\"" +
886 dt
= sdf
->parse(text
, pp
);
887 logln(" text: \"" + text
+ "\"" +
896 void DateFormatRegressionTest::Test4106807(void)
899 DateFormat
*df
= DateFormat::createDateTimeInstance();
901 UErrorCode status
= U_ZERO_ERROR
;
902 SimpleDateFormat
*sdfs
[] = {
903 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss"), status
),
904 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'Z'"), status
),
905 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss''"), status
),
906 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss'a''a'"), status
),
907 new SimpleDateFormat(UnicodeString("yyyyMMddHHmmss %"), status
)
909 if(U_FAILURE(status
)) {
910 dataerrln("Couldn't create SimpleDateFormat, error %s", u_errorName(status
));
919 failure(status
, "new SimpleDateFormat");
921 UnicodeString strings
[] = {
922 (UnicodeString
) "19980211140000",
923 (UnicodeString
) "19980211140000",
924 (UnicodeString
) "19980211140000",
925 (UnicodeString
) "19980211140000a",
926 (UnicodeString
) "19980211140000 "
930 new SimpleDateFormat("yyyyMMddHHmmss"), "19980211140000",
931 new SimpleDateFormat("yyyyMMddHHmmss'Z'"), "19980211140000",
932 new SimpleDateFormat("yyyyMMddHHmmss''"), "19980211140000",
933 new SimpleDateFormat("yyyyMMddHHmmss'a''a'"), "19980211140000a",
934 new SimpleDateFormat("yyyyMMddHHmmss %"), "19980211140000 ",
936 GregorianCalendar
*gc
= new GregorianCalendar(status
);
937 failure(status
, "new GregorianCalendar");
938 TimeZone
*timeZone
= TimeZone::createDefault();
940 TimeZone
*gmt
= timeZone
->clone();
942 gmt
->setRawOffset(0);
944 for(int32_t i
= 0; i
< 5; i
++) {
945 SimpleDateFormat
*format
= sdfs
[i
];
946 UnicodeString dateString
= strings
[i
];
948 format
->setTimeZone(*gmt
);
949 dt
= format
->parse(dateString
, status
);
950 // {sfb} some of these parses will fail purposely
951 if(U_FAILURE(status
))
953 status
= U_ZERO_ERROR
;
955 FieldPosition
pos(FieldPosition::DONT_CARE
);
956 fmtd
= df
->format(dt
, fmtd
, pos
);
958 //logln(df->format(dt));
959 gc
->setTime(dt
, status
);
960 failure(status
, "gc->getTime");
961 logln(UnicodeString("") + gc
->get(UCAL_ZONE_OFFSET
, status
));
962 failure(status
, "gc->get");
964 s
= format
->format(dt
, s
, pos
);
967 catch (ParseException e) {
968 logln("No way Jose");
974 for(int32_t j
= 0; j
< 5; j
++)
981 Synopsis: Chinese time zone CTT is not recogonized correctly.
982 Description: Platform Chinese Windows 95 - ** Time zone set to CST **
988 // {sfb} what to do with this one ??
989 void DateFormatRegressionTest::Test4108407(void)
991 /*long l = System.currentTimeMillis();
992 logln("user.timezone = " + System.getProperty("user.timezone", "?"));
993 logln("Time Zone :" +
994 DateFormat.getDateInstance().getTimeZone().getID());
995 logln("Default format :" +
996 DateFormat.getDateInstance().format(new Date(l)));
997 logln("Full format :" +
998 DateFormat.getDateInstance(DateFormat.FULL).format(new
1000 logln("*** Set host TZ to CST ***");
1001 logln("*** THE RESULTS OF THIS TEST MUST BE VERIFIED MANUALLY ***");*/
1006 * SimpleDateFormat won't parse "GMT"
1008 void DateFormatRegressionTest::Test4134203(void)
1010 UErrorCode status
= U_ZERO_ERROR
;
1011 UnicodeString dateFormat
= "MM/dd/yy HH:mm:ss zzz";
1012 SimpleDateFormat
*fmt
= new SimpleDateFormat(dateFormat
, status
);
1013 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
1014 ParsePosition
p0(0);
1015 UDate d
= fmt
->parse("01/22/92 04:52:00 GMT", p0
);
1016 logln(dateToString(d
));
1017 if(p0
== ParsePosition(0))
1018 errln("Fail: failed to parse 'GMT'");
1019 // In the failure case an exception is thrown by parse();
1020 // if no exception is thrown, the test passes.
1027 * SimpleDateFormat incorrect handling of 2 single quotes in format()
1029 void DateFormatRegressionTest::Test4151631(void)
1031 UnicodeString pattern
= "'TO_DATE('''dd'-'MM'-'yyyy HH:mm:ss''' , ''DD-MM-YYYY HH:MI:SS'')'";
1032 logln("pattern=" + pattern
);
1033 UErrorCode status
= U_ZERO_ERROR
;
1034 SimpleDateFormat
*format
= new SimpleDateFormat(pattern
, Locale::getUS(), status
);
1035 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
1036 UnicodeString result
;
1037 FieldPosition
pos(FieldPosition::DONT_CARE
);
1038 result
= format
->format(date(1998-1900, UCAL_JUNE
, 30, 13, 30, 0), result
, pos
);
1039 if (result
!= "TO_DATE('30-06-1998 13:30:00' , 'DD-MM-YYYY HH:MI:SS')") {
1040 errln("Fail: result=" + result
);
1043 logln("Pass: result=" + result
);
1051 * 'z' at end of date format throws index exception in SimpleDateFormat
1052 * CANNOT REPRODUCE THIS BUG ON 1.2FCS
1054 void DateFormatRegressionTest::Test4151706(void)
1056 UnicodeString
dateString("Thursday, 31-Dec-98 23:00:00 GMT");
1057 UErrorCode status
= U_ZERO_ERROR
;
1058 SimpleDateFormat
fmt(UnicodeString("EEEE, dd-MMM-yy HH:mm:ss z"), Locale::getUS(), status
);
1059 if (failure(status
, "new SimpleDateFormat", TRUE
)) return;
1061 UDate d
= fmt
.parse(dateString
, status
);
1062 failure(status
, "fmt->parse");
1063 // {sfb} what about next two lines?
1064 //if (d.getTime() != Date.UTC(1998-1900, Calendar.DECEMBER, 31, 23, 0, 0))
1065 // errln("Incorrect value: " + d);
1066 /*} catch (Exception e) {
1067 errln("Fail: " + e);
1070 FieldPosition
pos(0);
1071 logln(dateString
+ " -> " + fmt
.format(d
, temp
, pos
));
1076 * Cannot reproduce this bug under 1.2 FCS -- it may be a convoluted duplicate
1077 * of some other bug that has been fixed.
1080 DateFormatRegressionTest::Test4162071(void)
1082 UnicodeString
dateString("Thu, 30-Jul-1999 11:51:14 GMT");
1083 UnicodeString
format("EEE', 'dd-MMM-yyyy HH:mm:ss z"); // RFC 822/1123
1084 UErrorCode status
= U_ZERO_ERROR
;
1085 SimpleDateFormat
df(format
, Locale::getUS(), status
);
1086 if(U_FAILURE(status
)) {
1087 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status
));
1092 UDate x
= df
.parse(dateString
, status
);
1093 if(U_SUCCESS(status
))
1094 logln("Parse format \"" + format
+ "\" ok");
1096 errln("Parse format \"" + format
+ "\" failed.");
1098 FieldPosition
pos(0);
1099 logln(dateString
+ " -> " + df
.format(x
, temp
, pos
));
1100 //} catch (Exception e) {
1101 // errln("Parse format \"" + format + "\" failed.");
1106 * DateFormat shouldn't parse year "-1" as a two-digit year (e.g., "-1" -> 1999).
1108 void DateFormatRegressionTest::Test4182066(void) {
1109 UErrorCode status
= U_ZERO_ERROR
;
1110 SimpleDateFormat
fmt("MM/dd/yy", Locale::getUS(), status
);
1111 SimpleDateFormat
dispFmt("MMM dd yyyy GG", Locale::getUS(), status
);
1112 if (U_FAILURE(status
)) {
1113 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status
));
1117 /* We expect 2-digit year formats to put 2-digit years in the right
1118 * window. Out of range years, that is, anything less than "00" or
1119 * greater than "99", are treated as literal years. So "1/2/3456"
1120 * becomes 3456 AD. Likewise, "1/2/-3" becomes -3 AD == 2 BC.
1122 const char* STRINGS
[] = {
1132 int32_t STRINGS_COUNT
= (int32_t)(sizeof(STRINGS
) / sizeof(STRINGS
[0]));
1133 UDate FAIL_DATE
= (UDate
) 0;
1135 date(2000-1900, UCAL_FEBRUARY
, 29),
1136 date(2001-1900, UCAL_JANUARY
, 23),
1137 date( -1-1900, UCAL_APRIL
, 5),
1138 date( -9-1900, UCAL_JANUARY
, 23),
1139 date(1314-1900, UCAL_NOVEMBER
, 12),
1140 date( 1-1900, UCAL_OCTOBER
, 31),
1141 FAIL_DATE
, // "+1" isn't recognized by US NumberFormat
1142 date( 1-1900, UCAL_SEPTEMBER
,12),
1147 for (int32_t i
=0; i
<STRINGS_COUNT
; ++i
) {
1148 UnicodeString
str(STRINGS
[i
]);
1149 UDate expected
= DATES
[i
];
1150 status
= U_ZERO_ERROR
;
1151 UDate actual
= fmt
.parse(str
, status
);
1152 if (U_FAILURE(status
)) {
1155 UnicodeString actStr
;
1156 if (actual
== FAIL_DATE
) {
1157 actStr
.append("null");
1160 ((DateFormat
*)&dispFmt
)->format(actual
, actStr
);
1163 if (expected
== actual
) {
1164 out
.append(str
+ " => " + actStr
+ "\n");
1166 UnicodeString expStr
;
1167 if (expected
== FAIL_DATE
) {
1168 expStr
.append("null");
1171 ((DateFormat
*)&dispFmt
)->format(expected
, expStr
);
1173 out
.append("FAIL: " + str
+ " => " + actStr
1174 + ", expected " + expStr
+ "\n");
1186 * j32 {JDK Bug 4210209 4209272}
1187 * DateFormat cannot parse Feb 29 2000 when setLenient(false)
1190 DateFormatRegressionTest::Test4210209(void) {
1191 UErrorCode status
= U_ZERO_ERROR
;
1192 UnicodeString
pattern("MMM d, yyyy");
1193 SimpleDateFormat
sfmt(pattern
, Locale::getUS(), status
);
1194 SimpleDateFormat
sdisp("MMM dd yyyy GG", Locale::getUS(), status
);
1195 DateFormat
& fmt
= *(DateFormat
*)&sfmt
; // Yuck: See j25
1196 DateFormat
& disp
= *(DateFormat
*)&sdisp
; // Yuck: See j25
1197 if (U_FAILURE(status
)) {
1198 dataerrln("Couldn't create SimpleDateFormat - %s", u_errorName(status
));
1201 Calendar
* calx
= (Calendar
*)fmt
.getCalendar(); // cast away const!
1202 calx
->setLenient(FALSE
);
1203 UDate d
= date(2000-1900, UCAL_FEBRUARY
, 29);
1204 UnicodeString s
, ss
;
1206 logln(disp
.format(d
, ss
.remove()) + " f> " + pattern
+
1207 " => \"" + s
+ "\"");
1208 ParsePosition
pos(0);
1209 d
= fmt
.parse(s
, pos
);
1210 logln(UnicodeString("\"") + s
+ "\" p> " + pattern
+
1211 " => " + disp
.format(d
, ss
.remove()));
1212 logln(UnicodeString("Parse pos = ") + pos
.getIndex() +
1213 ", error pos = " + pos
.getErrorIndex());
1214 if (pos
.getErrorIndex() != -1) {
1215 errln(UnicodeString("FAIL: Error index should be -1"));
1218 // The underlying bug is in GregorianCalendar. If the following lines
1219 // succeed, the bug is fixed. If the bug isn't fixed, they will throw
1221 GregorianCalendar
cal(status
);
1222 if (U_FAILURE(status
)) {
1223 errln("FAIL: Unable to create Calendar");
1227 cal
.setLenient(FALSE
);
1228 cal
.set(2000, UCAL_FEBRUARY
, 29); // This should work!
1229 logln(UnicodeString("Attempt to set Calendar to Feb 29 2000: ") +
1230 disp
.format(cal
.getTime(status
), ss
.remove()));
1231 if (U_FAILURE(status
)) {
1232 errln("FAIL: Unable to set Calendar to Feb 29 2000");
1236 void DateFormatRegressionTest::Test714(void)
1239 UDate
d(978103543000.);
1240 DateFormat
*fmt
= DateFormat::createDateTimeInstance(DateFormat::NONE
,
1244 dataerrln("Error calling DateFormat::createDateTimeInstance");
1249 UnicodeString tests
=
1250 (UnicodeString
) "7:25:43 AM" ;
1251 UErrorCode status
= U_ZERO_ERROR
;
1253 if(U_FAILURE(status
))
1255 errln((UnicodeString
) "Fail, errmsg " + u_errorName(status
));
1261 errln((UnicodeString
) "Fail: " + s
+ " != " + tests
);
1265 logln("OK: " + s
+ " == " + tests
);
1271 class Test1684Data
{
1281 UnicodeString normalized
;
1283 Test1684Data(int32_t xyear
, int32_t xmonth
, int32_t xdate
,
1284 int32_t xwomyear
, int32_t xwommon
, int32_t xwom
, int32_t xdow
,
1285 const char *xdata
, const char *xnormalized
) :
1294 normalized((xnormalized
==NULL
)?xdata
:xnormalized
,"")
1298 void DateFormatRegressionTest::Test1684(void)
1300 // July 2001 August 2001 January 2002
1301 // Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1302 // 1 2 3 4 5 6 7 1 2 3 4 1 2 3 4 5
1303 // 8 9 10 11 12 13 14 5 6 7 8 9 10 11 6 7 8 9 10 11 12
1304 // 15 16 17 18 19 20 21 12 13 14 15 16 17 18 13 14 15 16 17 18 19
1305 // 22 23 24 25 26 27 28 19 20 21 22 23 24 25 20 21 22 23 24 25 26
1306 // 29 30 31 26 27 28 29 30 31 27 28 29 30 31
1307 Test1684Data
*tests
[] = {
1308 new Test1684Data(2001, 8, 6, 2001,8,2,UCAL_MONDAY
, "2001 08 02 Mon", NULL
),
1309 new Test1684Data(2001, 8, 7, 2001,8,2,UCAL_TUESDAY
, "2001 08 02 Tue", NULL
),
1310 new Test1684Data(2001, 8, 5,/*12,*/ 2001,8,2,UCAL_SUNDAY
, "2001 08 02 Sun", NULL
),
1311 new Test1684Data(2001, 8,6, /*7, 30,*/ 2001,7,6,UCAL_MONDAY
, "2001 07 06 Mon", "2001 08 02 Mon"),
1312 new Test1684Data(2001, 8,7, /*7, 31,*/ 2001,7,6,UCAL_TUESDAY
, "2001 07 06 Tue", "2001 08 02 Tue"),
1313 new Test1684Data(2001, 8, 5, 2001,7,6,UCAL_SUNDAY
, "2001 07 06 Sun", "2001 08 02 Sun"),
1314 new Test1684Data(2001, 7, 30, 2001,8,1,UCAL_MONDAY
, "2001 08 01 Mon", "2001 07 05 Mon"),
1315 new Test1684Data(2001, 7, 31, 2001,8,1,UCAL_TUESDAY
, "2001 08 01 Tue", "2001 07 05 Tue"),
1316 new Test1684Data(2001, 7,29, /*8, 5,*/ 2001,8,1,UCAL_SUNDAY
, "2001 08 01 Sun", "2001 07 05 Sun"),
1317 new Test1684Data(2001, 12, 31, 2001,12,6,UCAL_MONDAY
, "2001 12 06 Mon", NULL
),
1318 new Test1684Data(2002, 1, 1, 2002,1,1,UCAL_TUESDAY
, "2002 01 01 Tue", NULL
),
1319 new Test1684Data(2002, 1, 2, 2002,1,1,UCAL_WEDNESDAY
, "2002 01 01 Wed", NULL
),
1320 new Test1684Data(2002, 1, 3, 2002,1,1,UCAL_THURSDAY
, "2002 01 01 Thu", NULL
),
1321 new Test1684Data(2002, 1, 4, 2002,1,1,UCAL_FRIDAY
, "2002 01 01 Fri", NULL
),
1322 new Test1684Data(2002, 1, 5, 2002,1,1,UCAL_SATURDAY
, "2002 01 01 Sat", NULL
),
1323 new Test1684Data(2001,12,30, /*2002, 1, 6,*/ 2002,1,1,UCAL_SUNDAY
, "2002 01 01 Sun", "2001 12 06 Sun")
1326 #define kTest1684Count ((int32_t)(sizeof(tests)/sizeof(tests[0])))
1328 int32_t pass
= 0, error
= 0, warning
= 0;
1331 UErrorCode status
= U_ZERO_ERROR
;
1332 UnicodeString
pattern("yyyy MM WW EEE","");
1333 Calendar
*cal
= new GregorianCalendar(status
);
1334 SimpleDateFormat
*sdf
= new SimpleDateFormat(pattern
,status
);
1335 if (U_FAILURE(status
)) {
1336 dataerrln("Error constructing SimpleDateFormat");
1337 for(i
=0;i
<kTest1684Count
;i
++) {
1344 cal
->setFirstDayOfWeek(UCAL_SUNDAY
);
1345 cal
->setMinimalDaysInFirstWeek(1);
1347 sdf
->adoptCalendar(cal
);
1349 cal
= sdf
->getCalendar()->clone(); // sdf may have deleted calendar
1351 if(!cal
|| !sdf
|| U_FAILURE(status
)) {
1352 errln(UnicodeString("Error setting up test: ") + u_errorName(status
));
1355 for (i
= 0; i
< kTest1684Count
; ++i
) {
1356 Test1684Data
&test
= *(tests
[i
]);
1357 logln(UnicodeString("#") + i
+ UnicodeString("\n-----\nTesting round trip of ") + test
.year
+
1358 " " + (test
.month
+ 1) +
1360 " (written as) " + test
.data
);
1363 cal
->set(test
.year
, test
.month
, test
.date
);
1364 UDate ms
= cal
->getTime(status
);
1367 cal
->set(UCAL_YEAR
, test
.womyear
);
1368 cal
->set(UCAL_MONTH
, test
.wommon
);
1369 cal
->set(UCAL_WEEK_OF_MONTH
, test
.wom
);
1370 cal
->set(UCAL_DAY_OF_WEEK
, test
.dow
);
1371 UDate ms2
= cal
->getTime(status
);
1374 errln((UnicodeString
)"\nError: GregorianUCAL_DOM gave " + ms
+
1375 "\n GregorianUCAL_WOM gave " + ms2
);
1381 ms2
= sdf
->parse(test
.data
, status
);
1382 if(U_FAILURE(status
)) {
1383 errln("parse exception: " + UnicodeString(u_errorName(status
)));
1387 errln((UnicodeString
)"\nError: GregorianCalendar gave " + ms
+
1388 "\n SimpleDateFormat.parse gave " + ms2
);
1394 UnicodeString result
;
1395 sdf
->format(ms
, result
);
1396 if (result
!= test
.normalized
) {
1397 errln("\nWarning: format of '" + test
.data
+ "' gave" +
1398 "\n '" + result
+ "'" +
1399 "\n expected '" + test
.normalized
+ "'");
1406 ms3
= sdf
->parse(result
, status
);
1407 if(U_FAILURE(status
)) {
1408 errln("parse exception 2: " + (UnicodeString
)u_errorName(status
));
1413 errln((UnicodeString
)"\nError: Re-parse of '" + result
+ "' gave time of " +
1422 = UnicodeString("Passed: ") + pass
+ ", Warnings: " + warning
+ ", Errors: " + error
;
1429 for(i
=0;i
<kTest1684Count
;i
++) {
1436 void DateFormatRegressionTest::Test5554(void)
1438 UErrorCode status
= U_ZERO_ERROR
;
1439 UnicodeString
pattern("Z","");
1440 UnicodeString
newfoundland("Canada/Newfoundland", "");
1441 TimeZone
*zone
= TimeZone::createTimeZone(newfoundland
);
1442 Calendar
*cal
= new GregorianCalendar(zone
, status
);
1443 SimpleDateFormat
*sdf
= new SimpleDateFormat(pattern
,status
);
1444 if (U_FAILURE(status
)) {
1445 dataerrln("Error constructing SimpleDateFormat");
1450 cal
->set(2007, 1, 14);
1451 UDate date
= cal
->getTime(status
);
1452 if (U_FAILURE(status
)) {
1453 errln("Error getting time to format");
1456 sdf
->adoptCalendar(cal
);
1457 UnicodeString result
;
1458 UnicodeString
correct("-0330", "");
1459 sdf
->format(date
, result
);
1460 if (result
!= correct
) {
1461 errln("\nError: Newfoundland Z of Jan 14, 2007 gave '" + result
+ "', expected '" + correct
+ "'");
1466 void DateFormatRegressionTest::Test9237(void)
1468 UErrorCode status
= U_ZERO_ERROR
;
1469 UnicodeString
pattern("VVVV");
1471 SimpleDateFormat
fmt(pattern
, status
); // default locale
1472 SimpleDateFormat
fmtDE(pattern
, Locale("de_DE"), status
);
1473 if (U_FAILURE(status
)) {
1474 dataerrln("Error constructing SimpleDateFormat");
1479 SimpleDateFormat
fmtCopyDE(fmtDE
);
1480 UnicodeString resDE
, resCopyDE
;
1482 fmtDE
.format(0.0, resDE
);
1483 fmtCopyDE
.format(0.0, resCopyDE
);
1485 if (resDE
!= resCopyDE
) {
1486 errln(UnicodeString("Error: different result by the copied instance - org:") + resDE
+ " copy:" + resCopyDE
);
1489 // test for assignment operator
1492 UnicodeString resAssigned
;
1493 fmt
.format(0.0, resAssigned
);
1495 if (resDE
!= resAssigned
) {
1496 errln(UnicodeString("Error: different results by the assigned instance - org:") + resDE
+ " assigned:" + resAssigned
);
1500 void DateFormatRegressionTest::TestParsing(void) {
1501 UErrorCode status
= U_ZERO_ERROR
;
1502 UnicodeString
pattern("EEE-WW-MMMM-yyyy");
1503 UnicodeString
text("mon-02-march-2011");
1504 int32_t expectedDay
= 7;
1506 SimpleDateFormat
format(pattern
, status
);
1507 if (U_FAILURE(status
)) {
1508 dataerrln("Unable to create SimpleDateFormat - %s", u_errorName(status
));
1512 Calendar
*cal
= new GregorianCalendar(status
);
1513 if (cal
== NULL
|| U_FAILURE(status
)) {
1514 errln("Unable to create calendar - %s", u_errorName(status
));
1518 ParsePosition
pos(0);
1519 format
.parse(text
, *cal
, pos
);
1521 if (cal
->get(UCAL_DAY_OF_MONTH
, status
) != expectedDay
) {
1522 errln("Parsing failed: day of month should be '7' with pattern: \"" + pattern
+ "\" for text: \"" + text
+ "\"");
1528 #endif /* #if !UCONFIG_NO_FORMATTING */