From d5075819e9ab1eabf737b2a9d0e15f7d796cdaf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Bargull?= <andre.bargull@gmail.com>
Date: Wed, 8 Jul 2015 19:13:55 +0200
Subject: [PATCH] Check resolved time zone is valid

---
 harness/testIntl.js    | 37 +++++++++++++++++++++++++++++++++++++
 test/intl402/12.3.3.js |  2 +-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/harness/testIntl.js b/harness/testIntl.js
index b009a2e9ed..465d4b3b81 100644
--- a/harness/testIntl.js
+++ b/harness/testIntl.js
@@ -1147,6 +1147,43 @@ function testValidDateTimeComponentValue(component, value) {
 }
 
 
+/**
+ * @description Tests whether timeZone is a String value representing a
+ * structurally valid and canonicalized time zone name, as defined in
+ * sections 6.4.1 and 6.4.2 of the ECMAScript Internationalization API
+ * Specification.
+ * @param {String} timeZone the string to be tested.
+ * @result {Boolean} whether the test succeeded.
+ */
+
+function isCanonicalizedStructurallyValidTimeZoneName(timeZone) {
+    /**
+     * Regular expression defining IANA Time Zone names.
+     *
+     * Spec: IANA Time Zone Database, Theory file
+     */
+    var fileNameComponent = "(?:[A-Za-z_]|\\.(?!\\.?(?:/|$)))[A-Za-z.\\-_]{0,13}";
+    var fileName = fileNameComponent + "(?:/" + fileNameComponent + ")*";
+    var etcName = "(?:Etc/)?GMT[+-]\\d{1,2}";
+    var systemVName = "SystemV/[A-Z]{3}\\d{1,2}(?:[A-Z]{3})?";
+    var legacyName = etcName + "|" + systemVName + "|CST6CDT|EST5EDT|MST7MDT|PST8PDT|NZ|Canada/East-Saskatchewan";
+    var zoneNamePattern = new RegExp("^(?:" + fileName + "|" + legacyName + ")$");
+
+    if (typeof timeZone !== "string") {
+        return false;
+    }
+    // 6.4.2 CanonicalizeTimeZoneName (timeZone), step 3
+    if (timeZone === "UTC") {
+        return true;
+    }
+    // 6.4.2 CanonicalizeTimeZoneName (timeZone), step 3
+    if (timeZone === "Etc/UTC" || timeZone === "Etc/GMT") {
+        return false;
+    }
+    return zoneNamePattern.test(timeZone);
+}
+
+
 /**
  * Verifies that the actual array matches the expected one in length, elements,
  * and element order.
diff --git a/test/intl402/12.3.3.js b/test/intl402/12.3.3.js
index 55e31ad869..46a6b38c0e 100644
--- a/test/intl402/12.3.3.js
+++ b/test/intl402/12.3.3.js
@@ -40,7 +40,7 @@ var calendars = [
 mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
 mustHaveProperty(actual, "calendar", calendars);
 mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem);
-mustHaveProperty(actual, "timeZone", [undefined]);
+mustHaveProperty(actual, "timeZone", isCanonicalizedStructurallyValidTimeZoneName);
 mustNotHaveProperty(actual, "weekday");
 mustNotHaveProperty(actual, "era");
 mustHaveProperty(actual, "year", ["2-digit", "numeric"]);
-- 
GitLab