mirror of https://github.com/tc39/test262.git
Check resolved time zone is valid
This commit is contained in:
parent
438b87b5b6
commit
d5075819e9
|
@ -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,
|
* Verifies that the actual array matches the expected one in length, elements,
|
||||||
* and element order.
|
* and element order.
|
||||||
|
|
|
@ -40,7 +40,7 @@ var calendars = [
|
||||||
mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
|
mustHaveProperty(actual, "locale", isCanonicalizedStructurallyValidLanguageTag);
|
||||||
mustHaveProperty(actual, "calendar", calendars);
|
mustHaveProperty(actual, "calendar", calendars);
|
||||||
mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem);
|
mustHaveProperty(actual, "numberingSystem", isValidNumberingSystem);
|
||||||
mustHaveProperty(actual, "timeZone", [undefined]);
|
mustHaveProperty(actual, "timeZone", isCanonicalizedStructurallyValidTimeZoneName);
|
||||||
mustNotHaveProperty(actual, "weekday");
|
mustNotHaveProperty(actual, "weekday");
|
||||||
mustNotHaveProperty(actual, "era");
|
mustNotHaveProperty(actual, "era");
|
||||||
mustHaveProperty(actual, "year", ["2-digit", "numeric"]);
|
mustHaveProperty(actual, "year", ["2-digit", "numeric"]);
|
||||||
|
|
Loading…
Reference in New Issue