From eeea58fa5fbc26cf15424b3c14426f0353c9fe52 Mon Sep 17 00:00:00 2001
From: Ujjwal Sharma
Date: Wed, 3 Mar 2021 13:52:51 +0530
Subject: [PATCH 1/4] spec,polyfill: no observable "from" lookups
This commit removes observable "from" lookups for `Calendar` and
`TimeZone` from the spec and the polyfill, in response to the delegate
reviews.
Refs: https://github.com/tc39/proposal-temporal/issues/1293
---
polyfill/lib/ecmascript.mjs | 18 ++++++++++--------
spec/calendar.html | 26 +++++++++-----------------
spec/timezone.html | 23 +++++++++--------------
3 files changed, 28 insertions(+), 39 deletions(-)
diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs
index e7148dc298..1c9a76f351 100644
--- a/polyfill/lib/ecmascript.mjs
+++ b/polyfill/lib/ecmascript.mjs
@@ -1515,10 +1515,11 @@ export const ES = ObjectAssign({}, ES2020, {
},
CalendarFrom: (calendarLike) => {
const TemporalCalendar = GetIntrinsic('%Temporal.Calendar%');
- let from = TemporalCalendar.from;
- if (from === undefined) {
- from = GetIntrinsic('%Temporal.Calendar.from%');
- }
+ // let from = TemporalCalendar.from;
+ // if (from === undefined) {
+ // from = GetIntrinsic('%Temporal.Calendar.from%');
+ // }
+ const from = GetIntrinsic('%Temporal.Calendar.from%');
const calendar = ES.Call(from, TemporalCalendar, [calendarLike]);
if (ES.Type(calendar) !== 'Object') {
throw new TypeError('Temporal.Calendar.from should return an object');
@@ -1676,10 +1677,11 @@ export const ES = ObjectAssign({}, ES2020, {
},
TimeZoneFrom: (temporalTimeZoneLike) => {
const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%');
- let from = TemporalTimeZone.from;
- if (from === undefined) {
- from = GetIntrinsic('%Temporal.TimeZone.from%');
- }
+ // let from = TemporalTimeZone.from;
+ // if (from === undefined) {
+ // from = GetIntrinsic('%Temporal.TimeZone.from%');
+ // }
+ const from = GetIntrinsic('%Temporal.TimeZone.from%');
return ES.Call(from, TemporalTimeZone, [temporalTimeZoneLike]);
},
ToTemporalTimeZone: (temporalTimeZoneLike) => {
diff --git a/spec/calendar.html b/spec/calendar.html
index bb4ab938d4..0e3e96dc75 100644
--- a/spec/calendar.html
+++ b/spec/calendar.html
@@ -260,12 +260,14 @@ GetOptionalTemporalCalendar ( _item_ )
CalendarFrom ( _identifier_ )
- 1. Let _from_ be ? GetMethod(%Temporal.Calendar%, *"from"*).
- 1. If _from_ is *undefined*, set _from_ to %Temporal.Calendar.from%.
- 1. Let _calendar_ be ? Call(_from_, %Temporal.Calendar%, « _identifier_ »).
- 1. If Type(_calendar_) is not Object, then
- 1. Throw a *TypeError* exception.
- 1. Return _calendar_.
+ 1. If Type(_item_) is Object, then
+ 1. If ? HasProperty(_item_, *"calendar"*) is *false*, return _item_.
+ 1. Set _item_ to ? Get(_item_, *"calendar"*).
+ 1. If Type(_item_) is Object and ? HasProperty(_item_, *"calendar"*) is *false*, return _item_.
+ 1. Let _string_ be ? ToString(_item_).
+ 1. If ! IsBuiltinCalendar(_string_) is *false*, then
+ 1. Let _string_ be ? ParseTemporalCalendarString(_string_).
+ 1. Return ? GetBuiltinCalendar(_string_).
@@ -661,18 +663,8 @@ Temporal.Calendar.from ( _item_ )
The following steps are taken:
- 1. If Type(_item_) is Object, then
- 1. If ? HasProperty(_item_, *"calendar"*) is *false*, return _item_.
- 1. Set _item_ to ? Get(_item_, *"calendar"*).
- 1. If Type(_item_) is Object and ? HasProperty(_item_, *"calendar"*) is *false*, return _item_.
- 1. Let _string_ be ? ToString(_item_).
- 1. If ! IsBuiltinCalendar(_string_) is *false*, then
- 1. Let _string_ be ? ParseTemporalCalendarString(_string_).
- 1. Return ? GetBuiltinCalendar(_string_).
+ 1. Return ? CalendarFrom(_item_).
-
- This function is the %Temporal.Calendar.from% intrinsic object.
-
diff --git a/spec/timezone.html b/spec/timezone.html
index 28ec973a3b..9a27a0ff35 100644
--- a/spec/timezone.html
+++ b/spec/timezone.html
@@ -163,18 +163,8 @@ Temporal.TimeZone.from ( _item_ )
The following steps are taken:
- 1. If Type(_item_) is Object, then
- 1. If ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
- 1. Set _item_ to ? Get(_item_, *"timeZone"*).
- 1. If Type(_item_) is Object and ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
- 1. Let _string_ be ? ToString(_item_).
- 1. Let _result_ be ? ParseTemporalTimeZone(_string_).
- 1. Let _constructor_ be the *this* value.
- 1. Return ? CreateTemporalTimeZoneFromStatic(_constructor_, _result_).
+ 1. Return ? TimeZoneFrom(_item_).
-
- This function is the %Temporal.TimeZone.from intrinsic object.
-
@@ -578,9 +568,14 @@ ToTemporalTimeZone ( _temporalTimeZoneLike_ )
TimeZoneFrom ( _identifier_ )
- 1. Let _from_ be ? GetMethod(%Temporal.TimeZone%, *"from"*).
- 1. If _from_ is *undefined*, set _from_ to %Temporal.TimeZone.from%.
- 1. Return ? Call(_from_, %Temporal.TimeZone%, « _identifier_ »).
+ 1. If Type(_item_) is Object, then
+ 1. If ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
+ 1. Set _item_ to ? Get(_item_, *"timeZone"*).
+ 1. If Type(_item_) is Object and ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
+ 1. Let _string_ be ? ToString(_item_).
+ 1. Let _result_ be ? ParseTemporalTimeZone(_string_).
+ 1. Let _constructor_ be the *this* value.
+ 1. Return ? CreateTemporalTimeZoneFromStatic(_constructor_, _result_).
From aee4e6a271de611fa1b875ee7f99ebf2120fd054 Mon Sep 17 00:00:00 2001
From: Ujjwal Sharma
Date: Wed, 3 Mar 2021 17:21:17 +0530
Subject: [PATCH 2/4] doc: remove from monkey-patching
`from` methods can no longer be monkey-patched, so this commit removes
that behavior from the cookbook documentation.
---
docs/cookbook/stockExchangeTimeZone.mjs | 29 ++++++++-----------------
1 file changed, 9 insertions(+), 20 deletions(-)
diff --git a/docs/cookbook/stockExchangeTimeZone.mjs b/docs/cookbook/stockExchangeTimeZone.mjs
index 11ebd854e4..98e321f74f 100644
--- a/docs/cookbook/stockExchangeTimeZone.mjs
+++ b/docs/cookbook/stockExchangeTimeZone.mjs
@@ -131,17 +131,6 @@ class NYSETimeZone extends Temporal.TimeZone {
const tzNYSE = Object.freeze(new NYSETimeZone());
-// Monkeypatch Temporal.TimeZone.from to handle our custom time zone
-let oldTzFrom;
-const replacement = (item) => {
- if (item === 'NYSE') return tzNYSE;
- return oldTzFrom.call(Temporal.TimeZone, item);
-};
-if (Temporal.TimeZone.from !== replacement) {
- oldTzFrom = Temporal.TimeZone.from;
- Temporal.TimeZone.from = replacement;
-}
-
let zdt;
let isOpen;
let date;
@@ -165,16 +154,16 @@ assert.equal(date.toString(), '2020-11-12');
// 2. Is the stock market open on a particular date?
date = Temporal.PlainDate.from('2020-11-12');
-isOpen = date.toZonedDateTime('NYSE').toPlainDate().equals(date);
+isOpen = date.toZonedDateTime(tzNYSE).toPlainDate().equals(date);
assert.equal(isOpen, true);
date = Temporal.PlainDate.from('2020-11-14');
-isOpen = date.toZonedDateTime('NYSE').toPlainDate().equals(date);
+isOpen = date.toZonedDateTime(tzNYSE).toPlainDate().equals(date);
assert.equal(isOpen, false);
// 3. For a particular date, when is the next market day?
const getNextMarketDay = (date) => {
date = Temporal.PlainDate.from(date);
- const zdt = date.toZonedDateTime('NYSE');
+ const zdt = date.toZonedDateTime(tzNYSE);
if (zdt.toPlainDate().equals(date)) {
// It's a market day, so find the next one
return zdt.add({ days: 1 }).toPlainDate();
@@ -195,22 +184,22 @@ assert.equal(newDate.equals('2020-11-16'), true);
// If it's closed, then when will it open next?
// Return a result in the local time zone, not NYC's time zone.
zdt = Temporal.ZonedDateTime.from('2020-11-12T18:50-08:00[America/Los_Angeles]');
-inNYSE = zdt.withTimeZone('NYSE');
-isOpen = inNYSE.toPlainDateTime().toZonedDateTime('NYSE').equals(inNYSE);
+inNYSE = zdt.withTimeZone(tzNYSE);
+isOpen = inNYSE.toPlainDateTime().toZonedDateTime(tzNYSE).equals(inNYSE);
assert.equal(isOpen, false);
nextOpen = inNYSE.timeZone.getNextTransition(zdt.toInstant()).toZonedDateTimeISO(zdt.timeZone);
assert.equal(nextOpen.toString(), '2020-11-13T06:30:00-08:00[America/Los_Angeles]');
zdt = Temporal.ZonedDateTime.from('2020-11-12T12:50-08:00[America/Los_Angeles]');
-inNYSE = zdt.withTimeZone('NYSE');
-isOpen = inNYSE.toPlainDateTime().toZonedDateTime('NYSE').equals(inNYSE);
+inNYSE = zdt.withTimeZone(tzNYSE);
+isOpen = inNYSE.toPlainDateTime().toZonedDateTime(tzNYSE).equals(inNYSE);
assert.equal(isOpen, true);
todayClose = inNYSE.timeZone.getNextTransition(zdt.toInstant()).toZonedDateTimeISO(zdt.timeZone);
assert.equal(todayClose.toString(), '2020-11-12T13:00:00-08:00[America/Los_Angeles]');
// 5. For any particular market date, what were the opening and closing clock times in NYC?
date = Temporal.PlainDate.from('2020-11-09');
-openInstant = date.toZonedDateTime('NYSE').toInstant();
-closeInstant = date.toZonedDateTime('NYSE').timeZone.getNextTransition(openInstant);
+openInstant = date.toZonedDateTime(tzNYSE).toInstant();
+closeInstant = date.toZonedDateTime(tzNYSE).timeZone.getNextTransition(openInstant);
assert.equal(openInstant.toZonedDateTimeISO('America/New_York').toPlainTime().toString(), '09:30:00');
assert.equal(closeInstant.toZonedDateTimeISO('America/New_York').toPlainTime().toString(), '16:00:00');
From 7cf1acb254ad48d3c02b557e224537d3935a063e Mon Sep 17 00:00:00 2001
From: Ujjwal Sharma
Date: Wed, 3 Mar 2021 18:44:41 +0530
Subject: [PATCH 3/4] polyfill: update tests regarding from lookups
The polyfill no longer does observable `from` lookups for `Calendar` and
`TimeZone`. Therefore, this commit removes tests that check that
behavior and modifies those that merely rely on it.
---
.../toZonedDateTime/calendar-convert.js | 36 ----
.../calendar-from-invalid-result.js | 31 ----
.../calendar-from-undefined.js | 11 +-
.../prototype/toZonedDateTime/calendar.js | 64 -------
.../constructor/calendar-convert.js | 37 ----
.../calendar-from-invalid-result.js | 30 ----
.../constructor/calendar-from-undefined.js | 20 ---
.../constructor/constructor/calendar.js | 32 ----
.../constructor/order-of-operations.js | 27 +--
.../getPlainDateTimeFor/calendar-convert.js | 37 ----
.../calendar-from-invalid-result.js | 31 ----
.../calendar-from-undefined.js | 11 +-
.../prototype/getPlainDateTimeFor/calendar.js | 41 -----
.../constructor/timezone-undefined.js | 37 ----
.../test/now/plainDate/calendar-convert.js | 34 ----
.../plainDate/calendar-from-invalid-result.js | 30 ----
.../now/plainDate/calendar-from-undefined.js | 8 -
polyfill/test/now/plainDate/calendar.js | 28 +--
polyfill/test/now/plainDate/timezone.js | 22 +--
.../test/now/plainDate/toDate-override.js | 15 +-
.../now/plainDateTime/calendar-convert.js | 34 ----
.../calendar-from-invalid-result.js | 30 ----
.../plainDateTime/calendar-from-undefined.js | 8 -
polyfill/test/now/plainDateTime/calendar.js | 28 +--
polyfill/test/now/plainDateTime/timezone.js | 22 +--
polyfill/test/now/plainTimeISO/timezone.js | 22 +--
.../test/now/plainTimeISO/toTime-override.js | 15 +-
polyfill/test/regex.mjs | 6 +-
polyfill/test/usercalendar.mjs | 164 ------------------
polyfill/test/usertimezone.mjs | 128 +-------------
30 files changed, 15 insertions(+), 1024 deletions(-)
delete mode 100644 polyfill/test/Instant/prototype/toZonedDateTime/calendar-convert.js
delete mode 100644 polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-invalid-result.js
delete mode 100644 polyfill/test/Instant/prototype/toZonedDateTime/calendar.js
delete mode 100644 polyfill/test/PlainDateTime/constructor/constructor/calendar-convert.js
delete mode 100644 polyfill/test/PlainDateTime/constructor/constructor/calendar-from-invalid-result.js
delete mode 100644 polyfill/test/PlainDateTime/constructor/constructor/calendar-from-undefined.js
delete mode 100644 polyfill/test/PlainDateTime/constructor/constructor/calendar.js
delete mode 100644 polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-convert.js
delete mode 100644 polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-invalid-result.js
delete mode 100644 polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar.js
delete mode 100644 polyfill/test/ZonedDateTime/constructor/constructor/timezone-undefined.js
delete mode 100644 polyfill/test/now/plainDate/calendar-convert.js
delete mode 100644 polyfill/test/now/plainDate/calendar-from-invalid-result.js
delete mode 100644 polyfill/test/now/plainDateTime/calendar-convert.js
delete mode 100644 polyfill/test/now/plainDateTime/calendar-from-invalid-result.js
diff --git a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-convert.js b/polyfill/test/Instant/prototype/toZonedDateTime/calendar-convert.js
deleted file mode 100644
index 6967e0c161..0000000000
--- a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-convert.js
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.instant.prototype.tozoneddatetime
----*/
-
-const values = [
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [2020, "2020"],
- [2n, "2"],
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-
-const calendar = Temporal.Calendar.from("iso8601");
-for (const [input, output] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, output);
- return calendar;
- };
-
- const zdt = instant.toZonedDateTime({ timeZone: "UTC", calendar: input });
- assert.sameValue(called, 1);
- assert.sameValue(zdt.calendar, calendar);
-}
-
-Temporal.Calendar.from = function() {
- throw new Test262Error("Should not call Calendar.from");
-};
-
-assert.throws(TypeError, () => instant.toZonedDateTime({ timeZone: "UTC", calendar: Symbol() }));
diff --git a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-invalid-result.js b/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-invalid-result.js
deleted file mode 100644
index 6ad5265f3e..0000000000
--- a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-invalid-result.js
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.instant.prototype.tozoneddatetime
----*/
-
-const values = [
- [undefined, "undefined"],
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [Symbol(), "Symbol()"],
- [2020, "2020"],
- [2n, "2n"],
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-const timeZone = Temporal.TimeZone.from("UTC");
-
-for (const [value, description] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, "test");
- return value;
- };
-
- assert.throws(TypeError, () => instant.toZonedDateTime({ timeZone, calendar: "test" }), description);
- assert.sameValue(called, 1);
-}
diff --git a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-undefined.js b/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-undefined.js
index 4dba2adfe8..5946cbaad8 100644
--- a/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-undefined.js
+++ b/polyfill/test/Instant/prototype/toZonedDateTime/calendar-from-undefined.js
@@ -7,9 +7,7 @@ includes: [compareArray.js]
---*/
const actual = [];
-const expected = [
- "get Temporal.Calendar.from",
-];
+const expected = [];
const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
const dateTime = Temporal.PlainDateTime.from("1963-07-02T12:34:56.987654321");
@@ -30,13 +28,6 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
const result = instant.toZonedDateTime({ timeZone, calendar: "japanese" });
assert.sameValue(result.epochNanoseconds, instant.epochNanoseconds);
assert.sameValue(result.calendar instanceof Temporal.Calendar, true);
diff --git a/polyfill/test/Instant/prototype/toZonedDateTime/calendar.js b/polyfill/test/Instant/prototype/toZonedDateTime/calendar.js
deleted file mode 100644
index 0af95a3ddb..0000000000
--- a/polyfill/test/Instant/prototype/toZonedDateTime/calendar.js
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.instant.prototype.tozoneddatetime
-includes: [compareArray.js]
----*/
-
-const actual = [];
-const expected = [
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-const dateTime = Temporal.PlainDateTime.from("1963-07-02T12:34:56.987654321");
-
-const calendar = {};
-
-const timeZone = new Proxy({
- getPlainDateTimeFor() {
- actual.push("call timeZone.getPlainDateTimeFor");
- return dateTime;
- },
-}, {
- has(target, property) {
- actual.push(`has timeZone.${property}`);
- return property in target;
- },
- get(target, property) {
- actual.push(`get timeZone.${property}`);
- return target[property];
- },
-});
-
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
-const result = instant.toZonedDateTime({ timeZone: "UTC", calendar: "iso8601" });
-assert.sameValue(result.epochNanoseconds, instant.epochNanoseconds);
-assert.sameValue(result.calendar, calendar);
-
-assert.compareArray(actual, expected);
diff --git a/polyfill/test/PlainDateTime/constructor/constructor/calendar-convert.js b/polyfill/test/PlainDateTime/constructor/constructor/calendar-convert.js
deleted file mode 100644
index 6c72ca8e12..0000000000
--- a/polyfill/test/PlainDateTime/constructor/constructor/calendar-convert.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.plaindatetime
----*/
-
-const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789];
-const values = [
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [2020, "2020"],
- [2n, "2"],
-];
-
-const calendar = Temporal.Calendar.from("iso8601");
-for (const [input, output] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, output);
- return calendar;
- };
-
- const dateTime = new Temporal.PlainDateTime(...dateTimeArgs, input);
- assert.sameValue(called, 1);
- assert.sameValue(dateTime.calendar, calendar);
-}
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- throw new Test262Error("Should not get Calendar.from");
- },
-});
-
-assert.throws(TypeError, () => new Temporal.PlainDateTime(...dateTimeArgs, Symbol()));
diff --git a/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-invalid-result.js b/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-invalid-result.js
deleted file mode 100644
index a62034e76b..0000000000
--- a/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-invalid-result.js
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.plaindatetime
----*/
-
-const values = [
- [undefined, "undefined"],
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [Symbol(), "Symbol()"],
- [2020, "2020"],
- [2n, "2n"],
-];
-
-const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789];
-
-for (const [value, description] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, "test");
- return value;
- };
-
- assert.throws(TypeError, () => new Temporal.PlainDateTime(...dateTimeArgs, "test"), description);
- assert.sameValue(called, 1);
-}
diff --git a/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-undefined.js b/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-undefined.js
deleted file mode 100644
index 1a137df4b0..0000000000
--- a/polyfill/test/PlainDateTime/constructor/constructor/calendar-from-undefined.js
+++ /dev/null
@@ -1,20 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.plaindatetime
----*/
-
-const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789];
-
-let called = 0;
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- ++called;
- return undefined;
- },
-});
-
-const dateTime = new Temporal.PlainDateTime(...dateTimeArgs, "japanese");
-assert.sameValue(called, 1);
-assert.sameValue(dateTime.calendar.toString(), "japanese");
diff --git a/polyfill/test/PlainDateTime/constructor/constructor/calendar.js b/polyfill/test/PlainDateTime/constructor/constructor/calendar.js
deleted file mode 100644
index 9a6347429e..0000000000
--- a/polyfill/test/PlainDateTime/constructor/constructor/calendar.js
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.plaindatetime
-includes: [compareArray.js]
----*/
-
-const actual = [];
-const expected = [
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
-];
-
-const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789];
-const calendar = {};
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
-const dateTime = new Temporal.PlainDateTime(...dateTimeArgs, "iso8601");
-assert.sameValue(dateTime.calendar, calendar);
-
-assert.compareArray(actual, expected);
diff --git a/polyfill/test/PlainDateTime/constructor/constructor/order-of-operations.js b/polyfill/test/PlainDateTime/constructor/constructor/order-of-operations.js
index 9df8e86cc2..4076e2ead4 100644
--- a/polyfill/test/PlainDateTime/constructor/constructor/order-of-operations.js
+++ b/polyfill/test/PlainDateTime/constructor/constructor/order-of-operations.js
@@ -26,8 +26,6 @@ const expected = [
"call argument 7 valueOf",
"get argument 8 valueOf",
"call argument 8 valueOf",
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
];
const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789].map(function (value, idx) {
@@ -42,29 +40,6 @@ const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789].map(function (val
};
});
-const calendar = {
- year(d) { return d.getISOFields().isoYear; },
- month(d) { return d.getISOFields().isoMonth; },
- day(d) { return d.getISOFields().isoDay; },
- hour(t) { return t.getISOFields().isoHour; },
- minute(t) { return t.getISOFields().isoMinute; },
- second(t) { return t.getISOFields().isoSecond; },
- millisecond(t) { return t.getISOFields().isoMillisecond; },
- microsecond(t) { return t.getISOFields().isoMicrosecond; },
- nanosecond(t) { return t.getISOFields().isoNanosecond; },
-};
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
const dateTime = new Temporal.PlainDateTime(...dateTimeArgs, "iso8601");
assert.compareArray(actual, expected);
@@ -77,4 +52,4 @@ assert.sameValue(dateTime.second, 56);
assert.sameValue(dateTime.millisecond, 123);
assert.sameValue(dateTime.microsecond, 456);
assert.sameValue(dateTime.nanosecond, 789);
-assert.sameValue(dateTime.calendar, calendar);
+assert.sameValue(dateTime.calendar.id, "iso8601");
diff --git a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-convert.js b/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-convert.js
deleted file mode 100644
index a6127622fa..0000000000
--- a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-convert.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.timezone.prototype.getplaindatetimefor
----*/
-
-const values = [
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [2020, "2020"],
- [2n, "2"],
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-const timeZone = Temporal.TimeZone.from("UTC");
-
-const calendar = Temporal.Calendar.from("iso8601");
-for (const [input, output] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, output);
- return calendar;
- };
-
- const dateTime = timeZone.getPlainDateTimeFor(instant, input);
- assert.sameValue(called, 1);
- assert.sameValue(dateTime.calendar, calendar);
-}
-
-Temporal.Calendar.from = function() {
- throw new Test262Error("Should not call Calendar.from");
-};
-
-assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(instant, Symbol()));
diff --git a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-invalid-result.js b/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-invalid-result.js
deleted file mode 100644
index a9cc81cb65..0000000000
--- a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-invalid-result.js
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.timezone.prototype.getplaindatetimefor
----*/
-
-const values = [
- [undefined, "undefined"],
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [Symbol(), "Symbol()"],
- [2020, "2020"],
- [2n, "2n"],
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-const timeZone = Temporal.TimeZone.from("UTC");
-
-for (const [value, description] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, "test");
- return value;
- };
-
- assert.throws(TypeError, () => timeZone.getPlainDateTimeFor(instant, "test"), description);
- assert.sameValue(called, 1);
-}
diff --git a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-undefined.js b/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-undefined.js
index 5e34c70552..428a3b53db 100644
--- a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-undefined.js
+++ b/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar-from-undefined.js
@@ -7,20 +7,11 @@ includes: [compareArray.js]
---*/
const actual = [];
-const expected = [
- "get Temporal.Calendar.from",
-];
+const expected = [];
const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
const timeZone = Temporal.TimeZone.from("UTC");
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
const result = timeZone.getPlainDateTimeFor(instant, "japanese");
assert.sameValue(result.calendar.toString(), "japanese");
diff --git a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar.js b/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar.js
deleted file mode 100644
index 4ec13f30d6..0000000000
--- a/polyfill/test/TimeZone/prototype/getPlainDateTimeFor/calendar.js
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.timezone.prototype.getplaindatetimefor
-includes: [compareArray.js]
----*/
-
-const actual = [];
-const expected = [
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
-];
-
-const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789Z");
-const timeZone = Temporal.TimeZone.from("UTC");
-
-const calendar = {};
-
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return undefined;
- },
-});
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
-const result = timeZone.getPlainDateTimeFor(instant, "iso8601");
-assert.sameValue(result.calendar, calendar);
-
-assert.compareArray(actual, expected);
diff --git a/polyfill/test/ZonedDateTime/constructor/constructor/timezone-undefined.js b/polyfill/test/ZonedDateTime/constructor/constructor/timezone-undefined.js
deleted file mode 100644
index 0cb73855e1..0000000000
--- a/polyfill/test/ZonedDateTime/constructor/constructor/timezone-undefined.js
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright (C) 2021 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.zoneddatetime
-includes: [compareArray.js]
-features: [BigInt]
----*/
-
-const expected = [
- "get from",
- "call from",
-];
-let actual;
-const argument = 957270896987654321n;
-const timeZone = {};
-
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get from");
- return function(identifier) {
- actual.push("call from");
- assert.sameValue(identifier, "undefined");
- return timeZone;
- };
- },
-});
-
-actual = [];
-const explicit = new Temporal.ZonedDateTime(argument, undefined);
-assert.sameValue(explicit.timeZone, timeZone);
-assert.compareArray(actual, expected, "order of operations explicit");
-
-actual = [];
-const implicit = new Temporal.ZonedDateTime(argument);
-assert.sameValue(implicit.timeZone, timeZone);
-assert.compareArray(actual, expected, "order of operations implicit");
diff --git a/polyfill/test/now/plainDate/calendar-convert.js b/polyfill/test/now/plainDate/calendar-convert.js
deleted file mode 100644
index 6bacece298..0000000000
--- a/polyfill/test/now/plainDate/calendar-convert.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.now.plaindate
----*/
-
-const values = [
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [2020, "2020"],
- [2n, "2"],
-];
-
-const calendar = Temporal.Calendar.from("iso8601");
-for (const [input, output] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, output);
- return calendar;
- };
-
- const date = Temporal.now.plainDate(input, "UTC");
- assert.sameValue(called, 1);
- assert.sameValue(date.calendar, calendar);
-}
-
-Temporal.Calendar.from = function() {
- throw new Test262Error("Should not call Calendar.from");
-};
-
-assert.throws(TypeError, () => Temporal.now.plainDate(Symbol(), "UTC"));
diff --git a/polyfill/test/now/plainDate/calendar-from-invalid-result.js b/polyfill/test/now/plainDate/calendar-from-invalid-result.js
deleted file mode 100644
index a6cc8124ea..0000000000
--- a/polyfill/test/now/plainDate/calendar-from-invalid-result.js
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.now.plaindate
----*/
-
-const values = [
- [undefined, "undefined"],
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [Symbol(), "Symbol()"],
- [2020, "2020"],
- [2n, "2n"],
-];
-
-const timeZone = Temporal.TimeZone.from("UTC");
-
-for (const [value, description] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, "test");
- return value;
- };
-
- assert.throws(TypeError, () => Temporal.now.plainDate("test", timeZone), description);
- assert.sameValue(called, 1);
-}
diff --git a/polyfill/test/now/plainDate/calendar-from-undefined.js b/polyfill/test/now/plainDate/calendar-from-undefined.js
index e60a22b606..5121a4b169 100644
--- a/polyfill/test/now/plainDate/calendar-from-undefined.js
+++ b/polyfill/test/now/plainDate/calendar-from-undefined.js
@@ -8,7 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.Calendar.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -30,13 +29,6 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
const result = Temporal.now.plainDate("japanese", timeZone);
assert.sameValue(result instanceof Temporal.PlainDate, true);
diff --git a/polyfill/test/now/plainDate/calendar.js b/polyfill/test/now/plainDate/calendar.js
index 3a37383a9f..75d7d809c0 100644
--- a/polyfill/test/now/plainDate/calendar.js
+++ b/polyfill/test/now/plainDate/calendar.js
@@ -8,10 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -35,29 +31,7 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
-const result = Temporal.now.plainDate("iso8601", "UTC");
+const result = Temporal.now.plainDate(calendar, timeZone);
assert.sameValue(result instanceof Temporal.PlainDate, true);
assert.compareArray(actual, expected);
diff --git a/polyfill/test/now/plainDate/timezone.js b/polyfill/test/now/plainDate/timezone.js
index 2dda62ec42..64afa5985c 100644
--- a/polyfill/test/now/plainDate/timezone.js
+++ b/polyfill/test/now/plainDate/timezone.js
@@ -8,8 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -31,27 +29,9 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
const calendar = Temporal.Calendar.from("iso8601");
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
-const result = Temporal.now.plainDate(calendar, "UTC");
+const result = Temporal.now.plainDate(calendar, timeZone);
assert.sameValue(result instanceof Temporal.PlainDate, true);
assert.compareArray(actual, expected);
diff --git a/polyfill/test/now/plainDate/toDate-override.js b/polyfill/test/now/plainDate/toDate-override.js
index 7a2dc7e784..8e4f5ba266 100644
--- a/polyfill/test/now/plainDate/toDate-override.js
+++ b/polyfill/test/now/plainDate/toDate-override.js
@@ -8,8 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -40,18 +38,7 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-const result = Temporal.now.plainDate("iso8601", "UTC");
+const result = Temporal.now.plainDate("iso8601", timeZone);
assert.notSameValue(result, undefined);
assert.sameValue(result instanceof Temporal.PlainDate, true);
diff --git a/polyfill/test/now/plainDateTime/calendar-convert.js b/polyfill/test/now/plainDateTime/calendar-convert.js
deleted file mode 100644
index 8d27c619bf..0000000000
--- a/polyfill/test/now/plainDateTime/calendar-convert.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.now.plaindatetime
----*/
-
-const values = [
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [2020, "2020"],
- [2n, "2"],
-];
-
-const calendar = Temporal.Calendar.from("iso8601");
-for (const [input, output] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, output);
- return calendar;
- };
-
- const dateTime = Temporal.now.plainDateTime(input, "UTC");
- assert.sameValue(called, 1);
- assert.sameValue(dateTime.calendar, calendar);
-}
-
-Temporal.Calendar.from = function() {
- throw new Test262Error("Should not call Calendar.from");
-};
-
-assert.throws(TypeError, () => Temporal.now.plainDateTime(Symbol(), "UTC"));
diff --git a/polyfill/test/now/plainDateTime/calendar-from-invalid-result.js b/polyfill/test/now/plainDateTime/calendar-from-invalid-result.js
deleted file mode 100644
index 175fd6c383..0000000000
--- a/polyfill/test/now/plainDateTime/calendar-from-invalid-result.js
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2020 Igalia, S.L. All rights reserved.
-// This code is governed by the BSD license found in the LICENSE file.
-
-/*---
-esid: sec-temporal.now.plaindatetime
----*/
-
-const values = [
- [undefined, "undefined"],
- [null, "null"],
- [true, "true"],
- ["iso8601", "iso8601"],
- [Symbol(), "Symbol()"],
- [2020, "2020"],
- [2n, "2n"],
-];
-
-const timeZone = Temporal.TimeZone.from("UTC");
-
-for (const [value, description] of values) {
- let called = 0;
- Temporal.Calendar.from = function(argument) {
- ++called;
- assert.sameValue(argument, "test");
- return value;
- };
-
- assert.throws(TypeError, () => Temporal.now.plainDateTime("test", timeZone), description);
- assert.sameValue(called, 1);
-}
diff --git a/polyfill/test/now/plainDateTime/calendar-from-undefined.js b/polyfill/test/now/plainDateTime/calendar-from-undefined.js
index 1dff98cf30..15ef853804 100644
--- a/polyfill/test/now/plainDateTime/calendar-from-undefined.js
+++ b/polyfill/test/now/plainDateTime/calendar-from-undefined.js
@@ -8,7 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.Calendar.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -30,13 +29,6 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
const result = Temporal.now.plainDateTime("japanese", timeZone);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
diff --git a/polyfill/test/now/plainDateTime/calendar.js b/polyfill/test/now/plainDateTime/calendar.js
index fd657ce8dc..a8cf9a41c0 100644
--- a/polyfill/test/now/plainDateTime/calendar.js
+++ b/polyfill/test/now/plainDateTime/calendar.js
@@ -8,10 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
- "get Temporal.Calendar.from",
- "call Temporal.Calendar.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -35,29 +31,7 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return function(argument) {
- actual.push("call Temporal.Calendar.from");
- assert.sameValue(argument, "iso8601");
- return calendar;
- };
- },
-});
-
-const result = Temporal.now.plainDateTime("iso8601", "UTC");
+const result = Temporal.now.plainDateTime(calendar, timeZone);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
}
diff --git a/polyfill/test/now/plainDateTime/timezone.js b/polyfill/test/now/plainDateTime/timezone.js
index e48930a287..13437a635c 100644
--- a/polyfill/test/now/plainDateTime/timezone.js
+++ b/polyfill/test/now/plainDateTime/timezone.js
@@ -8,8 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -31,27 +29,9 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
const calendar = Temporal.Calendar.from("iso8601");
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
-const result = Temporal.now.plainDateTime(calendar, "UTC");
+const result = Temporal.now.plainDateTime(calendar, timeZone);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
}
diff --git a/polyfill/test/now/plainTimeISO/timezone.js b/polyfill/test/now/plainTimeISO/timezone.js
index f9ab51252a..ee1434a1b5 100644
--- a/polyfill/test/now/plainTimeISO/timezone.js
+++ b/polyfill/test/now/plainTimeISO/timezone.js
@@ -8,8 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -31,25 +29,7 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-Object.defineProperty(Temporal.Calendar, "from", {
- get() {
- actual.push("get Temporal.Calendar.from");
- return undefined;
- },
-});
-
-const result = Temporal.now.plainTimeISO("UTC");
+const result = Temporal.now.plainTimeISO(timeZone);
assert.sameValue(result instanceof Temporal.PlainTime, true);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
diff --git a/polyfill/test/now/plainTimeISO/toTime-override.js b/polyfill/test/now/plainTimeISO/toTime-override.js
index 50b7873f85..0d70a92b46 100644
--- a/polyfill/test/now/plainTimeISO/toTime-override.js
+++ b/polyfill/test/now/plainTimeISO/toTime-override.js
@@ -8,8 +8,6 @@ includes: [compareArray.js]
const actual = [];
const expected = [
- "get Temporal.TimeZone.from",
- "call Temporal.TimeZone.from",
"get timeZone.getOffsetNanosecondsFor",
"call timeZone.getOffsetNanosecondsFor",
];
@@ -40,18 +38,7 @@ const timeZone = new Proxy({
},
});
-Object.defineProperty(Temporal.TimeZone, "from", {
- get() {
- actual.push("get Temporal.TimeZone.from");
- return function(argument) {
- actual.push("call Temporal.TimeZone.from");
- assert.sameValue(argument, "UTC");
- return timeZone;
- };
- },
-});
-
-const result = Temporal.now.plainTimeISO("UTC");
+const result = Temporal.now.plainTimeISO(timeZone);
assert.sameValue(result instanceof Temporal.PlainTime, true);
for (const property of ["hour", "minute", "second", "millisecond", "microsecond", "nanosecond"]) {
assert.sameValue(result[property], 0, property);
diff --git a/polyfill/test/regex.mjs b/polyfill/test/regex.mjs
index 7e4f82fce6..07aefbbdba 100644
--- a/polyfill/test/regex.mjs
+++ b/polyfill/test/regex.mjs
@@ -588,7 +588,8 @@ describe('fromString regex', () => {
}
});
- describe('time zone ID', () => {
+ // These can be tested again once the resolver options are accepted.
+ describe.skip('time zone ID', () => {
let oldTemporalTimeZoneFrom = Temporal.TimeZone.from;
let fromCalledWith;
before(() => {
@@ -660,7 +661,8 @@ describe('fromString regex', () => {
});
});
- describe('calendar ID', () => {
+ // These can be tested again once the resolver options are accepted.
+ describe.skip('calendar ID', () => {
let oldTemporalCalendarFrom = Temporal.Calendar.from;
let fromCalledWith;
before(() => {
diff --git a/polyfill/test/usercalendar.mjs b/polyfill/test/usercalendar.mjs
index 09ffca8b14..fa5c328057 100644
--- a/polyfill/test/usercalendar.mjs
+++ b/polyfill/test/usercalendar.mjs
@@ -139,88 +139,6 @@ describe('Userland calendar', () => {
const nowDate = Temporal.now.plainDate(obj, 'UTC');
equal(nowDate.calendar.id, obj.id);
});
- describe('Making available globally', () => {
- const originalTemporalCalendarFrom = Temporal.Calendar.from;
- before(() => {
- Temporal.Calendar.from = function (item) {
- let id;
- if (item instanceof Temporal.Calendar) {
- id = item.id;
- } else {
- id = `${item}`;
- // TODO: Use Temporal.parse here to extract the ID from an ISO string
- }
- if (id === 'two-based') return new TwoBasedCalendar();
- return originalTemporalCalendarFrom.call(this, id);
- };
- });
- it('works for Calendar.from(id)', () => {
- const tz = Temporal.Calendar.from('two-based');
- assert(tz instanceof TwoBasedCalendar);
- });
- const iso = '1970-01-01T00:00+00:00[u-ca-two-based]';
- it.skip('works for Calendar.from(ISO string)', () => {
- const tz = Temporal.Calendar.from(iso);
- assert(tz instanceof TwoBasedCalendar);
- });
- it('works for Date.from(iso)', () => {
- const d = Temporal.PlainDate.from(iso);
- equal(`${d}`, '1970-01-01[u-ca-two-based]');
- });
- it('works for Date.from(props)', () => {
- const d = Temporal.PlainDate.from({ year: 1970, month: 2, day: 1, calendar: 'two-based' });
- equal(`${d}`, '1970-01-01[u-ca-two-based]');
- });
- it('works for Date.withCalendar', () => {
- const d = Temporal.PlainDate.from('1970-01-01');
- assert(d.withCalendar('two-based').equals(Temporal.PlainDate.from(iso)));
- });
- it('works for DateTime.from(iso)', () => {
- const dt = Temporal.PlainDateTime.from(iso);
- equal(`${dt}`, '1970-01-01T00:00:00[u-ca-two-based]');
- });
- it('works for DateTime.from(props)', () => {
- const dt = Temporal.PlainDateTime.from({ year: 1970, month: 2, day: 1, hour: 12, calendar: 'two-based' });
- equal(`${dt}`, '1970-01-01T12:00:00[u-ca-two-based]');
- });
- it('works for DateTime.withCalendar', () => {
- const dt = Temporal.PlainDateTime.from('1970-01-01T00:00');
- assert(dt.withCalendar('two-based').equals(Temporal.PlainDateTime.from(iso)));
- });
- it('works for YearMonth.from(iso)', () => {
- const ym = Temporal.PlainYearMonth.from(iso);
- equal(`${ym}`, '1970-01-01[u-ca-two-based]');
- });
- it('works for YearMonth.from(props)', () => {
- const ym = Temporal.PlainYearMonth.from({ year: 1970, month: 2, calendar: 'two-based' });
- equal(`${ym}`, '1970-01-01[u-ca-two-based]');
- });
- it('works for MonthDay.from(iso)', () => {
- const md = Temporal.PlainMonthDay.from(iso);
- equal(`${md}`, '1972-01-01[u-ca-two-based]');
- });
- it('works for MonthDay.from(props)', () => {
- const md = Temporal.PlainMonthDay.from({ monthCode: 'M02', day: 1, calendar: 'two-based' });
- equal(`${md}`, '1972-01-01[u-ca-two-based]');
- });
- it('works for TimeZone.getPlainDateTimeFor', () => {
- const tz = Temporal.TimeZone.from('UTC');
- const inst = Temporal.Instant.fromEpochSeconds(0);
- const dt = tz.getPlainDateTimeFor(inst, 'two-based');
- equal(dt.calendar.id, 'two-based');
- });
- it('works for Temporal.now.plainDateTime', () => {
- const nowDateTime = Temporal.now.plainDateTime('two-based', 'UTC');
- equal(nowDateTime.calendar.id, 'two-based');
- });
- it('works for Temporal.now.plainDate', () => {
- const nowDate = Temporal.now.plainDate('two-based', 'UTC');
- equal(nowDate.calendar.id, 'two-based');
- });
- after(() => {
- Temporal.Calendar.from = originalTemporalCalendarFrom;
- });
- });
});
describe('Trivial protocol implementation', () => {
// For the purposes of testing, a nonsensical calendar that has 10-month
@@ -367,88 +285,6 @@ describe('Userland calendar', () => {
const nowDate = Temporal.now.plainDate(obj, 'UTC');
equal(nowDate.calendar.id, obj.id);
});
- describe('Making available globally', () => {
- const originalTemporalCalendarFrom = Temporal.Calendar.from;
- before(() => {
- Temporal.Calendar.from = function (item) {
- let id;
- if (typeof item === 'object' && item) {
- id = item.id;
- } else {
- id = `${item}`;
- // TODO: Use Temporal.parse here to extract the ID from an ISO string
- }
- if (id === 'decimal') return obj;
- return originalTemporalCalendarFrom.call(this, id);
- };
- });
- it('works for Calendar.from(id)', () => {
- const cal = Temporal.Calendar.from('decimal');
- assert(Object.is(cal, obj));
- });
- const iso = '1970-01-01T00:00+00:00[u-ca-decimal]';
- it.skip('works for Calendar.from(ISO string)', () => {
- const cal = Temporal.Calendar.from(iso);
- assert(Object.is(cal, obj));
- });
- it('works for Date.from(iso)', () => {
- const d = Temporal.PlainDate.from(iso);
- equal(`${d}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for Date.from(props)', () => {
- const d = Temporal.PlainDate.from({ year: 0, month: 1, day: 1, calendar: 'decimal' });
- equal(`${d}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for Date.withCalendar', () => {
- const d = Temporal.PlainDate.from('1970-01-01');
- assert(d.withCalendar('decimal').equals(Temporal.PlainDate.from(iso)));
- });
- it('works for DateTime.from(iso)', () => {
- const dt = Temporal.PlainDateTime.from(iso);
- equal(`${dt}`, '1970-01-01T00:00:00[u-ca-decimal]');
- });
- it('works for DateTime.from(props)', () => {
- const dt = Temporal.PlainDateTime.from({ year: 0, month: 1, day: 1, hour: 12, calendar: 'decimal' });
- equal(`${dt}`, '1970-01-01T12:00:00[u-ca-decimal]');
- });
- it('works for DateTime.withCalendar', () => {
- const dt = Temporal.PlainDateTime.from('1970-01-01T00:00');
- assert(dt.withCalendar('decimal').equals(Temporal.PlainDateTime.from(iso)));
- });
- it('works for YearMonth.from(iso)', () => {
- const ym = Temporal.PlainYearMonth.from(iso);
- equal(`${ym}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for YearMonth.from(props)', () => {
- const ym = Temporal.PlainYearMonth.from({ year: 0, month: 1, calendar: 'decimal' });
- equal(`${ym}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for MonthDay.from(iso)', () => {
- const md = Temporal.PlainMonthDay.from(iso);
- equal(`${md}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for MonthDay.from(props)', () => {
- const md = Temporal.PlainMonthDay.from({ monthCode: 'M01', day: 1, calendar: 'decimal' });
- equal(`${md}`, '1970-01-01[u-ca-decimal]');
- });
- it('works for TimeZone.getPlainDateTimeFor', () => {
- const tz = Temporal.TimeZone.from('UTC');
- const inst = Temporal.Instant.fromEpochSeconds(0);
- const dt = tz.getPlainDateTimeFor(inst, 'decimal');
- equal(`${dt.calendar}`, 'decimal');
- });
- it('works for Temporal.now.plainDateTime', () => {
- const nowDateTime = Temporal.now.plainDateTime('decimal', 'UTC');
- equal(`${nowDateTime.calendar}`, 'decimal');
- });
- it('works for Temporal.now.plainDate', () => {
- const nowDate = Temporal.now.plainDate('decimal', 'UTC');
- equal(`${nowDate.calendar}`, 'decimal');
- });
- after(() => {
- Temporal.Calendar.from = originalTemporalCalendarFrom;
- });
- });
});
describe('calendar with extra fields', () => {
// Contrived example of a calendar identical to the ISO calendar except that
diff --git a/polyfill/test/usertimezone.mjs b/polyfill/test/usertimezone.mjs
index 3220c96d15..fb6aa8528c 100644
--- a/polyfill/test/usertimezone.mjs
+++ b/polyfill/test/usertimezone.mjs
@@ -4,7 +4,7 @@
// This code is governed by the BSD license found in the LICENSE file.
import Demitasse from '@pipobscure/demitasse';
-const { after, before, describe, it, report } = Demitasse;
+const { describe, it, report } = Demitasse;
import Pretty from '@pipobscure/demitasse-pretty';
const { reporter } = Pretty;
@@ -75,48 +75,6 @@ describe('Userland time zone', () => {
assert(Temporal.now.plainDate('gregory', obj) instanceof Temporal.PlainDate);
assert(Temporal.now.plainTimeISO(obj) instanceof Temporal.PlainTime);
});
- describe('Making available globally', () => {
- const originalTemporalTimeZoneFrom = Temporal.TimeZone.from;
- before(() => {
- Temporal.TimeZone.from = function (item) {
- let id;
- if (item instanceof Temporal.TimeZone) {
- id = item.id;
- } else {
- id = `${item}`;
- // TODO: Use Temporal.parse here to extract the ID from an ISO string
- }
- if (id === 'Etc/Custom/UTC_Subclass') return new CustomUTCSubclass();
- return originalTemporalTimeZoneFrom.call(this, id);
- };
- });
- it('works for TimeZone.from(id)', () => {
- const tz = Temporal.TimeZone.from('Etc/Custom/UTC_Subclass');
- assert(tz instanceof CustomUTCSubclass);
- });
- it.skip('works for TimeZone.from(ISO string)', () => {
- const tz = Temporal.TimeZone.from('1970-01-01T00:00+00:00[Etc/Custom/UTC_Subclass]');
- assert(tz instanceof CustomUTCSubclass);
- });
- it('works for Instant.from', () => {
- const instant = Temporal.Instant.from('1970-01-01T00:00+00:00[Etc/Custom/UTC_Subclass]');
- equal(`${instant}`, '1970-01-01T00:00:00Z');
- });
- it('works for Instant.toString', () => {
- const inst = Temporal.Instant.fromEpochSeconds(0);
- equal(inst.toString({ timeZone: 'Etc/Custom/UTC_Subclass' }), '1970-01-01T00:00:00+00:00');
- });
- it('works for Temporal.now', () => {
- assert(Temporal.now.plainDateTimeISO('Etc/Custom/UTC_Subclass') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateTime('gregory', 'Etc/Custom/UTC_Subclass') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateISO('Etc/Custom/UTC_Subclass') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainDate('gregory', 'Etc/Custom/UTC_Subclass') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainTimeISO('Etc/Custom/UTC_Subclass') instanceof Temporal.PlainTime);
- });
- after(() => {
- Temporal.TimeZone.from = originalTemporalTimeZoneFrom;
- });
- });
});
describe('Trivial protocol implementation', () => {
const obj = {
@@ -162,48 +120,6 @@ describe('Userland time zone', () => {
assert(Temporal.now.plainDate('gregory', obj) instanceof Temporal.PlainDate);
assert(Temporal.now.plainTimeISO(obj) instanceof Temporal.PlainTime);
});
- describe('Making available globally', () => {
- const originalTemporalTimeZoneFrom = Temporal.TimeZone.from;
- before(() => {
- Temporal.TimeZone.from = function (item) {
- let id;
- if (item instanceof Temporal.TimeZone) {
- id = item.id;
- } else {
- id = `${item}`;
- // TODO: Use Temporal.parse here to extract the ID from an ISO string
- }
- if (id === 'Etc/Custom/UTC_Protocol') return obj;
- return originalTemporalTimeZoneFrom.call(this, id);
- };
- });
- it('works for TimeZone.from(id)', () => {
- const tz = Temporal.TimeZone.from('Etc/Custom/UTC_Protocol');
- assert(Object.is(tz, obj));
- });
- it.skip('works for TimeZone.from(ISO string)', () => {
- const tz = Temporal.TimeZone.from('1970-01-01T00:00+00:00[Etc/Custom/UTC_Protocol]');
- assert(Object.is(tz, obj));
- });
- it('works for Instant.from', () => {
- const inst = Temporal.Instant.from('1970-01-01T00:00:00+00:00[Etc/Custom/UTC_Protocol]');
- equal(`${inst}`, '1970-01-01T00:00:00Z');
- });
- it('works for Instant.toString', () => {
- const inst = Temporal.Instant.fromEpochSeconds(0);
- equal(inst.toString({ timeZone: 'Etc/Custom/UTC_Protocol' }), '1970-01-01T00:00:00+00:00');
- });
- it('works for Temporal.now', () => {
- assert(Temporal.now.plainDateTimeISO('Etc/Custom/UTC_Protocol') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateTime('gregory', 'Etc/Custom/UTC_Protocol') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateISO('Etc/Custom/UTC_Protocol') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainDate('gregory', 'Etc/Custom/UTC_Protocol') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainTimeISO('Etc/Custom/UTC_Protocol') instanceof Temporal.PlainTime);
- });
- after(() => {
- Temporal.TimeZone.from = originalTemporalTimeZoneFrom;
- });
- });
});
describe('sub-minute offset', () => {
class SubminuteTimeZone extends Temporal.TimeZone {
@@ -266,48 +182,6 @@ describe('Userland time zone', () => {
assert(Temporal.now.plainDate('gregory', obj) instanceof Temporal.PlainDate);
assert(Temporal.now.plainTimeISO(obj) instanceof Temporal.PlainTime);
});
- describe('Making available globally', () => {
- const originalTemporalTimeZoneFrom = Temporal.TimeZone.from;
- before(() => {
- Temporal.TimeZone.from = function (item) {
- let id;
- if (item instanceof Temporal.TimeZone) {
- id = item.id;
- } else {
- id = `${item}`;
- // TODO: Use Temporal.parse here to extract the ID from an ISO string
- }
- if (id === 'Custom/Subminute') return new SubminuteTimeZone();
- return originalTemporalTimeZoneFrom.call(this, id);
- };
- });
- it('works for TimeZone.from(id)', () => {
- const tz = Temporal.TimeZone.from('Custom/Subminute');
- assert(tz instanceof SubminuteTimeZone);
- });
- it.skip('works for TimeZone.from(ISO string)', () => {
- const tz = Temporal.TimeZone.from('1970-01-01T00:00-00:00:01.111111111[Custom/Subminute]');
- assert(tz instanceof SubminuteTimeZone);
- });
- it('works for Instant.from', () => {
- const instant = Temporal.Instant.from('1970-01-01T11:59:58.888888889-00:00:01.111111111[Custom/Subminute]');
- equal(`${instant}`, '1970-01-01T12:00:00Z');
- });
- it('works for Instant.toString', () => {
- const inst = Temporal.Instant.fromEpochSeconds(0);
- equal(inst.toString({ timeZone: 'Custom/Subminute' }), '1969-12-31T23:59:58.888888889-00:00:01.111111111');
- });
- it('works for Temporal.now', () => {
- assert(Temporal.now.plainDateTimeISO('Custom/Subminute') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateTime('gregory', 'Custom/Subminute') instanceof Temporal.PlainDateTime);
- assert(Temporal.now.plainDateISO('Custom/Subminute') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainDate('gregory', 'Custom/Subminute') instanceof Temporal.PlainDate);
- assert(Temporal.now.plainTimeISO('Custom/Subminute') instanceof Temporal.PlainTime);
- });
- after(() => {
- Temporal.TimeZone.from = originalTemporalTimeZoneFrom;
- });
- });
});
});
From 955c9d29d4e0f5506b28e7b80bab438307fa1255 Mon Sep 17 00:00:00 2001
From: Ujjwal Sharma
Date: Sat, 6 Mar 2021 08:23:37 +0530
Subject: [PATCH 4/4] polyfill: update TimeZoneFrom and CalendarFrom
---
polyfill/lib/calendar.mjs | 18 ++-----------
polyfill/lib/ecmascript.mjs | 51 +++++++++++++++++++++----------------
polyfill/lib/timezone.mjs | 11 +-------
spec/calendar.html | 20 ++++++++++++---
spec/timezone.html | 8 +++---
spec/zoneddatetime.html | 2 +-
6 files changed, 53 insertions(+), 57 deletions(-)
diff --git a/polyfill/lib/calendar.mjs b/polyfill/lib/calendar.mjs
index ecf990499e..41258e04ee 100644
--- a/polyfill/lib/calendar.mjs
+++ b/polyfill/lib/calendar.mjs
@@ -153,21 +153,7 @@ export class Calendar {
return ES.ToString(this);
}
static from(item) {
- if (ES.Type(item) === 'Object') {
- if (!('calendar' in item)) return item;
- item = item.calendar;
- if (ES.Type(item) === 'Object' && !('calendar' in item)) return item;
- }
- const stringIdent = ES.ToString(item);
- if (IsBuiltinCalendar(stringIdent)) return new Calendar(stringIdent);
- let calendar;
- try {
- ({ calendar } = ES.ParseISODateTime(stringIdent, { zoneRequired: false }));
- } catch {
- throw new RangeError(`Invalid calendar: ${stringIdent}`);
- }
- if (!calendar) calendar = 'iso8601';
- return new Calendar(calendar);
+ return ES.CalendarFrom(item, this);
}
}
@@ -2000,6 +1986,6 @@ impl['gregory'] = ObjectAssign({}, nonIsoGeneralImpl, { helper: helperGregory })
const BUILTIN_CALENDAR_IDS = Object.keys(impl);
-function IsBuiltinCalendar(id) {
+export function IsBuiltinCalendar(id) {
return ArrayIncludes.call(BUILTIN_CALENDAR_IDS, id);
}
diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs
index 1c9a76f351..d7de739795 100644
--- a/polyfill/lib/ecmascript.mjs
+++ b/polyfill/lib/ecmascript.mjs
@@ -62,6 +62,7 @@ import {
MICROSECONDS,
NANOSECONDS
} from './slots.mjs';
+import { IsBuiltinCalendar } from './calendar.mjs';
const DAYMILLIS = 86400000;
const NS_MIN = bigInt(-86400).multiply(1e17);
@@ -1481,7 +1482,7 @@ export const ES = ObjectAssign({}, ES2020, {
calendar
} = ES.ParseTemporalZonedDateTimeString(ES.ToString(item)));
if (!ianaName) throw new RangeError('time zone ID required in brackets');
- timeZone = ES.TimeZoneFrom(ianaName);
+ timeZone = ES.TimeZoneFrom(ianaName, GetIntrinsic('%Temporal.TimeZone%'));
if (!calendar) calendar = ES.GetISO8601Calendar();
calendar = ES.ToTemporalCalendar(calendar);
}
@@ -1513,18 +1514,22 @@ export const ES = ObjectAssign({}, ES2020, {
const TemporalCalendar = GetIntrinsic('%Temporal.Calendar%');
return new TemporalCalendar('iso8601');
},
- CalendarFrom: (calendarLike) => {
- const TemporalCalendar = GetIntrinsic('%Temporal.Calendar%');
- // let from = TemporalCalendar.from;
- // if (from === undefined) {
- // from = GetIntrinsic('%Temporal.Calendar.from%');
- // }
- const from = GetIntrinsic('%Temporal.Calendar.from%');
- const calendar = ES.Call(from, TemporalCalendar, [calendarLike]);
- if (ES.Type(calendar) !== 'Object') {
- throw new TypeError('Temporal.Calendar.from should return an object');
+ CalendarFrom: (item, constructor) => {
+ if (ES.Type(item) === 'Object') {
+ if (!('calendar' in item)) return item;
+ item = item.calendar;
+ if (ES.Type(item) === 'Object' && !('calendar' in item)) return item;
+ }
+ const stringIdent = ES.ToString(item);
+ if (IsBuiltinCalendar(stringIdent)) return new constructor(stringIdent);
+ let calendar;
+ try {
+ ({ calendar } = ES.ParseISODateTime(stringIdent, { zoneRequired: false }));
+ } catch {
+ throw new RangeError(`Invalid calendar: ${stringIdent}`);
}
- return calendar;
+ if (!calendar) calendar = 'iso8601';
+ return new constructor(calendar);
},
CalendarFields: (calendar, fieldNames) => {
const fields = ES.GetMethod(calendar, 'fields');
@@ -1634,7 +1639,7 @@ export const ES = ObjectAssign({}, ES2020, {
return calendarLike;
}
const identifier = ES.ToString(calendarLike);
- return ES.CalendarFrom(identifier);
+ return ES.CalendarFrom(identifier, GetIntrinsic('%Temporal.Calendar%'));
},
CalendarCompare: (one, two) => {
const cal1 = ES.ToString(one);
@@ -1675,21 +1680,23 @@ export const ES = ObjectAssign({}, ES2020, {
if (!ES.IsTemporalMonthDay(result)) throw new TypeError('invalid result');
return result;
},
- TimeZoneFrom: (temporalTimeZoneLike) => {
- const TemporalTimeZone = GetIntrinsic('%Temporal.TimeZone%');
- // let from = TemporalTimeZone.from;
- // if (from === undefined) {
- // from = GetIntrinsic('%Temporal.TimeZone.from%');
- // }
- const from = GetIntrinsic('%Temporal.TimeZone.from%');
- return ES.Call(from, TemporalTimeZone, [temporalTimeZoneLike]);
+ TimeZoneFrom: (item, constructor) => {
+ if (ES.Type(item) === 'Object') {
+ if (!('timeZone' in item)) return item;
+ item = item.timeZone;
+ if (ES.Type(item) === 'Object' && !('timeZone' in item)) return item;
+ }
+ const timeZone = ES.TemporalTimeZoneFromString(ES.ToString(item));
+ const result = new constructor(timeZone);
+ if (!ES.IsTemporalTimeZone(result)) throw new TypeError('invalid result');
+ return result;
},
ToTemporalTimeZone: (temporalTimeZoneLike) => {
if (ES.Type(temporalTimeZoneLike) === 'Object') {
return temporalTimeZoneLike;
}
const identifier = ES.ToString(temporalTimeZoneLike);
- return ES.TimeZoneFrom(identifier);
+ return ES.TimeZoneFrom(identifier, GetIntrinsic('%Temporal.TimeZone%'));
},
TimeZoneCompare: (one, two) => {
const tz1 = ES.ToString(one);
diff --git a/polyfill/lib/timezone.mjs b/polyfill/lib/timezone.mjs
index 00263de6d2..4f12864527 100644
--- a/polyfill/lib/timezone.mjs
+++ b/polyfill/lib/timezone.mjs
@@ -143,18 +143,9 @@ export class TimeZone {
return ES.ToString(this);
}
static from(item) {
- if (ES.Type(item) === 'Object') {
- if (!('timeZone' in item)) return item;
- item = item.timeZone;
- if (ES.Type(item) === 'Object' && !('timeZone' in item)) return item;
- }
- const timeZone = ES.TemporalTimeZoneFromString(ES.ToString(item));
- const result = new this(timeZone);
- if (!ES.IsTemporalTimeZone(result)) throw new TypeError('invalid result');
- return result;
+ return ES.TimeZoneFrom(item, this);
}
}
MakeIntrinsicClass(TimeZone, 'Temporal.TimeZone');
-DefineIntrinsic('Temporal.TimeZone.from', TimeZone.from);
DefineIntrinsic('Temporal.TimeZone.prototype.getOffsetNanosecondsFor', TimeZone.prototype.getOffsetNanosecondsFor);
diff --git a/spec/calendar.html b/spec/calendar.html
index 0e3e96dc75..68894ec7f3 100644
--- a/spec/calendar.html
+++ b/spec/calendar.html
@@ -8,6 +8,17 @@ Temporal.Calendar Objects
Abstract Operations for Temporal.Calendar Objects
+
+ CreateTemporalCalendarFromStatic ( _constructor_, _identifier_ )
+
+ 1. Assert: ! IsBuiltinCalendar(_identifier_) is *true*.
+ 1. If ! IsConstructor(_constructor_) is *false*, throw a *TypeError* exception.
+ 1. Let _result_ be ? Construct(_constructor_, « _identifier_ »).
+ 1. Perform ? RequireInternalSlot(_result_, [[InitializedTemporalCalendar]]).
+ 1. Return _result_.
+
+
+
IsBuiltinCalendar ( _id_ )
@@ -228,7 +239,7 @@
ToTemporalCalendar ( _temporalCalendarLike_ )
1. If Type(_temporalCalendarLike_) is Object, then
1. Return _temporalCalendarLike_.
1. Let _identifier_ be ? ToString(_temporalCalendarLike_).
- 1. Return ? CalendarFrom(_identifier_).
+ 1. Return ? CalendarFrom(_identifier_, %Temporal.Calendar%).
@@ -258,7 +269,7 @@ GetOptionalTemporalCalendar ( _item_ )
- CalendarFrom ( _identifier_ )
+ CalendarFrom ( _identifier_, _constructor_ )
1. If Type(_item_) is Object, then
1. If ? HasProperty(_item_, *"calendar"*) is *false*, return _item_.
@@ -267,7 +278,7 @@ CalendarFrom ( _identifier_ )
1. Let _string_ be ? ToString(_item_).
1. If ! IsBuiltinCalendar(_string_) is *false*, then
1. Let _string_ be ? ParseTemporalCalendarString(_string_).
- 1. Return ? GetBuiltinCalendar(_string_).
+ 1. Return ? CreateTemporalCalendarFromStatic(_constructor_, _string_).
@@ -663,7 +674,8 @@ Temporal.Calendar.from ( _item_ )
The following steps are taken:
- 1. Return ? CalendarFrom(_item_).
+ 1. Let _constructor_ be the *this* value.
+ 1. Return ? CalendarFrom(_item_, _constructor_).
diff --git a/spec/timezone.html b/spec/timezone.html
index 9a27a0ff35..9e3d6f5f57 100644
--- a/spec/timezone.html
+++ b/spec/timezone.html
@@ -163,7 +163,8 @@ Temporal.TimeZone.from ( _item_ )
The following steps are taken:
- 1. Return ? TimeZoneFrom(_item_).
+ 1. Let _constructor_ be the *this* value.
+ 1. Return ? TimeZoneFrom(_item_, _constructor_).
@@ -561,12 +562,12 @@ ToTemporalTimeZone ( _temporalTimeZoneLike_ )
1. If Type(_temporalTimeZoneLike_) is Object, return _temporalTimeZoneLike_.
1. Let _identifier_ be ? ToString(_temporalTimeZoneLike_).
- 1. Return ? TimeZoneFrom(_identifier_).
+ 1. Return ? TimeZoneFrom(_identifier_, %Temporal.TimeZone%).
- TimeZoneFrom ( _identifier_ )
+ TimeZoneFrom ( _identifier_, _constructor_ )
1. If Type(_item_) is Object, then
1. If ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
@@ -574,7 +575,6 @@ TimeZoneFrom ( _identifier_ )
1. If Type(_item_) is Object and ? HasProperty(_item_, *"timeZone"*) is *false*, return _item_.
1. Let _string_ be ? ToString(_item_).
1. Let _result_ be ? ParseTemporalTimeZone(_string_).
- 1. Let _constructor_ be the *this* value.
1. Return ? CreateTemporalTimeZoneFromStatic(_constructor_, _result_).
diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html
index a3254719ee..872c052422 100644
--- a/spec/zoneddatetime.html
+++ b/spec/zoneddatetime.html
@@ -1139,7 +1139,7 @@ ToTemporalZonedDateTime ( _item_ [ , _constructor_ [ , _options_ ] ] )
1. Let _string_ be ? ToString(_item_).
1. Let _result_ be ? ParseTemporalZonedDateTimeString(_string_).
1. If _result_.[[TimeZoneName]] is *undefined*, throw a *RangeError* exception.
- 1. Let _timeZone_ be ? TimeZoneFrom(_result_.[[TimeZoneName]]).
+ 1. Let _timeZone_ be ? TimeZoneFrom(_result_.[[TimeZoneName]], %Temporal.TimeZone%).
1. Let _offsetString_ be _result_.[[TimeZoneOffsetString]].
1. Let _calendar_ be ? ToOptionalTemporalCalendar(_result_.[[Calendar]]).
1. Let _offsetNanoseconds_ be ? ParseTimeZoneOffsetString(_offsetString_).