/********************************************************************
* COPYRIGHT:
- * Copyright (c) 1997-2001, International Business Machines Corporation and
+ * Copyright (c) 1997-2012, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
if (exec) {
logln("SimpleDateFormat API test---"); logln("");
UErrorCode status = U_ZERO_ERROR;
+ Locale saveLocale;
Locale::setDefault(Locale::getEnglish(), status);
if(U_FAILURE(status)) {
errln("ERROR: Could not set default locale, test may not give correct results");
}
testAPI(/*par*/);
+ Locale::setDefault(saveLocale, status);
}
break;
SimpleDateFormat def(status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create SimpleDateFormat (default)");
+ dataerrln("ERROR: Could not create SimpleDateFormat (default) - exitting");
+ return;
}
status = U_ZERO_ERROR;
- const UnicodeString pattern("yyyy.MM.dd G 'at' hh:mm:ss z");
+ const UnicodeString pattern("yyyy.MM.dd G 'at' hh:mm:ss z", "");
+ const UnicodeString override("y=hebr;d=thai;s=arab", ""); /* use invariant converter */
+ const UnicodeString override_bogus("y=hebr;d=thai;s=bogus", "");
+
SimpleDateFormat pat(pattern, status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create SimpleDateFormat (pattern)");
+ errln("ERROR: Could not create SimpleDateFormat (pattern) - %s", u_errorName(status));
}
status = U_ZERO_ERROR;
status = U_ZERO_ERROR;
SimpleDateFormat cust1(pattern, symbols, status);
if(U_FAILURE(status)) {
- errln("ERROR: Could not create SimpleDateFormat (pattern, symbols*)");
+ dataerrln("ERROR: Could not create SimpleDateFormat (pattern, symbols*) - exitting");
+ return;
}
status = U_ZERO_ERROR;
errln("ERROR: Could not create SimpleDateFormat (pattern, symbols)");
}
+ status = U_ZERO_ERROR;
+ logln(UnicodeString("Override with: ") + override);
+ SimpleDateFormat ovr1(pattern, override, status);
+ if(U_FAILURE(status)) {
+ errln("ERROR: Could not create SimpleDateFormat (pattern, override) - %s", u_errorName(status));
+ }
+
+ status = U_ZERO_ERROR;
+ SimpleDateFormat ovr2(pattern, override, Locale::getGerman(), status);
+ if(U_FAILURE(status)) {
+ errln("ERROR: Could not create SimpleDateFormat (pattern, override, locale) - %s", u_errorName(status));
+ }
+
+ status = U_ZERO_ERROR;
+ logln(UnicodeString("Override with: ") + override_bogus);
+ SimpleDateFormat ovr3(pattern, override_bogus, Locale::getGerman(), status);
+ if(U_SUCCESS(status)) {
+ errln("ERROR: Should not have been able to create SimpleDateFormat (pattern, override, locale) with a bogus override");
+ }
+
+
SimpleDateFormat copy(pat);
// ======= Test clone(), assignment, and equality
status = U_ZERO_ERROR;
pat.applyLocalizedPattern(p1, status);
if(U_FAILURE(status)) {
- errln("ERROR: applyPattern() failed with " + (int32_t) status);
+ errln("ERROR: applyPattern() failed with %s", u_errorName(status));
}
UnicodeString s3;
status = U_ZERO_ERROR;
if(test->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
-
+
delete test;
+
+// ======= Test Ticket 5684 (Parsing with 'e' and 'Y')
+ SimpleDateFormat object(UNICODE_STRING_SIMPLE("YYYY'W'wwe"), status);
+ if(U_FAILURE(status)) {
+ errln("ERROR: Couldn't create a SimpleDateFormat");
+ }
+ object.setLenient(false);
+ ParsePosition pp(0);
+ UDate udDate = object.parse("2007W014", pp);
+ if ((double)udDate == 0.0) {
+ errln("ERROR: Parsing failed using 'Y' and 'e'");
+ }
}
#endif /* #if !UCONFIG_NO_FORMATTING */