diff --git a/intl/locale/DateTimeFormat.cpp b/intl/locale/DateTimeFormat.cpp index 51a547d9b6ab..3c87f95452f1 100644 --- a/intl/locale/DateTimeFormat.cpp +++ b/intl/locale/DateTimeFormat.cpp @@ -74,8 +74,6 @@ nsresult DateTimeFormat::FormatDateTime( UErrorCode status = U_ZERO_ERROR; nsAutoString skeleton; - nsAutoString pattern; - switch (aSkeleton) { case Skeleton::yyyyMM: skeleton.AssignASCII("yyyyMM"); @@ -87,28 +85,10 @@ nsresult DateTimeFormat::FormatDateTime( MOZ_ASSERT_UNREACHABLE("Unhandled skeleton enum"); } - UDateTimePatternGenerator* patternGenerator = - udatpg_open(mLocale->get(), &status); - if (U_SUCCESS(status)) { - int32_t patternLength; - pattern.SetLength(DATETIME_FORMAT_INITIAL_LEN); - patternLength = udatpg_getBestPattern( - patternGenerator, - reinterpret_cast(skeleton.BeginReading()), - skeleton.Length(), reinterpret_cast(pattern.BeginWriting()), - DATETIME_FORMAT_INITIAL_LEN, &status); - pattern.SetLength(patternLength); - - if (status == U_BUFFER_OVERFLOW_ERROR) { - status = U_ZERO_ERROR; - udatpg_getBestPattern( - patternGenerator, - reinterpret_cast(skeleton.BeginReading()), - skeleton.Length(), reinterpret_cast(pattern.BeginWriting()), - patternLength, &status); - } + nsAutoString pattern; + if (!OSPreferences::GetPatternForSkeleton(skeleton, *mLocale, pattern)) { + return NS_ERROR_FAILURE; } - udatpg_close(patternGenerator); nsAutoString timeZoneID; BuildTimeZoneString(aExplodedTime->tm_params, timeZoneID); diff --git a/intl/locale/OSPreferences.h b/intl/locale/OSPreferences.h index dc327cc7d006..96fe7bcbc6ca 100644 --- a/intl/locale/OSPreferences.h +++ b/intl/locale/OSPreferences.h @@ -77,6 +77,10 @@ class OSPreferences : public mozIOSPreferences { return RefPtr(GetInstance()).forget(); } + static bool GetPatternForSkeleton(const nsAString& aSkeleton, + const nsACString& aLocale, + nsAString& aRetVal); + static bool GetDateTimeConnectorPattern(const nsACString& aLocale, nsAString& aRetVal); @@ -121,9 +125,6 @@ class OSPreferences : public mozIOSPreferences { const nsACString& aLocale, nsAString& aRetVal); - bool GetPatternForSkeleton(const nsAString& aSkeleton, - const nsACString& aLocale, nsAString& aRetVal); - /** * This is a host environment specific method that will be implemented * separately for each platform.