Skip to content

Commit 3683604

Browse files
committed
Fix Intl default timezone is incorrect
1 parent 15f648b commit 3683604

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

patches/jsc_intl_timezone.patch

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
diff -aur target-org/webkit/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp target/webkit/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp
2+
--- target-org/webkit/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp 2019-01-28 09:56:29.000000000 +0800
3+
+++ target/webkit/Source/JavaScriptCore/runtime/IntlDateTimeFormat.cpp 2019-09-06 02:00:12.000000000 +0800
4+
@@ -40,6 +40,8 @@
5+
#include <unicode/udatpg.h>
6+
#include <unicode/uenum.h>
7+
#include <wtf/text/StringBuilder.h>
8+
+#include <sys/system_properties.h>
9+
+#include <wtf/unicode/UTF8Conversion.h>
10+
11+
#if JSC_ICU_HAS_UFIELDPOSITER
12+
#include <unicode/ufieldpositer.h>
13+
@@ -121,14 +123,34 @@
14+
// 6.4.3 DefaultTimeZone () (ECMA-402 2.0)
15+
// The DefaultTimeZone abstract operation returns a String value representing the valid (6.4.1) and canonicalized (6.4.2) time zone name for the host environment’s current time zone.
16+
17+
- UErrorCode status = U_ZERO_ERROR;
18+
+ UErrorCode status = U_UNDEFINED_VARIABLE;
19+
Vector<UChar, 32> buffer(32);
20+
- auto bufferLength = ucal_getDefaultTimeZone(buffer.data(), buffer.size(), &status);
21+
- if (status == U_BUFFER_OVERFLOW_ERROR) {
22+
- status = U_ZERO_ERROR;
23+
- buffer.grow(bufferLength);
24+
- ucal_getDefaultTimeZone(buffer.data(), bufferLength, &status);
25+
+ size_t bufferLength = 32;
26+
+
27+
+ // [0] Try to get timezone from Android system property
28+
+ char systemPropBuffer[2 * (PROP_VALUE_MAX + 1)] = {0};
29+
+ if (__system_property_get("persist.sys.timezone", systemPropBuffer) != 0) {
30+
+ size_t systemPropLength = strlen(systemPropBuffer);
31+
+ if (systemPropLength > buffer.capacity()) {
32+
+ buffer.grow(strlen(systemPropBuffer));
33+
+ }
34+
+ UChar* bufferStart = buffer.data();
35+
+ if (WTF::Unicode::convertUTF8ToUTF16(reinterpret_cast<const char**>(&systemPropBuffer), systemPropBuffer + systemPropLength, &bufferStart, bufferStart + buffer.capacity()) == WTF::Unicode::conversionOK) {
36+
+ status = U_ZERO_ERROR;
37+
+ }
38+
}
39+
+
40+
+ // [1] Fallback to get timezone from ICU default
41+
+ if (U_FAILURE(status)) {
42+
+ bufferLength = ucal_getDefaultTimeZone(buffer.data(), buffer.size(), &status);
43+
+ if (status == U_BUFFER_OVERFLOW_ERROR) {
44+
+ status = U_ZERO_ERROR;
45+
+ buffer.grow(bufferLength);
46+
+ ucal_getDefaultTimeZone(buffer.data(), bufferLength, &status);
47+
+ }
48+
+ }
49+
+
50+
+ // [2] Get canonical timezone ID
51+
if (U_SUCCESS(status)) {
52+
status = U_ZERO_ERROR;
53+
Vector<UChar, 32> canonicalBuffer(32);

scripts/patch.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ JSC_PATCHSET=(
5555

5656
# Workaround JIT crash on arm64, especially for Saumsung S7 Edge
5757
"jsc_fix_arm64_jit_crash.patch"
58+
59+
# Intl default timezone with Android integration
60+
"jsc_intl_timezone.patch"
5861
)
5962

6063
if [[ "$I18N" = false ]]

0 commit comments

Comments
 (0)