summaryrefslogtreecommitdiff
path: root/harness
diff options
context:
space:
mode:
authorAndré Bargull <andre.bargull@gmail.com>2015-07-08 19:13:55 +0200
committerAndré Bargull <andre.bargull@gmail.com>2015-07-08 19:13:55 +0200
commitd5075819e9ab1eabf737b2a9d0e15f7d796cdaf5 (patch)
treed636f491554d13450d3012e1be6c5e3a58758781 /harness
parent438b87b5b649314e7247c305b5870ed69916bb53 (diff)
downloadqtdeclarative-testsuites-d5075819e9ab1eabf737b2a9d0e15f7d796cdaf5.tar.gz
Check resolved time zone is valid
Diffstat (limited to 'harness')
-rw-r--r--harness/testIntl.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/harness/testIntl.js b/harness/testIntl.js
index b009a2e9e..465d4b3b8 100644
--- a/harness/testIntl.js
+++ b/harness/testIntl.js
@@ -1148,6 +1148,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.
* @param {Array} expected the expected array.