ICU-6703 Fallback to default calendar when unknown specific calendar is requested.

X-SVN-Rev: 25637
This commit is contained in:
Jason Spieth 2009-03-20 19:06:29 +00:00
parent edea4db881
commit fbc5170a41
3 changed files with 67 additions and 4 deletions

View File

@ -727,14 +727,47 @@ Calendar::createInstance(TimeZone* zone, const Locale& aLocale, UErrorCode& succ
// no calendar type. Default to nothing.
calLocaleType[0] = 0;
}
#ifdef U_DEBUG_CALSVC
fprintf(stderr, " getFunctionalEquivalent calendar=%s [%s]\n", keyword, u_errorName(status));
#endif
// create functional equivalent default calendar
u = createStandardCalendar(calLocaleType, aLocale, success);
}
else {
#ifdef U_DEBUG_CALSVC
else { fprintf(stderr, " explicit calendar=%s\n", keyword); }
fprintf(stderr, " explicit calendar=%s\n", keyword);
#endif
u = createStandardCalendar(calLocaleType, aLocale, success);
// create explicit calendar
u = createStandardCalendar(calLocaleType, aLocale, success);
// check the results, fallback and build default if in error
if(success == U_UNSUPPORTED_ERROR) {
char funcEquiv[ULOC_FULLNAME_CAPACITY];
feErr = U_ZERO_ERROR;
// fetch default calendar id
ures_getFunctionalEquivalent(funcEquiv, sizeof(funcEquiv)-1,
NULL, "calendar", "calendar",
aLocale.getName(),
NULL, FALSE, &feErr);
keywordCapacity = uloc_getKeywordValue(funcEquiv, "calendar", calLocaleType,
sizeof(calLocaleType)-1, &feErr); // This can fail if there is no data.
// Don't want to stop calendar construction just because we couldn't get this type.
if (keywordCapacity == 0 || U_FAILURE(feErr)) {
// no calendar type. Default to nothing.
calLocaleType[0] = 0;
}
#ifdef U_DEBUG_CALSVC
fprintf(stderr, " getFunctionalEquivalent calendar=%s [%s]\n", keyword, u_errorName(status));
#endif
// create functional equivalent default calendar
success = U_ZERO_ERROR;
u = createStandardCalendar(calLocaleType, aLocale, success);
}
}
}
Calendar* c = NULL;

View File

@ -203,7 +203,13 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
TestDebug();
}
break;
case 22:
name = "Test6703";
if(exec) {
logln("Test6703---"); logln("");
Test6703();
}
break;
default: name = ""; break;
}
}
@ -1982,7 +1988,30 @@ UDate CalendarTest::minDateOfCalendar(const Calendar& cal, UBool &isGregorian, U
return doMinDateOfCalendar(cal.clone(), isGregorian, status);
}
void CalendarTest::Test6703()
{
UErrorCode status = U_ZERO_ERROR;
Calendar *cal;
Locale loc1("en@calendar=fubar");
cal = Calendar::createInstance(loc1, status);
if (failure(status, "Calendar::createInstance")) return;
delete cal;
status = U_ZERO_ERROR;
Locale loc2("en");
cal = Calendar::createInstance(loc2, status);
if (failure(status, "Calendar::createInstance")) return;
delete cal;
status = U_ZERO_ERROR;
Locale loc3("en@calendar=roc");
cal = Calendar::createInstance(loc3, status);
if (failure(status, "Calendar::createInstance")) return;
delete cal;
return;
}
#endif /* #if !UCONFIG_NO_FORMATTING */

View File

@ -1,5 +1,5 @@
/***********************************************************************
* Copyright (c) 1997-2007, International Business Machines Corporation
* Copyright (c) 1997-2009, International Business Machines Corporation
* and others. All Rights Reserved.
***********************************************************************/
@ -216,6 +216,7 @@ public: // package
// internal - for other test use
public:
void Test6703(void);
};