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: *
- * 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: @@ -99,9 +82,10 @@ static UBool U_CALLCONV hashTableValueComparator(UHashTok val1, UHashTok val2) ; * 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". diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp index 86f49b545e3..e1a17d97b5f 100644 --- a/icu4c/source/test/intltest/dtifmtts.cpp +++ b/icu4c/source/test/intltest/dtifmtts.cpp @@ -52,123 +52,12 @@ void DateIntervalFormatTest::runIndexedTest( int32_t index, UBool exec, const ch */ void DateIntervalFormatTest::testAPI() { - // ======= Test create instance with default local - UErrorCode status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create instance with defaule locale"); - - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (default) - exitting"); - return; - } else { - delete dtitvfmt; - } - - // ======= Test create instance with given locale - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create instance with given locale"); - - dtitvfmt = DateIntervalFormat::createInstance(Locale::getGerman(), status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (given locale) - exitting"); - return; - } else { - delete dtitvfmt; - } - - /* ====== Test create date interval instance with default locale and - * ====== date format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create date instance with default locale and date format style"); - - dtitvfmt = DateIntervalFormat::createDateIntervalInstance(DateFormat::kFull, status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (default local + date style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - /* ====== Test create date interval instance with given locale and - * ====== date format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create date instance with given locale and date format style"); - - dtitvfmt = DateIntervalFormat::createDateIntervalInstance(DateFormat::kFull, Locale::getFrench(), status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (local + date style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - - /* ====== Test create time interval instance with default locale and - * ====== time format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create time instance with default locale and time format style"); - - dtitvfmt = DateIntervalFormat::createTimeIntervalInstance(DateFormat::kLong, status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (default local + time style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - /* ====== Test create time interval instance with given locale and - * ====== time format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create time instance with given locale and time format style"); - - dtitvfmt = DateIntervalFormat::createTimeIntervalInstance(DateFormat::kLong, Locale::getItalian(), status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (local + time style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - /* ====== Test create date time interval instance with default locale and - * ====== date time format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create date time instance with iven locale and date time format style"); - - dtitvfmt = DateIntervalFormat::createDateTimeIntervalInstance(DateFormat::kMedium, DateFormat::kShort, status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (default locale + date time style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - - /* ====== Test create date time interval instance with given locale and - * ====== date time format style - */ - status = U_ZERO_ERROR; - logln("Testing DateIntervalFormat create date time instance with given locale and date time format style"); - - dtitvfmt = DateIntervalFormat::createDateTimeIntervalInstance(DateFormat::kMedium, DateFormat::kShort, Locale::getItalian(), status); - if(U_FAILURE(status)) { - dataerrln("ERROR: Could not create DateIntervalFormat (local + date time style) - exitting"); - return; - } else { - delete dtitvfmt; - } - - /* ====== Test create interval instance with default locale and skeleton */ - status = U_ZERO_ERROR; + UErrorCode status = U_ZERO_ERROR; logln("Testing DateIntervalFormat create instance with default locale and skeleton"); - dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_LONG_FORMAT, FALSE, status); + DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_LONG_FORMAT, status); if(U_FAILURE(status)) { dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + default locale) - exitting"); return; @@ -182,7 +71,7 @@ void DateIntervalFormatTest::testAPI() { status = U_ZERO_ERROR; logln("Testing DateIntervalFormat create instance with given locale and skeleton"); - dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_LONG_FORMAT, FALSE, Locale::getJapanese(), status); + dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_LONG_FORMAT, Locale::getJapanese(), status); if(U_FAILURE(status)) { dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + locale) - exitting"); return; @@ -198,7 +87,7 @@ void DateIntervalFormatTest::testAPI() { DateIntervalInfo* dtitvinf = new DateIntervalInfo(Locale::getSimplifiedChinese(), status); - dtitvfmt = DateIntervalFormat::createInstance("EEEdMMMyhms", FALSE, dtitvinf, status); + dtitvfmt = DateIntervalFormat::createInstance("EEEdMMMyhms", dtitvinf, status); if(U_FAILURE(status)) { dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + DateIntervalInfo + default locale) - exitting"); return; @@ -214,7 +103,7 @@ void DateIntervalFormatTest::testAPI() { dtitvinf = new DateIntervalInfo(Locale::getSimplifiedChinese(), status); - dtitvfmt = DateIntervalFormat::createInstance("EEEdMMMyhms", FALSE, Locale::getSimplifiedChinese(), dtitvinf, status); + dtitvfmt = DateIntervalFormat::createInstance("EEEdMMMyhms", Locale::getSimplifiedChinese(), dtitvinf, status); if(U_FAILURE(status)) { dataerrln("ERROR: Could not create DateIntervalFormat (skeleton + DateIntervalInfo + locale) - exitting"); return; @@ -462,66 +351,11 @@ void DateIntervalFormatTest::expect(const char** data, int32_t data_length, if (!assertSuccess("parse", ec)) return; DateInterval dtitv(date, date_2); - for ( DateFormat::EStyle style = DateFormat::kFull; - style < DateFormat::kDateOffset; - style = (DateFormat::EStyle)(style+1) ) { - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createDateIntervalInstance(style, loc, ec); - FieldPosition pos=0; - if (!assertSuccess("createDateInstance", ec)) return; - dtitvfmt->format(&dtitv, str.remove(), pos, ec); - if (!assertSuccess("format", ec)) return; -#ifdef DTIFMTTS_DEBUG - sprintf(mesg, "date interval, style = %d\n", style); - PRINTMESG(mesg) - str.extract(0, str.length(), result, "UTF-8"); - sprintf(mesg, "interval date: %s\n", result); - PRINTMESG(mesg) -#endif - delete dtitvfmt; - } - - for ( DateFormat::EStyle style = DateFormat::kFull; - style < DateFormat::kDateOffset; - style = (DateFormat::EStyle)(style+1) ) { - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createTimeIntervalInstance(style, loc, ec); - - if (!assertSuccess("createTimeInstance", ec)) return; - FieldPosition pos=0; - dtitvfmt->format(&dtitv, str.remove(), pos, ec); - if (!assertSuccess("format", ec)) return; -#ifdef DTIFMTTS_DEBUG - sprintf(mesg, "time interval, style = %d\n", style); - PRINTMESG(mesg) - str.extract(0, str.length(), result, "UTF-8"); - sprintf(mesg, "interval date: %s\n", result); - PRINTMESG(mesg) -#endif - delete dtitvfmt; - } - - for ( DateFormat::EStyle style = DateFormat::kFull; - style < DateFormat::kDateOffset; - style = (DateFormat::EStyle)(style+1) ) { - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createDateTimeIntervalInstance(style, style, loc, ec); - if (!assertSuccess("createDateTimeInstance", ec)) return; - FieldPosition pos=0; - dtitvfmt->format(&dtitv, str.remove(), pos, ec); - if (!assertSuccess("format", ec)) return; -#ifdef DTIFMTTS_DEBUG - sprintf(mesg, "date time interval, style = %d\n", style); - PRINTMESG(mesg) - str.extract(0, str.length(), result, "UTF-8"); - sprintf(mesg, "interval date: %s\n", result); - PRINTMESG(mesg) -#endif - delete dtitvfmt; - } - for ( uint32_t skeletonIndex = 0; skeletonIndex < ARRAY_SIZE(skeleton); ++skeletonIndex ) { const UnicodeString& oneSkeleton = skeleton[skeletonIndex]; - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(oneSkeleton, FALSE, loc, ec); + DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(oneSkeleton, loc, ec); if (!assertSuccess("createInstance(skeleton)", ec)) return; FieldPosition pos=0; dtitvfmt->format(&dtitv, str.remove(), pos, ec); @@ -545,7 +379,7 @@ void DateIntervalFormatTest::expect(const char** data, int32_t data_length, if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec)) return; dtitvinf->setIntervalPattern(YEAR_MONTH_DAY_MEDIUM_FORMAT, UCAL_HOUR_OF_DAY, "yyyy MMM d HH:mm - HH:mm", ec); if (!assertSuccess("DateIntervalInfo::setIntervalPattern", ec)) return; - DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_MEDIUM_FORMAT, FALSE, loc, dtitvinf, ec); + DateIntervalFormat* dtitvfmt = DateIntervalFormat::createInstance(YEAR_MONTH_DAY_MEDIUM_FORMAT, loc, dtitvinf, ec); if (!assertSuccess("createInstance(skeleton,dtitvinf)", ec)) return; FieldPosition pos=0; dtitvfmt->format(&dtitv, str.remove(), pos, ec);