/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Step 34. (Reordered) var formatOptions = lazyDateTimeFormatData.formatOptions;
// Steps 23-29. // // Copy the hourCycle setting, if present, to the format options. But // only do this if no hour12 option is present, because the latter takes // precedence over hourCycle. if (r.hc !== null && formatOptions.hour12 === undefined) {
formatOptions.hourCycle = r.hc;
}
// The caller is responsible for associating |internalProps| with the right // object using |setInternalProperties|. return internalProps;
}
/** * Returns an object containing the DateTimeFormat internal properties of |obj|.
*/ function getDateTimeFormatInternals(obj) { assert(IsObject(obj), "getDateTimeFormatInternals called with non-object"); assert(
intl_GuardToDateTimeFormat(obj) !== null, "getDateTimeFormatInternals called with non-DateTimeFormat"
);
var internals = getIntlObjectInternals(obj); assert(
internals.type === "DateTimeFormat", "bad type escaped getIntlObjectInternals"
);
// If internal properties have already been computed, use them. var internalProps = maybeInternalProperties(internals); if (internalProps) { return internalProps;
}
// Otherwise it's time to fully create them.
internalProps = resolveDateTimeFormatInternals(internals.lazyData);
setInternalProperties(internals, internalProps); return internalProps;
}
/** * 12.1.10 UnwrapDateTimeFormat( dtf )
*/ function UnwrapDateTimeFormat(dtf) { // Steps 2 and 4 (error handling moved to caller). if (
IsObject(dtf) &&
intl_GuardToDateTimeFormat(dtf) === null &&
!intl_IsWrappedDateTimeFormat(dtf) &&
callFunction(
std_Object_isPrototypeOf,
GetBuiltinPrototype("DateTimeFormat"),
dtf
)
) {
dtf = dtf[intlFallbackSymbol()];
} return dtf;
}
/** * 6.4.2 CanonicalizeTimeZoneName ( timeZone ) * * Canonicalizes the given IANA time zone name. * * ES2017 Intl draft rev 4a23f407336d382ed5e3471200c690c9b020b5f3
*/ function CanonicalizeTimeZoneName(timeZone) { assert(typeof timeZone === "string", "CanonicalizeTimeZoneName");
// Step 1. (Not applicable, the input is already a valid IANA time zone.) assert(timeZone !== "Etc/Unknown", "Invalid time zone"); assert(
timeZone === intl_IsValidTimeZoneName(timeZone), "Time zone name not normalized"
);
// Step 2. var ianaTimeZone = intl_canonicalizeTimeZone(timeZone); assert(ianaTimeZone !== "Etc/Unknown", "Invalid canonical time zone"); assert(
ianaTimeZone === intl_IsValidTimeZoneName(ianaTimeZone), "Unsupported canonical time zone"
);
// Step 3. (Not applicable.) assert(ianaTimeZone !== "Etc/UTC", "Invalid link to UTC"); assert(ianaTimeZone !== "Etc/GMT", "Invalid link to UTC"); assert(ianaTimeZone !== "GMT", "Invalid link to UTC");
// Step 4. return ianaTimeZone;
}
var timeZoneCache = {
icuDefaultTimeZone: undefined,
defaultTimeZone: undefined,
};
/** * 6.4.3 DefaultTimeZone () * * Returns the IANA time zone name for the host environment's current time zone. * * ES2017 Intl draft rev 4a23f407336d382ed5e3471200c690c9b020b5f3
*/ function DefaultTimeZone() { if (intl_isDefaultTimeZone(timeZoneCache.icuDefaultTimeZone)) { return timeZoneCache.defaultTimeZone;
}
// Verify that the current ICU time zone is a valid ECMA-402 time zone. var icuDefaultTimeZone = intl_defaultTimeZone(); var timeZone = intl_IsValidTimeZoneName(icuDefaultTimeZone); if (timeZone === null) { // Before defaulting to "UTC", try to represent the default time zone // using the Etc/GMT + offset format. This format only accepts full // hour offsets. var msPerHour = 60 * 60 * 1000; var offset = intl_defaultTimeZoneOffset(); assert(
offset === (offset | 0), "milliseconds offset shouldn't be able to exceed int32_t range"
); var offsetHours = offset / msPerHour; var offsetHoursFraction = offset % msPerHour; if (offsetHoursFraction === 0) { // Etc/GMT + offset uses POSIX-style signs, i.e. a positive offset // means a location west of GMT.
timeZone = "Etc/GMT" + (offsetHours < 0 ? "+" : "-") + std_Math_abs(offsetHours);
// Check if the fallback is valid.
timeZone = intl_IsValidTimeZoneName(timeZone);
}
// Fallback to "UTC" if everything else fails. if (timeZone === null) {
timeZone = "UTC";
}
}
// Canonicalize the ICU time zone, e.g. change Etc/UTC to UTC. var defaultTimeZone = CanonicalizeTimeZoneName(timeZone);
// Return if there are too few or too many characters for an offset string. if (offsetString.length < 3 || offsetString.length > 6) { returnnull;
}
// The first character must match |ASCIISign|. var sign = offsetString[0]; if (sign !== "+" && sign !== "-") { returnnull;
}
// Read the next two characters for the |Hour| grammar production. var hourTens = offsetString[1]; var hourOnes = offsetString[2];
// Read the remaining characters for the optional |MinuteSecond| grammar production. var minutesTens = "0"; var minutesOnes = "0"; if (offsetString.length > 3) { // |TimeSeparator| is optional. var separatorLength = offsetString[3] === ":" ? 1 : 0;
// Return if there are too many characters for an offset string. if (offsetString.length !== (5 + separatorLength)) { returnnull;
}
/* eslint-disable complexity */ /** * 11.1.2 CreateDateTimeFormat ( newTarget, locales, options, required, defaults [ , toLocaleStringTimeZone ] ) * * Initializes an object as a DateTimeFormat. * * This method is complicated a moderate bit by its implementing initialization * as a *lazy* concept. Everything that must happen now, does -- but we defer * all the work we can until the object is actually used as a DateTimeFormat. * This later work occurs in |resolveDateTimeFormatInternals|; steps not noted * here occur there.
*/ function InitializeDateTimeFormat(
dateTimeFormat,
thisValue,
locales,
options,
required,
defaults,
toLocaleStringTimeZone,
mozExtensions
) { assert(
IsObject(dateTimeFormat), "InitializeDateTimeFormat called with non-Object"
); assert(
intl_GuardToDateTimeFormat(dateTimeFormat) !== null, "InitializeDateTimeFormat called with non-DateTimeFormat"
); assert(
required === "date" || required === "time" || required === "any",
`InitializeDateTimeFormat called with invalid required value: ${required}`
); assert(
defaults === "date" || defaults === "time" || defaults === "all",
`InitializeDateTimeFormat called with invalid defaults value: ${defaults}`
); assert(
toLocaleStringTimeZone === undefined || typeof toLocaleStringTimeZone === "string",
`InitializeDateTimeFormat called with invalid toLocaleStringTimeZone value: ${toLocaleStringTimeZone}`
);
// Lazy DateTimeFormat data has the following structure: // // { // requestedLocales: List of locales, // // localeOpt: // *first* opt computed in InitializeDateTimeFormat // { // localeMatcher: "lookup" / "best fit", // // ca: string matching a Unicode extension type, // optional // // nu: string matching a Unicode extension type, // optional // // hc: "h11" / "h12" / "h23" / "h24", // optional // } // // timeZone: IANA time zone name or a normalized time zone offset string, // // formatOptions: // *second* opt computed in InitializeDateTimeFormat // { // // all the properties/values listed in Table 3 // // (weekday, era, year, month, day, &c.) // // hour12: true / false, // optional // } // // formatMatcher: "basic" / "best fit", // // required: "date" / "time" / "any", // optional // // defaults: "date" / "time" / "all", // optional // } // // Note that lazy data is only installed as a final step of initialization, // so every DateTimeFormat lazy data object has *all* these properties, // never a subset of them. var lazyDateTimeFormatData = std_Object_create(null);
// Step 1. (Performed in caller)
// Step 2. var requestedLocales = CanonicalizeLocaleList(locales);
lazyDateTimeFormatData.requestedLocales = requestedLocales;
// Step 34. var formatOptions = new_Record();
lazyDateTimeFormatData.formatOptions = formatOptions;
if (mozExtensions) { var pattern = GetOption(options, "pattern", "string", undefined, undefined);
lazyDateTimeFormatData.patternOption = pattern;
}
// Step 35. // // Pass hr12 on to ICU. The hour cycle option is passed through |localeOpt|. if (hour12 !== undefined) {
formatOptions.hour12 = hour12;
}
// Step 36. (Explicit format component computed in step 43.)
// Step 38. // // For some reason (ICU not exposing enough interface?) we drop the // requested format matcher on the floor after this. In any case, even if // doing so is justified, we have to do this work here in case it triggers // getters or similar. (bug 852837) var formatMatcher = GetOption(
options, "formatMatcher", "string",
["basic", "best fit"], "best fit"
); void formatMatcher;
// Steps 45-50. (see resolveDateTimeFormatInternals).
// We've done everything that must be done now: mark the lazy data as fully // computed and install it.
initializeIntlObject(
dateTimeFormat, "DateTimeFormat",
lazyDateTimeFormatData
);
/** * Returns the subset of the given locale list for which this locale list has a * matching (possibly fallback) locale. Locales appear in the same order in the * returned list as in the input list. * * Spec: ECMAScript Internationalization API Specification, 12.3.2.
*/ function Intl_DateTimeFormat_supportedLocalesOf(locales /*, options*/) { var options = ArgumentsLength() > 1 ? GetArgument(1) : undefined;
// Step 1. var availableLocales = "DateTimeFormat";
// Step 2. var requestedLocales = CanonicalizeLocaleList(locales);
/** * Create function to be cached and returned by Intl.DateTimeFormat.prototype.format. * * Spec: ECMAScript Internationalization API Specification, 12.1.5.
*/ function createDateTimeFormatFormat(dtf) { // This function is not inlined in $Intl_DateTimeFormat_format_get to avoid // creating a call-object on each call to $Intl_DateTimeFormat_format_get. returnfunction(date) { // Step 1 (implicit).
// Step 2. assert(IsObject(dtf), "dateTimeFormatFormatToBind called with non-Object"); assert(
intl_GuardToDateTimeFormat(dtf) !== null, "dateTimeFormatFormatToBind called with non-DateTimeFormat"
);
/** * Returns a function bound to this DateTimeFormat that returns a String value * representing the result of calling ToNumber(date) according to the * effective locale and the formatting options of this DateTimeFormat. * * Spec: ECMAScript Internationalization API Specification, 12.4.3.
*/ // Uncloned functions with `$` prefix are allocated as extended function // to store the original name in `SetCanonicalName`. function $Intl_DateTimeFormat_format_get() { // Steps 1-3. var thisArg = UnwrapDateTimeFormat(this); var dtf = thisArg; if (!IsObject(dtf) || (dtf = intl_GuardToDateTimeFormat(dtf)) === null) { return callFunction(
intl_CallDateTimeFormatMethodIfWrapped,
thisArg, "$Intl_DateTimeFormat_format_get"
);
}
/** * Returns the resolved options for a DateTimeFormat object. * * Spec: ECMAScript Internationalization API Specification, 12.4.5.
*/ function Intl_DateTimeFormat_resolvedOptions() { // Steps 1-3. var thisArg = UnwrapDateTimeFormat(this); var dtf = thisArg; if (!IsObject(dtf) || (dtf = intl_GuardToDateTimeFormat(dtf)) === null) { return callFunction(
intl_CallDateTimeFormatMethodIfWrapped,
thisArg, "Intl_DateTimeFormat_resolvedOptions"
);
}
// Ensure the internals are resolved. var internals = getDateTimeFormatInternals(dtf);
// Steps 4-5. var result = {
locale: internals.locale,
calendar: internals.calendar,
numberingSystem: internals.numberingSystem,
timeZone: internals.timeZone,
};
if (internals.pattern !== undefined) { // The raw pattern option is only internal to Mozilla, and not part of the // ECMA-402 API.
DefineDataProperty(result, "pattern", internals.pattern);
}
var hasDateStyle = internals.dateStyle !== undefined; var hasTimeStyle = internals.timeStyle !== undefined;
if (hasDateStyle || hasTimeStyle) { if (hasTimeStyle) { // timeStyle (unlike dateStyle) requires resolving the pattern to // ensure "hourCycle" and "hour12" properties are added to |result|.
intl_resolveDateTimeFormatComponents(
dtf,
result, /* includeDateTimeFields = */ false
);
} if (hasDateStyle) {
DefineDataProperty(result, "dateStyle", internals.dateStyle);
} if (hasTimeStyle) {
DefineDataProperty(result, "timeStyle", internals.timeStyle);
}
} else { // Components bag or a (Mozilla-only) raw pattern.
intl_resolveDateTimeFormatComponents(
dtf,
result, /* includeDateTimeFields = */ true
);
}
// Step 6. return result;
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.