From 99ca0b9eac60a597ac0aaf50aa985f888df61941 Mon Sep 17 00:00:00 2001 From: Jason Spieth Date: Mon, 16 Mar 2009 15:23:11 +0000 Subject: [PATCH] ICU-6726 Changes to dateTimePatterns lengths and default glue pattern usage X-SVN-Rev: 25592 --- icu4c/source/i18n/reldtfmt.cpp | 25 +++++++++++++- icu4c/source/i18n/smpdtfmt.cpp | 10 +++++- icu4c/source/i18n/unicode/datefmt.h | 2 +- icu4c/source/i18n/windtfmt.cpp | 13 +++++-- icu4c/source/i18n/windtfmt.h | 3 +- icu4c/source/test/intltest/dtfmttst.cpp | 45 +++++++++++++++++++++++-- icu4c/source/test/intltest/dtfmttst.h | 1 + 7 files changed, 90 insertions(+), 9 deletions(-) diff --git a/icu4c/source/i18n/reldtfmt.cpp b/icu4c/source/i18n/reldtfmt.cpp index 436375276a..333ef5cde2 100644 --- a/icu4c/source/i18n/reldtfmt.cpp +++ b/icu4c/source/i18n/reldtfmt.cpp @@ -261,7 +261,30 @@ void RelativeDateFormat::loadDates(UErrorCode &status) { UResourceBundle *dateTimePatterns = calData.getByKey(DT_DateTimePatternsTag, tempStatus); if(U_SUCCESS(tempStatus) && ures_getSize(dateTimePatterns) > DateFormat::kDateTime) { int32_t resStrLen = 0; - const UChar *resStr = ures_getStringByIndex(dateTimePatterns, (int32_t)DateFormat::kDateTime, &resStrLen, &tempStatus); + + int32_t glueIndex = (int32_t)DateFormat::kDateTime; + switch (fDateStyle) { + case kFullRelative: + case kFull: + glueIndex = kDateTimeOffset + kFull; + break; + case kLongRelative: + case kLong: + glueIndex = kDateTimeOffset + kLong; + break; + case kMediumRelative: + case kMedium: + glueIndex = kDateTimeOffset + kMedium; + break; + case kShortRelative: + case kShort: + glueIndex = kDateTimeOffset + kShort; + break; + default: + break; + } + + const UChar *resStr = ures_getStringByIndex(dateTimePatterns, glueIndex, &resStrLen, &tempStatus); fCombinedFormat = new MessageFormat(UnicodeString(TRUE, resStr, resStrLen), fLocale, tempStatus); } diff --git a/icu4c/source/i18n/smpdtfmt.cpp b/icu4c/source/i18n/smpdtfmt.cpp index d9244fee22..f4a9f1946b 100644 --- a/icu4c/source/i18n/smpdtfmt.cpp +++ b/icu4c/source/i18n/smpdtfmt.cpp @@ -567,7 +567,15 @@ void SimpleDateFormat::construct(EStyle timeStyle, } timeDateArray[1].adoptString(tempus2); - resStr = ures_getStringByIndex(dateTimePatterns, (int32_t)kDateTime, &resStrLen, &status); + int32_t glueIndex = ures_getSize(dateTimePatterns); + if (glueIndex > kDateTimeOffset) { + glueIndex = (int32_t)(kDateTimeOffset + (dateStyle - kDateOffset)); + } + else { + glueIndex = kDateTime; + } + + resStr = ures_getStringByIndex(dateTimePatterns, glueIndex, &resStrLen, &status); MessageFormat::format(UnicodeString(TRUE, resStr, resStrLen), timeDateArray, 2, fPattern, status); } // if the pattern includes just time data or just date date, load the appropriate diff --git a/icu4c/source/i18n/unicode/datefmt.h b/icu4c/source/i18n/unicode/datefmt.h index f543156e78..bbf6feabd2 100644 --- a/icu4c/source/i18n/unicode/datefmt.h +++ b/icu4c/source/i18n/unicode/datefmt.h @@ -161,7 +161,7 @@ public: // kShort + kDateOffset = 7 kDateTime = 8, - + kDateTimeOffset = kDateTime + 1, // relative dates kRelative = (1 << 7), diff --git a/icu4c/source/i18n/windtfmt.cpp b/icu4c/source/i18n/windtfmt.cpp index 7771bf88f5..f78290989e 100644 --- a/icu4c/source/i18n/windtfmt.cpp +++ b/icu4c/source/i18n/windtfmt.cpp @@ -1,6 +1,6 @@ /* ******************************************************************************** -* Copyright (C) 2005-2008, International Business Machines +* Copyright (C) 2005-2009, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************** * @@ -52,7 +52,7 @@ UOBJECT_DEFINE_RTTI_IMPLEMENTATION(Win32DateFormat) #define STACK_BUFFER_SIZE 64 -UnicodeString *getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) +UnicodeString* Win32DateFormat::getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const { UnicodeString *result = NULL; const char *type = cal->getType(); @@ -74,7 +74,14 @@ UnicodeString *getTimeDateFormat(const Calendar *cal, const Locale *locale, UErr } int32_t resStrLen = 0; - const UChar *resStr = ures_getStringByIndex(patBundle, (int32_t)DateFormat::kDateTime, &resStrLen, &status); + int32_t glueIndex = ures_getSize(patBundle); + if (glueIndex > DateFormat::kDateTimeOffset) { + glueIndex = (int32_t)(DateFormat::kDateTimeOffset + (fDateStyle - DateFormat::kDateOffset)); + } + else { + glueIndex = DateFormat::kDateTime; + } + const UChar *resStr = ures_getStringByIndex(patBundle, glueIndex, &resStrLen, &status); result = new UnicodeString(TRUE, resStr, resStrLen); diff --git a/icu4c/source/i18n/windtfmt.h b/icu4c/source/i18n/windtfmt.h index 869044e04b..5f6e2dab49 100644 --- a/icu4c/source/i18n/windtfmt.h +++ b/icu4c/source/i18n/windtfmt.h @@ -1,6 +1,6 @@ /* ******************************************************************************** -* Copyright (C) 2005-2007, International Business Machines +* Copyright (C) 2005-2009, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************** * @@ -125,6 +125,7 @@ private: void formatTime(const SYSTEMTIME *st, UnicodeString &appendTo) const; UnicodeString setTimeZoneInfo(TIME_ZONE_INFORMATION *tzi, const TimeZone &zone) const; + UnicodeString* getTimeDateFormat(const Calendar *cal, const Locale *locale, UErrorCode &status) const; UnicodeString *fDateTimeMsg; DateFormat::EStyle fTimeStyle; diff --git a/icu4c/source/test/intltest/dtfmttst.cpp b/icu4c/source/test/intltest/dtfmttst.cpp index e6824b7f20..05764a911e 100644 --- a/icu4c/source/test/intltest/dtfmttst.cpp +++ b/icu4c/source/test/intltest/dtfmttst.cpp @@ -76,9 +76,10 @@ void DateFormatTest::runIndexedTest( int32_t index, UBool exec, const char* &nam TESTCASE(36,TestTimeZoneDisplayName); TESTCASE(37,TestRoundtripWithCalendar); TESTCASE(38,Test6338); + TESTCASE(39,Test6726); /* - TESTCASE(39,TestRelativeError); - TESTCASE(40,TestRelativeOther); + TESTCASE(40,TestRelativeError); + TESTCASE(41,TestRelativeOther); */ default: name = ""; break; } @@ -3142,6 +3143,46 @@ void DateFormatTest::Test6338(void) } +void DateFormatTest::Test6726(void) +{ + // status + UErrorCode status = U_ZERO_ERROR; + + // fmtf, fmtl, fmtm, fmts; + UnicodeString strf, strl, strm, strs; + UDate dt = date(2008-1900, UCAL_JUNE, 10, 12, 00); + + Locale loc("ja"); + DateFormat* fmtf = DateFormat::createDateTimeInstance(DateFormat::FULL, DateFormat::FULL, loc); + DateFormat* fmtl = DateFormat::createDateTimeInstance(DateFormat::LONG, DateFormat::FULL, loc); + DateFormat* fmtm = DateFormat::createDateTimeInstance(DateFormat::MEDIUM, DateFormat::FULL, loc); + DateFormat* fmts = DateFormat::createDateTimeInstance(DateFormat::SHORT, DateFormat::FULL, loc); + strf = fmtf->format(dt, strf); + strl = fmtl->format(dt, strl); + strm = fmtm->format(dt, strm); + strs = fmts->format(dt, strs); + + if (strf.charAt(13) == UChar(' ')) { + errln((UnicodeString)"FAIL: Improper formated date: " + strf); + } + if (strl.charAt(10) == UChar(' ')) { + errln((UnicodeString)"FAIL: Improper formated date: " + strl); + } + if (strm.charAt(10) != UChar(' ')) { + errln((UnicodeString)"FAIL: Improper formated date: " + strm); + } + if (strs.charAt(8) != UChar(' ')) { + errln((UnicodeString)"FAIL: Improper formated date: " + strs); + } + + delete fmtf; + delete fmtl; + delete fmtm; + delete fmts; + + return; +} + #endif /* #if !UCONFIG_NO_FORMATTING */ //eof diff --git a/icu4c/source/test/intltest/dtfmttst.h b/icu4c/source/test/intltest/dtfmttst.h index 5aa180cc8f..2b610c6f8b 100644 --- a/icu4c/source/test/intltest/dtfmttst.h +++ b/icu4c/source/test/intltest/dtfmttst.h @@ -161,6 +161,7 @@ public: // package void Test6338(void); + void Test6726(void); public: /** * Test host-specific formatting.