ICU-5267 DateFormatSymbols::getZoneType() needs to check for empty strings.

X-SVN-Rev: 19854
This commit is contained in:
Eric Mader 2006-07-18 22:14:29 +00:00
parent 278eaef75e
commit e933e38b2d
3 changed files with 23 additions and 2 deletions

View File

@ -1987,7 +1987,7 @@ DateFormatSymbols::getZoneType(const UnicodeString& zid, const UnicodeString& te
UnicodeString* strings = (UnicodeString*)fZoneStringsHash->get(zid);
if(strings != NULL){
for(int32_t j=0; j<UTZ_MAX_DISPLAY_STRINGS_LENGTH; j++){
if(text.caseCompare(start, strings[j].length(), strings[j], 0)==0){
if(strings[j].length() >0 && text.caseCompare(start, strings[j].length(), strings[j], 0)==0){
type = (TimeZoneTranslationType)j;
value.setTo(strings[j]);
return;

View File

@ -54,6 +54,7 @@ DateFormatRoundTripTest::runIndexedTest( int32_t index, UBool exec, const char*
optionv = (par && *par=='v');
switch (index) {
CASE(0,TestDateFormatRoundTrip)
CASE(1, TestCentury)
default: name = ""; break;
}
}
@ -82,6 +83,25 @@ DateFormatRoundTripTest::failure(UErrorCode status, const char* msg, const Unico
return FALSE;
}
void DateFormatRoundTripTest::TestCentury()
{
UErrorCode status = U_ZERO_ERROR;
Locale locale("es_PA");
UnicodeString pattern = "MM/dd/yy hh:mm:ss a z";
SimpleDateFormat fmt(pattern, locale, status);
UDate date[] = {-55018555891590.05, 0, 0};
UnicodeString *result = new UnicodeString[2];
fmt.format(date[0], result[0]);
date[1] = fmt.parse(result[0], status);
fmt.format(date[1], result[1]);
date[2] = fmt.parse(result[1], status);
if (date[1] != date[2] || result[0] != result[1]) {
errln("Round trip failure: \"%S\" (%f), \"%S\" (%f)", result[0].getBuffer(), date[1], result[1].getBuffer(), date[2]);
}
}
// ==
void DateFormatRoundTripTest::TestDateFormatRoundTrip()

View File

@ -1,6 +1,6 @@
/********************************************************************
* COPYRIGHT:
* Copyright (c) 1997-2003, International Business Machines Corporation and
* Copyright (c) 1997-2006, International Business Machines Corporation and
* others. All Rights Reserved.
********************************************************************/
@ -30,6 +30,7 @@ public:
virtual ~DateFormatRoundTripTest();
void TestDateFormatRoundTrip(void);
void TestCentury(void);
void test(const Locale& loc);
void test(DateFormat *fmt, const Locale &origLocale, UBool timeOnly = FALSE );
int32_t getField(UDate d, int32_t f);