const canonicalDefaultTimeZone = new Intl.DateTimeFormat("en", {
timeZone: defaultTimeZone
}).resolvedOptions().timeZone;
function test(timeZone) { // The time zone of the initial global is correct.
assertEq(getRealmTimeZone(), canonicalDefaultTimeZone);
// Create a new global with a different time zone. var g = newGlobal({timeZone});
var initialTimeZone = timeZone ?? canonicalDefaultTimeZone;
// Ensure the new global has the expected time zone.
assertEq(g.getRealmTimeZone(), initialTimeZone);
// Create a Date object in the new global. var d = new g.Date();
// Call getTimeZoneOffset to fill the local date-time slots in |d|.
assertEq(
d.getTimezoneOffset() * nsPerMinute,
-d.toTemporalInstant().toZonedDateTimeISO(initialTimeZone).offsetNanoseconds + 0
);
// Change the time zone of the new global.
g.setRealmTimeZone("Asia/Tokyo");
// Ensure the new global has the expected time zone.
assertEq(g.getRealmTimeZone(), "Asia/Tokyo");
// The time zone of the initial global hasn't changed.
assertEq(getRealmTimeZone(), canonicalDefaultTimeZone);
// Ensure the local date-time slots in |d| don't return stale values.
assertEq(
d.getTimezoneOffset() * nsPerMinute,
-d.toTemporalInstant().toZonedDateTimeISO("Asia/Tokyo").offsetNanoseconds + 0
);
// Change the time zone of the new global to use the default time zone.
g.setRealmTimeZone(undefined);
// Ensure the new global has the expected time zone.
assertEq(g.getRealmTimeZone(), canonicalDefaultTimeZone);
// Ensure the local date-time slots in |d| don't return stale values.
assertEq(
d.getTimezoneOffset() * nsPerMinute,
-d.toTemporalInstant().toZonedDateTimeISO(defaultTimeZone).offsetNanoseconds + 0
);
}
test();
test("Europe/London");
if (typeof reportCompare === "function")
reportCompare(true, true);
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.