[INTL] Implement Intl.DateTimeFormat.prototype.formatToParts
https://bugs.webkit.org/show_bug.cgi?id=169458
Patch by Andy VanWagoner <thetalecrafter@gmail.com> on 2017-04-21
Reviewed by JF Bastien.
Source/JavaScriptCore:
Use udat_formatForFields to iterate through the parts of a formatted date string.
Make formatToParts and related functions dependent on ICU version >= 55.
* icu/unicode/udat.h: Update to 55.1.
* icu/unicode/ufieldpositer.h: Added from 55.1.
* icu/unicode/uvernum.h: Update to 55.1
* runtime/IntlDateTimeFormat.cpp:
(JSC::IntlDateTimeFormat::partTypeString): Convert UDateFormatField to string.
(JSC::IntlDateTimeFormat::formatToParts): Return parts of formatted date string.
* runtime/IntlDateTimeFormat.h:
* runtime/IntlDateTimeFormatPrototype.cpp:
(JSC::IntlDateTimeFormatPrototypeFuncFormatToParts): Add prototype function formatToParts.
LayoutTests:
Add tests for formatToParts
* js/intl-datetimeformat-expected.txt:
* js/script-tests/intl-datetimeformat.js:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@215616 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h
index f2e35d1..473db81 100644
--- a/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h
+++ b/Source/JavaScriptCore/runtime/IntlDateTimeFormat.h
@@ -29,6 +29,11 @@
#include "JSDestructibleObject.h"
#include <unicode/udat.h>
+#include <unicode/uvernum.h>
+
+#if U_ICU_VERSION_MAJOR_NUM >= 55
+#define JSC_ICU_HAS_UFIELDPOSITER 1
+#endif
namespace JSC {
@@ -46,6 +51,9 @@
void initializeDateTimeFormat(ExecState&, JSValue locales, JSValue options);
JSValue format(ExecState&, double value);
+#if JSC_ICU_HAS_UFIELDPOSITER
+ JSValue formatToParts(ExecState&, double value);
+#endif
JSObject* resolvedOptions(ExecState&);
JSBoundFunction* boundFormat() const { return m_boundFormat.get(); }
@@ -101,6 +109,14 @@
Minute m_minute { Minute::None };
Second m_second { Second::None };
TimeZoneName m_timeZoneName { TimeZoneName::None };
+
+#if JSC_ICU_HAS_UFIELDPOSITER
+ struct UFieldPositionIteratorDeleter {
+ void operator()(UFieldPositionIterator*) const;
+ };
+
+ static const char* partTypeString(UDateFormatField);
+#endif
};
} // namespace JSC