mirror of
https://github.com/Samsung/escargot.git
synced 2026-06-22 10:01:50 +00:00
RelativeTimeFormat should have own NumberFormat
Signed-off-by: Seonghyun Kim <sh8281.kim@samsung.com>
This commit is contained in:
parent
a526fc2ad8
commit
989e924b49
6 changed files with 37 additions and 10 deletions
|
|
@ -66,8 +66,8 @@ IntlRelativeTimeFormatObject::IntlRelativeTimeFormatObject(ExecutionState& state
|
|||
#if defined(ENABLE_RUNTIME_ICU_BINDER)
|
||||
UVersionInfo versionArray;
|
||||
u_getVersion(versionArray);
|
||||
if (versionArray[0] < 62) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Intl.NumberFormat needs 62+ version of ICU");
|
||||
if (versionArray[0] < 68) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "Intl.NumberFormat needs 68+ version of ICU");
|
||||
}
|
||||
#endif
|
||||
// Let requestedLocales be ? CanonicalizeLocaleList(locales).
|
||||
|
|
@ -143,6 +143,31 @@ IntlRelativeTimeFormatObject::IntlRelativeTimeFormatObject(ExecutionState& state
|
|||
// Let relativeTimeFormat.[[PluralRules]] be ! Construct(%PluralRules%, « locale »).
|
||||
// Return relativeTimeFormat.
|
||||
|
||||
StringBuilder dataLocaleBuilder;
|
||||
dataLocaleBuilder.appendString(m_dataLocale);
|
||||
dataLocaleBuilder.appendString("-u-nu-");
|
||||
dataLocaleBuilder.appendString(m_numberingSystem);
|
||||
String* dataLocaleWithExtensions = dataLocaleBuilder.finalize();
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
m_icuNumberFormat = unum_open(UNUM_DECIMAL, nullptr, 0, dataLocaleWithExtensions->toNonGCUTF8StringData().data(), nullptr, &status);
|
||||
if (UNLIKELY(U_FAILURE(status))) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "failed to initialize RelativeTimeFormat");
|
||||
}
|
||||
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_MIN_INTEGER_DIGITS, 1);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_MIN_FRACTION_DIGITS, 0);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_MAX_FRACTION_DIGITS, 3);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_GROUPING_USED, true);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_GROUPING_SIZE, UNUM_MINIMUM_GROUPING_DIGITS_AUTO);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_SECONDARY_GROUPING_SIZE, UNUM_MINIMUM_GROUPING_DIGITS_AUTO);
|
||||
unum_setAttribute(m_icuNumberFormat, UNUM_MINIMUM_GROUPING_DIGITS, UNUM_MINIMUM_GROUPING_DIGITS_AUTO);
|
||||
UNumberFormat* clonedNumberFormat = unum_clone(m_icuNumberFormat, &status);
|
||||
|
||||
if (UNLIKELY(U_FAILURE(status))) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "failed to initialize RelativeTimeFormat");
|
||||
}
|
||||
|
||||
UDateRelativeDateTimeFormatterStyle icuStyle;
|
||||
if (m_style->equals("short")) {
|
||||
icuStyle = UDAT_STYLE_SHORT;
|
||||
|
|
@ -153,8 +178,7 @@ IntlRelativeTimeFormatObject::IntlRelativeTimeFormatObject(ExecutionState& state
|
|||
icuStyle = UDAT_STYLE_LONG;
|
||||
}
|
||||
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
m_icuRelativeDateTimeFormatter = ureldatefmt_open(m_locale->toNonGCUTF8StringData().data(), nullptr, icuStyle, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status);
|
||||
m_icuRelativeDateTimeFormatter = ureldatefmt_open(dataLocaleWithExtensions->toNonGCUTF8StringData().data(), clonedNumberFormat, icuStyle, UDISPCTX_CAPITALIZATION_FOR_STANDALONE, &status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
ErrorObject::throwBuiltinError(state, ErrorCode::TypeError, "failed to initialize RelativeTimeFormat");
|
||||
|
|
@ -163,6 +187,7 @@ IntlRelativeTimeFormatObject::IntlRelativeTimeFormatObject(ExecutionState& state
|
|||
addFinalizer([](PointerValue* obj, void* data) {
|
||||
IntlRelativeTimeFormatObject* self = (IntlRelativeTimeFormatObject*)obj;
|
||||
ureldatefmt_close(self->m_icuRelativeDateTimeFormatter);
|
||||
unum_close(self->m_icuNumberFormat);
|
||||
},
|
||||
nullptr);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ protected:
|
|||
String* m_numeric;
|
||||
|
||||
URelativeDateTimeFormatter* m_icuRelativeDateTimeFormatter;
|
||||
UNumberFormat* m_icuNumberFormat;
|
||||
};
|
||||
|
||||
} // namespace Escargot
|
||||
|
|
|
|||
1
third_party/runtime_icu_binder/ICUPolyfill.h
vendored
1
third_party/runtime_icu_binder/ICUPolyfill.h
vendored
|
|
@ -92,6 +92,7 @@
|
|||
#define unum_formatDouble RuntimeICUBinder::ICU::instance().unum_formatDouble
|
||||
#define unum_formatDoubleForFields RuntimeICUBinder::ICU::instance().unum_formatDoubleForFields
|
||||
#define unum_close RuntimeICUBinder::ICU::instance().unum_close
|
||||
#define unum_clone RuntimeICUBinder::ICU::instance().unum_clone
|
||||
|
||||
#define udat_getAvailable RuntimeICUBinder::ICU::instance().udat_getAvailable
|
||||
#define udat_countAvailable RuntimeICUBinder::ICU::instance().udat_countAvailable
|
||||
|
|
|
|||
5
third_party/runtime_icu_binder/ICUTypes.h
vendored
5
third_party/runtime_icu_binder/ICUTypes.h
vendored
|
|
@ -6581,6 +6581,11 @@ typedef enum UNumberFormatAttribute {
|
|||
UNUM_LIMIT_BOOLEAN_ATTRIBUTE = 0x1003
|
||||
} UNumberFormatAttribute;
|
||||
|
||||
typedef enum UNumberFormatMinimumGroupingDigits {
|
||||
UNUM_MINIMUM_GROUPING_DIGITS_AUTO = -2,
|
||||
UNUM_MINIMUM_GROUPING_DIGITS_MIN2 = -3,
|
||||
} UNumberFormatMinimumGroupingDigits;
|
||||
|
||||
// uloc.h
|
||||
|
||||
/** Useful constant for this language. @stable ICU 2.0 */
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ namespace RuntimeICUBinder {
|
|||
F(unum_open, UNumberFormat*(CALLCONV*)(UNumberFormatStyle style, const UChar* pattern, int32_t patternLength, const char* locale, UParseError* parseErr, UErrorCode* status), UNumberFormat*) \
|
||||
F(unum_formatDouble, int32_t(CALLCONV*)(const UNumberFormat* fmt, double number, UChar* result, int32_t resultLength, UFieldPosition* pos, UErrorCode* status), int32_t) \
|
||||
F(unum_formatDoubleForFields, int32_t(CALLCONV*)(const UNumberFormat* format, double number, UChar* result, int32_t resultLength, UFieldPositionIterator* fpositer, UErrorCode* status), int32_t) \
|
||||
F(unum_clone, UNumberFormat*(CALLCONV*)(const UNumberFormat* fmt, UErrorCode* status), UNumberFormat*) \
|
||||
F(ubrk_open, UBreakIterator*(CALLCONV*)(UBreakIteratorType type, const char* locale, const UChar* text, int32_t textLength, UErrorCode* status), UBreakIterator*) \
|
||||
F(ubrk_openRules, UBreakIterator*(CALLCONV*)(const UChar* rules, int32_t rulesLength, const UChar* text, int32_t textLength, UParseError* parseErr, UErrorCode* status), UBreakIterator*) \
|
||||
F(ubrk_next, int32_t(CALLCONV*)(UBreakIterator * bi), int32_t) \
|
||||
|
|
|
|||
|
|
@ -4652,12 +4652,6 @@
|
|||
<test id="intl402/Locale/extensions-grandfathered"><reason>TODO</reason></test>
|
||||
<test id="intl402/Locale/getters-grandfathered"><reason>TODO</reason></test>
|
||||
<test id="intl402/Locale/likely-subtags-grandfathered"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-long"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-narrow"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/format/pl-pl-style-short"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-long"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-narrow"><reason>TODO</reason></test>
|
||||
<test id="intl402/RelativeTimeFormat/prototype/formatToParts/pl-pl-style-short"><reason>TODO</reason></test>
|
||||
<test id="intl402/Temporal/Duration/compare/relativeto-hour"><reason>TODO</reason></test>
|
||||
<test id="intl402/Temporal/Duration/compare/relativeto-sub-minute-offset"><reason>TODO</reason></test>
|
||||
<test id="intl402/Temporal/Duration/compare/twenty-five-hour-day"><reason>TODO</reason></test>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue