Modified: trunk/JSTests/stress/date-toLocaleString.js (260236 => 260237)
--- trunk/JSTests/stress/date-toLocaleString.js 2020-04-17 04:34:19 UTC (rev 260236)
+++ trunk/JSTests/stress/date-toLocaleString.js 2020-04-17 04:57:13 UTC (rev 260237)
@@ -46,8 +46,8 @@
shouldThrow(() => new Date().toLocaleString('i'), RangeError);
shouldBe(new Date(0).toLocaleString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }), '一九七〇/一/一 上午一二:〇〇:〇〇');
shouldBe(new Date(0).toLocaleString('zh-Hans-CN', { timeZone: 'UTC', numberingSystem: 'hanidec' }), '一九七〇/一/一 上午一二:〇〇:〇〇');
-shouldBe(new Date(0).toLocaleString('en-u-ca-chinese', { year: 'numeric' }), '1969(ji-you)');
-shouldBe(new Date(0).toLocaleString('en', { year: 'numeric', calendar: 'chinese' }), '1969(ji-you)');
+shouldBe(new Date(0).toLocaleString('en-u-ca-chinese', { timeZone: 'UTC', year: 'numeric' }), '1969(ji-you)');
+shouldBe(new Date(0).toLocaleString('en', { timeZone: 'UTC', year: 'numeric', calendar: 'chinese' }), '1969(ji-you)');
// Defaults to mdy, hms
shouldBe(new Date(0).toLocaleString('en', { timeZone: 'UTC' }), '1/1/1970, 12:00:00 AM');
@@ -85,8 +85,8 @@
shouldThrow(() => new Date().toLocaleDateString('i'), RangeError);
shouldBe(new Date(0).toLocaleDateString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }), '一九七〇/一/一');
shouldBe(new Date(0).toLocaleDateString('zh-Hans-CN', { timeZone: 'UTC', numberingSystem: 'hanidec' }), '一九七〇/一/一');
-shouldBe(new Date(0).toLocaleDateString('en-u-ca-chinese', { year: 'numeric' }), '1969(ji-you)');
-shouldBe(new Date(0).toLocaleDateString('en', { year: 'numeric', calendar: 'chinese' }), '1969(ji-you)');
+shouldBe(new Date(0).toLocaleDateString('en-u-ca-chinese', { timeZone: 'UTC', year: 'numeric' }), '1969(ji-you)');
+shouldBe(new Date(0).toLocaleDateString('en', { timeZone: 'UTC', year: 'numeric', calendar: 'chinese' }), '1969(ji-you)');
// Defaults to mdy
shouldBe(new Date(0).toLocaleDateString('en', { timeZone: 'UTC' }), '1/1/1970');
@@ -126,8 +126,8 @@
shouldThrow(() => new Date().toLocaleTimeString('i'), RangeError);
shouldBe(new Date(0).toLocaleTimeString('zh-Hans-CN-u-nu-hanidec', { timeZone: 'UTC' }), "上午一二:〇〇:〇〇");
shouldBe(new Date(0).toLocaleTimeString('zh-Hans-CN', { timeZone: 'UTC', numberingSystem: 'hanidec' }), "上午一二:〇〇:〇〇");
-shouldBe(new Date(0).toLocaleTimeString('en-u-ca-chinese', { year: 'numeric' }), '1969(ji-you), 4:00:00 PM');
-shouldBe(new Date(0).toLocaleTimeString('en', { year: 'numeric', calendar: 'chinese' }), '1969(ji-you), 4:00:00 PM');
+shouldBe(new Date(0).toLocaleTimeString('en-u-ca-chinese', { timeZone: 'UTC', year: 'numeric' }), '1969(ji-you), 12:00:00 AM');
+shouldBe(new Date(0).toLocaleTimeString('en', { timeZone: 'UTC', year: 'numeric', calendar: 'chinese' }), '1969(ji-you), 12:00:00 AM');
// Defaults to hms
shouldBe(new Date(0).toLocaleTimeString('en', { timeZone: 'UTC' }), "12:00:00 AM");
Modified: trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp (260236 => 260237)
--- trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-04-17 04:34:19 UTC (rev 260236)
+++ trunk/Source/_javascript_Core/runtime/IntlDateTimeFormat.cpp 2020-04-17 04:57:13 UTC (rev 260237)
@@ -104,12 +104,17 @@
m_boundFormat.set(vm, this, format);
}
+static ALWAYS_INLINE bool isUTCEquivalent(StringView timeZone)
+{
+ return timeZone == "Etc/UTC" || timeZone == "Etc/GMT";
+}
+
+// https://tc39.es/ecma402/#sec-defaulttimezone
static String defaultTimeZone()
{
- // 6.4.3 DefaultTimeZone () (ECMA-402 2.0)
- // 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.
+ UErrorCode status = U_ZERO_ERROR;
+ String canonical;
- UErrorCode status = U_ZERO_ERROR;
Vector<UChar, 32> buffer(32);
auto bufferLength = ucal_getDefaultTimeZone(buffer.data(), buffer.size(), &status);
if (status == U_BUFFER_OVERFLOW_ERROR) {
@@ -127,10 +132,13 @@
ucal_getCanonicalTimeZoneID(buffer.data(), bufferLength, canonicalBuffer.data(), canonicalLength, nullptr, &status);
}
if (U_SUCCESS(status))
- return String(canonicalBuffer.data(), canonicalLength);
+ canonical = String(canonicalBuffer.data(), canonicalLength);
}
- return "UTC"_s;
+ if (canonical.isNull() || isUTCEquivalent(canonical))
+ return "UTC"_s;
+
+ return canonical;
}
static String canonicalizeTimeZoneName(const String& timeZoneName)
@@ -176,8 +184,8 @@
uenum_close(timeZones);
// 3. If ianaTimeZone is "Etc/UTC" or "Etc/GMT", then return "UTC".
- if (canonical == "Etc/UTC" || canonical == "Etc/GMT")
- canonical = "UTC"_s;
+ if (isUTCEquivalent(canonical))
+ return "UTC"_s;
// 4. Return ianaTimeZone.
return canonical;
Modified: trunk/Source/_javascript_Core/runtime/IntlObject.cpp (260236 => 260237)
--- trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-04-17 04:34:19 UTC (rev 260236)
+++ trunk/Source/_javascript_Core/runtime/IntlObject.cpp 2020-04-17 04:57:13 UTC (rev 260237)
@@ -536,7 +536,7 @@
++numExtParts;
auto lowercase = extPart.convertToASCIILowercase();
- if (lowercase != "true"_s)
+ if (lowercase != "true")
extension.append('-', lowercase);
}
@@ -885,7 +885,7 @@
value = requestedValue;
supportedExtensionAddition = makeString('-', key, '-', value);
}
- } else if (keyLocaleData.contains(static_cast<String>("true"_s))) {
+ } else if (keyLocaleData.contains("true"_s)) {
value = "true"_s;
supportedExtensionAddition = makeString('-', key);
}