From a8aff4fc7bf09fb83675440af62819cbe64850fa Mon Sep 17 00:00:00 2001 From: Xiaomei Ji Date: Sat, 25 Oct 2008 00:31:55 +0000 Subject: [PATCH] ICU-6503 move createPatternInstance from DateFormat to DateIntervalFormat X-SVN-Rev: 24884 --- icu4c/source/i18n/datefmt.cpp | 23 --------------------- icu4c/source/i18n/dtitvfmt.cpp | 28 +++++++++++++++++++++++--- icu4c/source/i18n/unicode/datefmt.h | 30 ---------------------------- icu4c/source/i18n/unicode/dtitvfmt.h | 21 ++++++++++++++++++- 4 files changed, 45 insertions(+), 57 deletions(-) diff --git a/icu4c/source/i18n/datefmt.cpp b/icu4c/source/i18n/datefmt.cpp index b437f070b0..f04a41a4ec 100644 --- a/icu4c/source/i18n/datefmt.cpp +++ b/icu4c/source/i18n/datefmt.cpp @@ -275,29 +275,6 @@ DateFormat::createInstance() return create(kShort, (EStyle) (kShort + kDateOffset), Locale::getDefault()); } -//---------------------------------------------------------------------- -DateFormat* U_EXPORT2 -DateFormat::createPatternInstance(const UnicodeString& skeleton, - const Locale& locale, - DateTimePatternGenerator* dtpng, - UErrorCode& status) -{ - if ( U_FAILURE(status) ) { - return NULL; - } - - const UnicodeString pattern = dtpng->getBestPattern(skeleton, status); - if ( U_FAILURE(status) ) { - return NULL; - } - SimpleDateFormat* dtfmt = new SimpleDateFormat(pattern, locale, status); - if ( U_FAILURE(status) ) { - delete dtfmt; - return NULL; - } - return dtfmt; -} - //---------------------------------------------------------------------- DateFormat* U_EXPORT2 diff --git a/icu4c/source/i18n/dtitvfmt.cpp b/icu4c/source/i18n/dtitvfmt.cpp index 4b9f23f6ae..a38fb5e646 100644 --- a/icu4c/source/i18n/dtitvfmt.cpp +++ b/icu4c/source/i18n/dtitvfmt.cpp @@ -429,8 +429,8 @@ DateIntervalFormat::DateIntervalFormat(const Locale& locale, return; } fDtpng = DateTimePatternGenerator::createInstance(locale, status); - DateFormat* dtfmt = DateFormat::createPatternInstance(*skeleton, locale, - fDtpng, status); + SimpleDateFormat* dtfmt = createSDFPatternInstance(*skeleton, locale, + fDtpng, status); if ( U_FAILURE(status) ) { delete dtItvInfo; delete fDtpng; @@ -449,7 +449,7 @@ DateIntervalFormat::DateIntervalFormat(const Locale& locale, fSkeleton = *skeleton; } fInfo = dtItvInfo; - fDateFormat = (SimpleDateFormat*)dtfmt; + fDateFormat = dtfmt; if ( dtfmt->getCalendar() ) { fFromCalendar = dtfmt->getCalendar()->clone(); fToCalendar = dtfmt->getCalendar()->clone(); @@ -461,6 +461,28 @@ DateIntervalFormat::DateIntervalFormat(const Locale& locale, } +SimpleDateFormat* U_EXPORT2 +DateIntervalFormat::createSDFPatternInstance(const UnicodeString& skeleton, + const Locale& locale, + DateTimePatternGenerator* dtpng, + UErrorCode& status) +{ + if ( U_FAILURE(status) ) { + return NULL; + } + + const UnicodeString pattern = dtpng->getBestPattern(skeleton, status); + if ( U_FAILURE(status) ) { + return NULL; + } + SimpleDateFormat* dtfmt = new SimpleDateFormat(pattern, locale, status); + if ( U_FAILURE(status) ) { + delete dtfmt; + return NULL; + } + return dtfmt; +} + DateIntervalFormat* U_EXPORT2 DateIntervalFormat::create(const Locale& locale, diff --git a/icu4c/source/i18n/unicode/datefmt.h b/icu4c/source/i18n/unicode/datefmt.h index 86de11d26d..5b91ac1f08 100644 --- a/icu4c/source/i18n/unicode/datefmt.h +++ b/icu4c/source/i18n/unicode/datefmt.h @@ -414,36 +414,6 @@ public: */ static DateFormat* U_EXPORT2 createInstance(void); - /** - * This is for ICU internal use only. Please do not use. - * 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_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 - * "EEEE, MMMM d". - * - * Temporarily, this is an internal API, used by DateIntevalFormat only. - * There will be a new set of APIs for the same purpose coming soon. - * After which, this API will be replaced. - * - * @param skeleton the skeleton on which date format based. - * @param locale the given locale. - * @param dtpng the date time pattern generator. - * @param status Output param to be set to success/failure code. - * If it is failure, the returned date formatter will - * be NULL. - * @return a simple date formatter which the caller owns. - * @internal ICU 4.0 - */ - static DateFormat* U_EXPORT2 createPatternInstance( - const UnicodeString& skeleton, - const Locale& locale, - DateTimePatternGenerator* dtpng, - UErrorCode& status); - /** * Creates a time formatter with the given formatting style for the given * locale. diff --git a/icu4c/source/i18n/unicode/dtitvfmt.h b/icu4c/source/i18n/unicode/dtitvfmt.h index 86184ef6d4..61a3875307 100644 --- a/icu4c/source/i18n/unicode/dtitvfmt.h +++ b/icu4c/source/i18n/unicode/dtitvfmt.h @@ -609,9 +609,28 @@ private: const UnicodeString* skeleton, UErrorCode& status); + /** + * Create a simple date/time formatter from skeleton, given locale, + * and date time pattern generator. + * + * @param skeleton the skeleton on which date format based. + * @param locale the given locale. + * @param dtpng the date time pattern generator. + * @param status Output param to be set to success/failure code. + * If it is failure, the returned date formatter will + * be NULL. + * @return a simple date formatter which the caller owns. + * @internal ICU 4.0 + */ + static SimpleDateFormat* U_EXPORT2 createSDFPatternInstance( + const UnicodeString& skeleton, + const Locale& locale, + DateTimePatternGenerator* dtpng, + UErrorCode& status); + /** - * Below are for generating interval patterns locale to the formatter + * Below are for generating interval patterns local to the formatter */