Skip to content
Snippets Groups Projects
Commit d5075819 authored by André Bargull's avatar André Bargull
Browse files

Check resolved time zone is valid

parent 438b87b5
No related branches found
No related tags found
No related merge requests found
......@@ -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.
......
......@@ -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"]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment