From 8d6be178daf6384a84049ee8fdf86f9a38549ba8 Mon Sep 17 00:00:00 2001 From: Xiaomei Ji Date: Thu, 29 May 2008 19:23:52 +0000 Subject: [PATCH] ICU-6309 interval format clean up after consolidate skeleton consts X-SVN-Rev: 24072 --- icu4c/source/i18n/datefmt.cpp | 6 +- icu4c/source/i18n/dtitvfmt.cpp | 86 +------ icu4c/source/i18n/unicode/datefmt.h | 10 +- icu4c/source/i18n/unicode/dtitvfmt.h | 296 ++---------------------- icu4c/source/i18n/unicode/dtitvinf.h | 20 +- icu4c/source/test/intltest/dtifmtts.cpp | 180 +------------- 6 files changed, 34 insertions(+), 564 deletions(-) diff --git a/icu4c/source/i18n/datefmt.cpp b/icu4c/source/i18n/datefmt.cpp index 64f3466ef59..dc156b86d6e 100644 --- a/icu4c/source/i18n/datefmt.cpp +++ b/icu4c/source/i18n/datefmt.cpp @@ -277,9 +277,8 @@ DateFormat::createInstance() //---------------------------------------------------------------------- DateFormat* U_EXPORT2 -DateFormat::createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, - const Locale& locale) +DateFormat::createPatternInstance(const UnicodeString& skeleton, + const Locale& locale) { UErrorCode status = U_ZERO_ERROR; @@ -291,7 +290,6 @@ DateFormat::createInstance(const UnicodeString& skeleton, return NULL; } - // FIXME: use adjustFieldWidth later const UnicodeString pattern = dtptg->getBestPattern(skeleton, status); delete dtptg; if ( U_FAILURE(status) ) { diff --git a/icu4c/source/i18n/dtitvfmt.cpp b/icu4c/source/i18n/dtitvfmt.cpp index 1f9a42c0e45..fe152e0fff8 100644 --- a/icu4c/source/i18n/dtitvfmt.cpp +++ b/icu4c/source/i18n/dtitvfmt.cpp @@ -60,98 +60,22 @@ static const UChar gEarlierFirstPrefix[] = {LOW_E, LOW_A, LOW_R, LOW_L, LOW_I, L UOBJECT_DEFINE_RTTI_IMPLEMENTATION(DateIntervalFormat) -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createInstance(UErrorCode& status) { - return createInstance(Locale::getDefault(), status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createInstance(const Locale& locale, UErrorCode& status) { - return createDateTimeIntervalInstance(DateFormat::kDefault, - DateFormat::kDefault, locale, status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createDateIntervalInstance(DateFormat::EStyle style, - UErrorCode& status) { - return createDateIntervalInstance(style, Locale::getDefault(), status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createDateIntervalInstance(DateFormat::EStyle style, - const Locale& locale, - UErrorCode& status) { - if ( U_FAILURE(status) ) { - return NULL; - } - DateFormat* dtfmt = DateFormat::createDateInstance(style, locale); - DateIntervalInfo* dtitvinf = new DateIntervalInfo(locale, status); - // for CJK, even for non-short format, - // get skeleton will always return yMd. - // so, assign it directly instead of getting if from getSkeleton(). - UnicodeString skeleton = UnicodeString(gDateFormatSkeleton[(int32_t)style]); - return create(dtfmt, dtitvinf, &skeleton, status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createTimeIntervalInstance(DateFormat::EStyle style, - UErrorCode& status) { - return createTimeIntervalInstance(style, Locale::getDefault(), status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createTimeIntervalInstance(DateFormat::EStyle style, - const Locale& locale, - UErrorCode& status) { - return createDateTimeIntervalInstance(DateFormat::kNone, style, locale, status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createDateTimeIntervalInstance(DateFormat::EStyle dateStyle, - DateFormat::EStyle timeStyle, - UErrorCode& status) { - return createDateTimeIntervalInstance(dateStyle, timeStyle, Locale::getDefault(), status); -} - - -DateIntervalFormat* U_EXPORT2 -DateIntervalFormat::createDateTimeIntervalInstance(DateFormat::EStyle dateStyle, - DateFormat::EStyle timeStyle, - const Locale& locale, - UErrorCode& status) { - if ( U_FAILURE(status) ) { - return NULL; - } - DateFormat* dtfmt = DateFormat::createDateTimeInstance(dateStyle, timeStyle, locale); - DateIntervalInfo* dtitvinf = new DateIntervalInfo(locale, status); - return create(dtfmt, dtitvinf, status); -} - - DateIntervalFormat* U_EXPORT2 DateIntervalFormat::createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, UErrorCode& status) { - return createInstance(skeleton, adjustFieldWidth, Locale::getDefault(), status); + return createInstance(skeleton, Locale::getDefault(), status); } DateIntervalFormat* U_EXPORT2 DateIntervalFormat::createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, const Locale& locale, UErrorCode& status) { if ( U_FAILURE(status) ) { return NULL; } - DateFormat* dtfmt = DateFormat::createInstance(skeleton, adjustFieldWidth, locale); + DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale); #ifdef DTITVFMT_DEBUG char result[1000]; @@ -173,16 +97,14 @@ DateIntervalFormat::createInstance(const UnicodeString& skeleton, DateIntervalFormat* U_EXPORT2 DateIntervalFormat::createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, DateIntervalInfo* dtitvinf, UErrorCode& status) { - return createInstance(skeleton, adjustFieldWidth, Locale::getDefault(), dtitvinf, status); + return createInstance(skeleton, Locale::getDefault(), dtitvinf, status); } DateIntervalFormat* U_EXPORT2 DateIntervalFormat::createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, const Locale& locale, DateIntervalInfo* dtitvinf, UErrorCode& status) { @@ -190,7 +112,7 @@ DateIntervalFormat::createInstance(const UnicodeString& skeleton, delete dtitvinf; return NULL; } - DateFormat* dtfmt = DateFormat::createInstance(skeleton, adjustFieldWidth, locale); + DateFormat* dtfmt = DateFormat::createPatternInstance(skeleton, locale); return create(dtfmt, dtitvinf, &skeleton, status); } diff --git a/icu4c/source/i18n/unicode/datefmt.h b/icu4c/source/i18n/unicode/datefmt.h index 23a3afb09c9..d64dec578a9 100644 --- a/icu4c/source/i18n/unicode/datefmt.h +++ b/icu4c/source/i18n/unicode/datefmt.h @@ -417,7 +417,7 @@ public: * Create a date/time formatter from skeleton and a given locale. * * Users are encouraged to use the skeleton macros defined in udat.h. - * For example, MONTH_DOW_DAY_LONG_FORMAT, which is "MMMMEEEEd", + * For example, MONTH_WEEKDAY_DAY, which is "MMMMEEEEd", * and which means the pattern should have day, month, and day-of-week * fields, and follow the long date format defined in date time pattern. * For example, for English, the full pattern should be @@ -428,16 +428,12 @@ public: * After which, this API will be replaced. * * @param skeleton the skeleton on which date format based. - * @param adjustFieldWidth whether adjust the skeleton field width or not. - * It is used for DateTimePatternGenerator to - * adjust field width when get - * full pattern from skeleton. * @param locale the given locale. * @return a simple date formatter which the caller owns. * @internal ICU 4.0 */ - static DateFormat* U_EXPORT2 createInstance(const UnicodeString& skeleton, - UBool adjustFieldWidth, + static DateFormat* U_EXPORT2 createPatternInstance( + const UnicodeString& skeleton, const Locale& locale); /** diff --git a/icu4c/source/i18n/unicode/dtitvfmt.h b/icu4c/source/i18n/unicode/dtitvfmt.h index cac55920abf..d6526301166 100644 --- a/icu4c/source/i18n/unicode/dtitvfmt.h +++ b/icu4c/source/i18n/unicode/dtitvfmt.h @@ -85,23 +85,6 @@ U_NAMESPACE_BEGIN * * *

- * There is a set of pre-defined static skeleton strings. - * The skeletons defined consist of the desired calendar field set - * (for example, DAY, MONTH, YEAR) and the format length (long, medium, short) - * used in date time patterns. - * - * For example, skeleton YEAR_MONTH_MEDIUM_FORMAT consists month and year, - * and it's corresponding full pattern is medium format date pattern. - * So, the skeleton is "yMMM", for English, the full pattern is "MMM yyyy", - * which is the format by removing DATE from medium date format. - * - * For example, skeleton YEAR_MONTH_DOW_DAY_MEDIUM_FORMAT consists day, month, - * year, and day-of-week, and it's corresponding full pattern is the medium - * format date pattern. So, the skeleton is "yMMMEEEd", for English, - * the full pattern is "EEE, MMM d, yyyy", which is the medium date format - * plus day-of-week. - * - *

* The calendar fields we support for interval formatting are: * year, month, date, day-of-week, am-pm, hour, hour-of-day, and minute. * Those calendar fields can be defined in the following order: @@ -114,9 +97,10 @@ U_NAMESPACE_BEGIN * and "Feb 20, 2008" is year. * *

+ * There is a set of pre-defined static skeleton strings. * There are pre-defined interval patterns for those pre-defined skeletons * in locales' resource files. - * For example, for a skeleton YEAR_MONTH_DAY_MEDIUM_FORMAT, which is "yMMMd", + * For example, for a skeleton UDAT_YEAR_ABBR_MONTH_DAY, which is "yMMMd", * in en_US, if the largest different calendar field between date1 and date2 * is "year", the date interval pattern is "MMM d, yyyy - MMM d, yyyy", * such as "Jan 10, 2007 - Jan 10, 2008". @@ -175,20 +159,12 @@ U_NAMESPACE_BEGIN * It can be instantiated in several ways: *