Implement Date.toLocaleString() using ICU
authorefidler@rim.com <efidler@rim.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 00:11:34 +0000 (00:11 +0000)
committerefidler@rim.com <efidler@rim.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 00:11:34 +0000 (00:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76714

Reviewed by Darin Adler.

* runtime/DatePrototype.cpp:
(JSC::formatLocaleDate):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105939 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/DatePrototype.cpp

index 217cfda..f30cc17 100644 (file)
@@ -1,3 +1,13 @@
+2012-01-25  Eli Fidler  <efidler@rim.com>
+
+        Implement Date.toLocaleString() using ICU
+        https://bugs.webkit.org/show_bug.cgi?id=76714
+
+        Reviewed by Darin Adler.
+
+        * runtime/DatePrototype.cpp:
+        (JSC::formatLocaleDate):
+
 2012-01-25  Hajime Morita  <morrita@google.com>
 
         ENABLE_SHADOW_DOM should be available via build-webkit --shadow-dom
index 93261f6..67d7351 100644 (file)
 #include <CoreFoundation/CoreFoundation.h>
 #endif
 
+#if USE(ICU_UNICODE)
+#include <unicode/udat.h>
+#endif
+
 #if OS(WINCE) && !PLATFORM(QT)
 extern "C" size_t strftime(char * const s, const size_t maxsize, const char * const format, const struct tm * const t); //provided by libce
 #endif
@@ -195,7 +199,29 @@ static JSCell* formatLocaleDate(ExecState* exec, DateInstance*, double timeInMil
     return jsNontrivialString(exec, UString(buffer, length));
 }
 
-#else // !PLATFORM(MAC) && !PLATFORM(IOS)
+#elif USE(ICU_UNICODE) && !UCONFIG_NO_FORMATTING
+
+static JSCell* formatLocaleDate(ExecState* exec, DateInstance* dateObject, double timeInMilliseconds, LocaleDateTimeFormat format)
+{
+    UDateFormatStyle timeStyle = (format != LocaleDate ? UDAT_LONG : UDAT_NONE);
+    UDateFormatStyle dateStyle = (format != LocaleTime ? UDAT_LONG : UDAT_NONE);
+
+    UErrorCode status = U_ZERO_ERROR;
+    UDateFormat* df = udat_open(timeStyle, dateStyle, 0, 0, -1, 0, 0, &status);
+    if (!df)
+        return jsEmptyString(exec);
+
+    UChar buffer[128];
+    int32_t length;
+    length = udat_format(df, timeInMilliseconds, buffer, 128, 0, &status);
+    udat_close(df);
+    if (status != U_ZERO_ERROR)
+        return jsEmptyString(exec);
+
+    return jsNontrivialString(exec, UString(buffer, length));
+}
+
+#else
 
 static JSCell* formatLocaleDate(ExecState* exec, const GregorianDateTime& gdt, LocaleDateTimeFormat format)
 {