diff --git a/icu4c/source/i18n/reldatefmt.cpp b/icu4c/source/i18n/reldatefmt.cpp index a9b60057e0..61de3098ed 100644 --- a/icu4c/source/i18n/reldatefmt.cpp +++ b/icu4c/source/i18n/reldatefmt.cpp @@ -58,14 +58,13 @@ U_CDECL_END U_NAMESPACE_BEGIN -static int32_t getStyleIndex(UDateFormatStyle style) { +static int32_t getStyleIndex(UDateRelativeDateTimeFormatterStyle style) { switch (style) { - case UDAT_FULL: - case UDAT_LONG: + case UDAT_STYLE_LONG: return 0; - case UDAT_MEDIUM: + case UDAT_STYLE_SHORT: return 1; - case UDAT_SHORT: + case UDAT_STYLE_NARROW: return 2; default: return 0; @@ -669,7 +668,7 @@ RelativeDateTimeFormatter::RelativeDateTimeFormatter(UErrorCode& status) : fCache(NULL), fNumberFormat(NULL), fPluralRules(NULL), - fStyle(UDAT_FULL), + fStyle(UDAT_STYLE_LONG), fContext(UDISPCTX_CAPITALIZATION_NONE), fOptBreakIterator(NULL) { init(NULL, NULL, status); @@ -680,7 +679,7 @@ RelativeDateTimeFormatter::RelativeDateTimeFormatter( fCache(NULL), fNumberFormat(NULL), fPluralRules(NULL), - fStyle(UDAT_FULL), + fStyle(UDAT_STYLE_LONG), fContext(UDISPCTX_CAPITALIZATION_NONE), fOptBreakIterator(NULL), fLocale(locale) { @@ -692,7 +691,7 @@ RelativeDateTimeFormatter::RelativeDateTimeFormatter( fCache(NULL), fNumberFormat(NULL), fPluralRules(NULL), - fStyle(UDAT_FULL), + fStyle(UDAT_STYLE_LONG), fContext(UDISPCTX_CAPITALIZATION_NONE), fOptBreakIterator(NULL), fLocale(locale) { @@ -702,7 +701,7 @@ RelativeDateTimeFormatter::RelativeDateTimeFormatter( RelativeDateTimeFormatter::RelativeDateTimeFormatter( const Locale& locale, NumberFormat *nfToAdopt, - UDateFormatStyle styl, + UDateRelativeDateTimeFormatterStyle styl, UDisplayContext capitalizationContext, UErrorCode& status) : fCache(NULL), @@ -784,7 +783,7 @@ UDisplayContext RelativeDateTimeFormatter::getCapitalizationContext() const { return fContext; } -UDateFormatStyle RelativeDateTimeFormatter::getFormatStyle() const { +UDateRelativeDateTimeFormatterStyle RelativeDateTimeFormatter::getFormatStyle() const { return fStyle; } diff --git a/icu4c/source/i18n/unicode/reldatefmt.h b/icu4c/source/i18n/unicode/reldatefmt.h index bbff21194c..1ca375ebef 100644 --- a/icu4c/source/i18n/unicode/reldatefmt.h +++ b/icu4c/source/i18n/unicode/reldatefmt.h @@ -15,7 +15,6 @@ #include "unicode/utypes.h" #include "unicode/uobject.h" #include "unicode/udisplaycontext.h" -#include "unicode/udat.h" #include "unicode/locid.h" /** @@ -27,6 +26,31 @@ #ifndef U_HIDE_DRAFT_API +/** + * The formatting style + * @draft ICU 54 + */ +typedef enum UDateRelativeDateTimeFormatterStyle { + + /** + * Everything spelled out. + * @draft ICU 54 + */ + UDAT_STYLE_LONG, + + /** + * Abbreviations used when possible. + * @draft ICU 54 + */ + UDAT_STYLE_SHORT, + + /** + * Use the shortest possible form. + * @draft ICU 54 + */ + UDAT_STYLE_NARROW, +}; + /** * Represents the unit for formatting a relative date. e.g "in 5 days" * or "in 3 months" @@ -345,7 +369,7 @@ public: RelativeDateTimeFormatter( const Locale& locale, NumberFormat *nfToAdopt, - UDateFormatStyle style, + UDateRelativeDateTimeFormatterStyle style, UDisplayContext capitalizationContext, UErrorCode& status); @@ -445,12 +469,12 @@ public: * * @draft ICU 54 */ - UDateFormatStyle getFormatStyle() const; + UDateRelativeDateTimeFormatterStyle getFormatStyle() const; private: const RelativeDateTimeCacheData* fCache; const SharedNumberFormat *fNumberFormat; const SharedPluralRules *fPluralRules; - UDateFormatStyle fStyle; + UDateRelativeDateTimeFormatterStyle fStyle; UDisplayContext fContext; const SharedBreakIterator *fOptBreakIterator; Locale fLocale; diff --git a/icu4c/source/test/intltest/reldatefmttest.cpp b/icu4c/source/test/intltest/reldatefmttest.cpp index eeda64c6d6..76dd84de7a 100644 --- a/icu4c/source/test/intltest/reldatefmttest.cpp +++ b/icu4c/source/test/intltest/reldatefmttest.cpp @@ -550,7 +550,7 @@ private: int32_t expectedResultLength); void RunTest( const Locale& locale, - UDateFormatStyle style, + UDateRelativeDateTimeFormatterStyle style, const WithQuantityExpected* expectedResults, int32_t expectedResultLength); void RunTest( @@ -559,7 +559,7 @@ private: int32_t expectedResultLength); void RunTest( const Locale& locale, - UDateFormatStyle style, + UDateRelativeDateTimeFormatterStyle style, const WithoutQuantityExpected* expectedResults, int32_t expectedResultLength); void RunTest( @@ -625,7 +625,7 @@ void RelativeDateTimeFormatterTest::TestEnglishCaps() { RelativeDateTimeFormatter fmt( "en", NULL, - UDAT_FULL, + UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); RelativeDateTimeFormatter fmt3(status); @@ -638,11 +638,11 @@ void RelativeDateTimeFormatterTest::TestEnglishCaps() { } void RelativeDateTimeFormatterTest::TestEnglishShort() { - RunTest("en", UDAT_MEDIUM, kEnglishShort, LENGTHOF(kEnglishShort)); + RunTest("en", UDAT_STYLE_SHORT, kEnglishShort, LENGTHOF(kEnglishShort)); } void RelativeDateTimeFormatterTest::TestEnglishNarrow() { - RunTest("en", UDAT_SHORT, kEnglishNarrow, LENGTHOF(kEnglishNarrow)); + RunTest("en", UDAT_STYLE_NARROW, kEnglishNarrow, LENGTHOF(kEnglishNarrow)); } void RelativeDateTimeFormatterTest::TestSerbian() { @@ -650,7 +650,7 @@ void RelativeDateTimeFormatterTest::TestSerbian() { } void RelativeDateTimeFormatterTest::TestSerbianFallback() { - RunTest("sr", UDAT_SHORT, kSerbian, LENGTHOF(kSerbian)); + RunTest("sr", UDAT_STYLE_NARROW, kSerbian, LENGTHOF(kSerbian)); } void RelativeDateTimeFormatterTest::TestEnglishNoQuantity() { @@ -662,7 +662,7 @@ void RelativeDateTimeFormatterTest::TestEnglishNoQuantityCaps() { RelativeDateTimeFormatter fmt( "en", NULL, - UDAT_FULL, + UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE, status); assertSuccess("", status); @@ -676,7 +676,7 @@ void RelativeDateTimeFormatterTest::TestEnglishNoQuantityCaps() { void RelativeDateTimeFormatterTest::TestEnglishNoQuantityShort() { RunTest( "en", - UDAT_MEDIUM, + UDAT_STYLE_SHORT, kEnglishNoQuantityShort, LENGTHOF(kEnglishNoQuantityShort)); } @@ -684,7 +684,7 @@ void RelativeDateTimeFormatterTest::TestEnglishNoQuantityShort() { void RelativeDateTimeFormatterTest::TestEnglishNoQuantityNarrow() { RunTest( "en", - UDAT_SHORT, + UDAT_STYLE_NARROW, kEnglishNoQuantityNarrow, LENGTHOF(kEnglishNoQuantityNarrow)); } @@ -747,7 +747,7 @@ void RelativeDateTimeFormatterTest::TestGetters() { RelativeDateTimeFormatter fmt( "en", NULL, - UDAT_SHORT, + UDAT_STYLE_NARROW, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, status); RelativeDateTimeFormatter fmt3(status); @@ -755,7 +755,7 @@ void RelativeDateTimeFormatterTest::TestGetters() { // copy and assignment. RelativeDateTimeFormatter fmt2(fmt); fmt3 = fmt2; - assertEquals("style", UDAT_SHORT, fmt3.getFormatStyle()); + assertEquals("style", UDAT_STYLE_NARROW, fmt3.getFormatStyle()); assertEquals( "context", UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, @@ -785,7 +785,7 @@ void RelativeDateTimeFormatterTest::TestCombineDateAndTime() { void RelativeDateTimeFormatterTest::TestBadDisplayContext() { UErrorCode status = U_ZERO_ERROR; RelativeDateTimeFormatter fmt( - "en", NULL, UDAT_FULL, UDISPCTX_STANDARD_NAMES, status); + "en", NULL, UDAT_STYLE_LONG, UDISPCTX_STANDARD_NAMES, status); if (status != U_ILLEGAL_ARGUMENT_ERROR) { errln("Expected U_ILLEGAL_ARGUMENT_ERROR, got %s", u_errorName(status)); } @@ -808,7 +808,7 @@ void RelativeDateTimeFormatterTest::RunTest( void RelativeDateTimeFormatterTest::RunTest( const Locale& locale, - UDateFormatStyle style, + UDateRelativeDateTimeFormatterStyle style, const WithQuantityExpected* expectedResults, int32_t expectedResultLength) { UErrorCode status = U_ZERO_ERROR; @@ -836,7 +836,7 @@ void RelativeDateTimeFormatterTest::RunTest( void RelativeDateTimeFormatterTest::RunTest( const Locale& locale, - UDateFormatStyle style, + UDateRelativeDateTimeFormatterStyle style, const WithoutQuantityExpected* expectedResults, int32_t expectedResultLength) { UErrorCode status = U_ZERO_ERROR;