Bug 1719551 - Part 1: Add DateTimePatternGenerator::GetPlaceholderPattern. r=platform-i18n-reviewers,anba,gregtatum

Differential Revision: https://phabricator.services.mozilla.com/D128460
This commit is contained in:
Yoshi Cheng-Hao Huang 2021-10-19 07:34:00 +00:00
Родитель e3df5fd682
Коммит e08bac2c1d
2 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -179,6 +179,14 @@ TEST(IntlDateTimePatternGenerator, GetSkeleton)
ASSERT_TRUE(buffer.verboseMatches(u"yMd"));
}
TEST(IntlDateTimePatternGenerator, GetPlaceholderPattern)
{
auto gen = DateTimePatternGenerator::TryCreate("en").unwrap();
auto span = gen->GetPlaceholderPattern();
// The default date-time pattern for 'en' locale is u"{1}, {0}".
ASSERT_EQ(span, MakeStringSpan(u"{1}, {0}"));
}
// A utility function to help test the DateTimeFormat::ComponentsBag.
[[nodiscard]] bool FormatComponents(
TestBuffer<char16_t>& aBuffer, DateTimeFormat::ComponentsBag& aComponents,

Просмотреть файл

@ -92,6 +92,28 @@ class DateTimePatternGenerator final {
});
}
/**
* Get a pattern of the form "{1} {0}" to combine separate date and time
* patterns into a single pattern. The "{0}" part is the placeholder for the
* time pattern and "{1}" is the placeholder for the date pattern.
*
* See dateTimeFormat from
* https://unicode.org/reports/tr35/tr35-dates.html#dateTimeFormat
*
* Note:
* In CLDR, it's called Date-Time Combined Format
* https://cldr.unicode.org/translation/date-time/datetime-patterns#h.x7ca7qwzh4m
*
* The naming 'placeholder pattern' is from ICU4X.
* https://unicode-org.github.io/icu4x-docs/doc/icu_pattern/index.html
*/
Span<const char16_t> GetPlaceholderPattern() const {
int32_t length;
const char16_t* combined =
udatpg_getDateTimeFormat(mGenerator.GetConst(), &length);
return Span{combined, static_cast<size_t>(length)};
}
/**
* TODO(Bug 1686965) - Temporarily get the underlying ICU object while
* migrating to the unified API. This should be removed when completing the