diff options
author | Job Bautista <jobbautista9@protonmail.com> | 2022-07-25 14:07:36 +0800 |
---|---|---|
committer | Job Bautista <jobbautista9@protonmail.com> | 2022-07-25 14:07:36 +0800 |
commit | 824c2f0d4012f8e718dcca5c3db9b796a7530008 (patch) | |
tree | af2af37f56790bd99566c5566fafef3ec6b266de /intl | |
parent | 6542ca6bcdf836ee1fb82b75d77adb0e9604b97b (diff) | |
download | uxp-824c2f0d4012f8e718dcca5c3db9b796a7530008.tar.gz |
Issue #1969 - Implement Intl.RelativeTimeFormat.
Based on Mozilla bugs 1270140, 1504656, 1483545, and 1504334.
Took note of Mozilla bug 1379222 which changed GetPrototypeFromCallableConstructor
to GetPrototypeFromBuiltinConstructor.
There are many other changes I did myself since the initial implementation by
Mozilla wouldn't work with this codebase.
Diffstat (limited to 'intl')
-rw-r--r-- | intl/icu-patches/bug-1504656-relativetimeformat-plural-other-fallback.diff | 45 | ||||
-rw-r--r-- | intl/icu/source/i18n/reldatefmt.cpp | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | intl/patch-icu.sh | 2 | ||||
-rwxr-xr-x | intl/update-icu.sh | 5 |
4 files changed, 63 insertions, 9 deletions
diff --git a/intl/icu-patches/bug-1504656-relativetimeformat-plural-other-fallback.diff b/intl/icu-patches/bug-1504656-relativetimeformat-plural-other-fallback.diff new file mode 100644 index 0000000000..060ea5c0bf --- /dev/null +++ b/intl/icu-patches/bug-1504656-relativetimeformat-plural-other-fallback.diff @@ -0,0 +1,45 @@ +Workaround for https://unicode-org.atlassian.net/browse/ICU-20253 + +https://bugzilla.mozilla.org/show_bug.cgi?id=1504656 + +diff --git a/intl/icu/source/i18n/reldatefmt.cpp b/intl/icu/source/i18n/reldatefmt.cpp +--- a/intl/icu/source/i18n/reldatefmt.cpp ++++ b/intl/icu/source/i18n/reldatefmt.cpp +@@ -157,24 +157,30 @@ const UnicodeString& RelativeDateTimeCac + } + + // Use fallback cache for SimpleFormatter relativeUnits. + const SimpleFormatter* RelativeDateTimeCacheData::getRelativeDateTimeUnitFormatter( + int32_t fStyle, + URelativeDateTimeUnit unit, + int32_t pastFutureIndex, + int32_t pluralUnit) const { +- int32_t style = fStyle; +- do { +- if (relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit] != nullptr) { +- return relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit]; ++ while (true) { ++ int32_t style = fStyle; ++ do { ++ if (relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit] != nullptr) { ++ return relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit]; ++ } ++ style = fallBackCache[style]; ++ } while (style != -1); ++ ++ if (pluralUnit == StandardPlural::OTHER) { ++ return nullptr; // No formatter found. + } +- style = fallBackCache[style]; +- } while (style != -1); +- return nullptr; // No formatter found. ++ pluralUnit = StandardPlural::OTHER; ++ } + } + + static UBool getStringWithFallback( + const UResourceBundle *resource, + const char *key, + UnicodeString &result, + UErrorCode &status) { + int32_t len = 0; diff --git a/intl/icu/source/i18n/reldatefmt.cpp b/intl/icu/source/i18n/reldatefmt.cpp index 1a4da0f0b9..85637cb456 100644 --- a/intl/icu/source/i18n/reldatefmt.cpp +++ b/intl/icu/source/i18n/reldatefmt.cpp @@ -162,14 +162,20 @@ const UnicodeString& RelativeDateTimeCacheData::getAbsoluteUnitString( URelativeDateTimeUnit unit, int32_t pastFutureIndex, int32_t pluralUnit) const { - int32_t style = fStyle; - do { - if (relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit] != nullptr) { - return relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit]; + while (true) { + int32_t style = fStyle; + do { + if (relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit] != nullptr) { + return relativeUnitsFormatters[style][unit][pastFutureIndex][pluralUnit]; + } + style = fallBackCache[style]; + } while (style != -1); + + if (pluralUnit == StandardPlural::OTHER) { + return nullptr; // No formatter found. } - style = fallBackCache[style]; - } while (style != -1); - return nullptr; // No formatter found. + pluralUnit = StandardPlural::OTHER; + } } static UBool getStringWithFallback( diff --git a/intl/patch-icu.sh b/intl/patch-icu.sh index 4c8cd89cba..a8e9977ea5 100644..100755 --- a/intl/patch-icu.sh +++ b/intl/patch-icu.sh @@ -21,7 +21,9 @@ for patch in \ suppress-warnings.diff \ bug-1172609-timezone-recreateDefault.diff \ bug-1198952-workaround-make-3.82-bug.diff \ + bug-1504656-relativetimeformat-plural-other-fallback.diff \ ; do echo "Applying local patch $patch" patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch done + diff --git a/intl/update-icu.sh b/intl/update-icu.sh index 7e4c833c7b..ae22076ab3 100755 --- a/intl/update-icu.sh +++ b/intl/update-icu.sh @@ -7,11 +7,11 @@ set -e # Update to an ICU release: # Usage: update-icu.sh <URL of ICU GIT> <release tag name> -# E.g., for ICU 63.2: update-icu.sh https://github.com/unicode-org/icu.git release-63-2 +# E.g., for ICU 62.2: update-icu.sh https://github.com/unicode-org/icu.git release-62-2 # # Update to an ICU maintenance branch: # Usage: update-icu.sh <URL of ICU GIT> <maintenance name> -# E.g., for ICU 63.2: update-icu.sh https://github.com/unicode-org/icu.git maint/maint-63 +# E.g., for ICU 62.2: update-icu.sh https://github.com/unicode-org/icu.git maint/maint-62 if [ $# -lt 2 ]; then echo "Usage: update-icu.sh <URL of ICU GIT> <release tag name>" @@ -86,6 +86,7 @@ for patch in \ suppress-warnings.diff \ bug-1172609-timezone-recreateDefault.diff \ bug-1198952-workaround-make-3.82-bug.diff \ + bug-1504656-relativetimeformat-plural-other-fallback.diff \ ; do echo "Applying local patch $patch" patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch |