Temporal: Remove tests that throw on calendar or time zone method accesses

Many tests tested some functionality while asserting that there were no
calls of calendar or time zone methods. We can continue testing the
functionality, but there are no more methods to call, so we can delete
those parts of the tests.
This commit is contained in:
Philip Chimento 2024-06-04 12:24:26 +02:00 committed by Ms2ger
parent 7d970fbe4e
commit debd22a2ad
37 changed files with 18 additions and 655 deletions

View File

@ -1589,63 +1589,6 @@ var TemporalHelpers = {
}); });
}, },
/*
* A custom calendar that does not allow any of its methods to be called, for
* the purpose of asserting that a particular operation does not call into
* user code.
*/
calendarThrowEverything() {
class CalendarThrowEverything extends Temporal.Calendar {
constructor() {
super("iso8601");
}
toString() {
TemporalHelpers.assertUnreachable("toString should not be called");
}
dateFromFields() {
TemporalHelpers.assertUnreachable("dateFromFields should not be called");
}
yearMonthFromFields() {
TemporalHelpers.assertUnreachable("yearMonthFromFields should not be called");
}
monthDayFromFields() {
TemporalHelpers.assertUnreachable("monthDayFromFields should not be called");
}
dateAdd() {
TemporalHelpers.assertUnreachable("dateAdd should not be called");
}
dateUntil() {
TemporalHelpers.assertUnreachable("dateUntil should not be called");
}
era() {
TemporalHelpers.assertUnreachable("era should not be called");
}
eraYear() {
TemporalHelpers.assertUnreachable("eraYear should not be called");
}
year() {
TemporalHelpers.assertUnreachable("year should not be called");
}
month() {
TemporalHelpers.assertUnreachable("month should not be called");
}
monthCode() {
TemporalHelpers.assertUnreachable("monthCode should not be called");
}
day() {
TemporalHelpers.assertUnreachable("day should not be called");
}
fields() {
TemporalHelpers.assertUnreachable("fields should not be called");
}
mergeFields() {
TemporalHelpers.assertUnreachable("mergeFields should not be called");
}
}
return new CalendarThrowEverything();
},
/* /*
* oneShiftTimeZone(shiftInstant, shiftNanoseconds): * oneShiftTimeZone(shiftInstant, shiftNanoseconds):
* *
@ -1826,30 +1769,6 @@ var TemporalHelpers = {
}); });
}, },
/*
* A custom time zone that does not allow any of its methods to be called, for
* the purpose of asserting that a particular operation does not call into
* user code.
*/
timeZoneThrowEverything() {
class TimeZoneThrowEverything extends Temporal.TimeZone {
constructor() {
super("UTC");
}
getOffsetNanosecondsFor() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be called");
}
getPossibleInstantsFor() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be called");
}
toString() {
TemporalHelpers.assertUnreachable("toString should not be called");
}
}
return new TimeZoneThrowEverything();
},
/* /*
* Returns an object that will append logs of any Gets or Calls of its valueOf * Returns an object that will append logs of any Gets or Calls of its valueOf
* or toString properties to the array calls. Both valueOf and toString will * or toString properties to the array calls. Both valueOf and toString will

View File

@ -3,10 +3,7 @@
/*--- /*---
esid: sec-temporal.duration.compare esid: sec-temporal.duration.compare
description: > description: Return when two Temporal.Durations have identical internal slots
Shortcut return with no observable user code calls when two Temporal.Duration
have identical internal slots
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
@ -22,23 +19,9 @@ assert.sameValue(
"relativeTo is not required if two distinct Duration instances are identical" "relativeTo is not required if two distinct Duration instances are identical"
); );
const calendar = TemporalHelpers.calendarThrowEverything();
const relativeTo = new Temporal.PlainDate(2000, 1, 1, calendar);
assert.sameValue(
Temporal.Duration.compare(dateDuration1, dateDuration2, { relativeTo }),
0,
"no calendar methods are called if two distinct Duration instances are identical"
);
const dateDuration3 = new Temporal.Duration(5, 5, 5, 5, 4, 65, 5, 5, 5, 5); const dateDuration3 = new Temporal.Duration(5, 5, 5, 5, 4, 65, 5, 5, 5, 5);
assert.throws( assert.throws(
RangeError, RangeError,
() => Temporal.Duration.compare(dateDuration1, dateDuration3), () => Temporal.Duration.compare(dateDuration1, dateDuration3),
"relativeTo is required if two Duration instances are the same length but not identical" "relativeTo is required if two Duration instances are the same length but not identical"
); );
assert.throws(
Test262Error,
() => Temporal.Duration.compare(dateDuration1, dateDuration3, { relativeTo }),
"calendar methods are called if two Duration instances are the same length but not identical"
);

View File

@ -4,32 +4,11 @@
/*--- /*---
esid: sec-temporal.duration.compare esid: sec-temporal.duration.compare
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Duration.compare(new Temporal.Duration(1), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); Temporal.Duration.compare(new Temporal.Duration(1), new Temporal.Duration(), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,27 +4,9 @@
/*--- /*---
esid: sec-temporal.duration.prototype.round esid: sec-temporal.duration.prototype.round
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
@ -32,6 +14,3 @@ const instance = new Temporal.Duration(1);
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); instance.round({ largestUnit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,16 +4,13 @@
/*--- /*---
esid: sec-temporal.duration.prototype.round esid: sec-temporal.duration.prototype.round
description: > description: >
No calendar or time zone methods are called under circumstances where rounding Circumstances where rounding is a no-op, return a new but equal duration
is a no-op
includes: [temporalHelpers.js] includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const calendar = TemporalHelpers.calendarThrowEverything(); const plainRelativeTo = new Temporal.PlainDate(2000, 1, 1, "iso8601");
const timeZone = TemporalHelpers.timeZoneThrowEverything(); const zonedRelativeTo = new Temporal.ZonedDateTime(0n, "UTC", "iso8601");
const plainRelativeTo = new Temporal.PlainDate(2000, 1, 1, calendar);
const zonedRelativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
const d = new Temporal.Duration(0, 0, 0, 0, 23, 59, 59, 999, 999, 997); const d = new Temporal.Duration(0, 0, 0, 0, 23, 59, 59, 999, 999, 997);
@ -38,49 +35,3 @@ for (const [duration, options, descr] of noopRoundingOperations) {
assert.notSameValue(negResult, negDuration, "rounding result should be a new object (negative)"); assert.notSameValue(negResult, negDuration, "rounding result should be a new object (negative)");
TemporalHelpers.assertDurationsEqual(negResult, negDuration, `rounding should be a no-op with ${descr} (negative)`); TemporalHelpers.assertDurationsEqual(negResult, negDuration, `rounding should be a no-op with ${descr} (negative)`);
} }
// These operations are not no-op rounding operations, but still should not call
// any calendar methods:
const roundingOperationsNotCallingCalendarMethods = [
[d, { smallestUnit: "microseconds" }, "round to 1 µs"],
[d, { smallestUnit: "nanoseconds", roundingIncrement: 2 }, "round to 2 ns"],
[new Temporal.Duration(0, 0, 0, 0, 24), { largestUnit: "days" }, "upwards balancing requested"],
[d, { largestUnit: "minutes" }, "downwards balancing requested"],
[new Temporal.Duration(0, 0, 0, 0, 1, 120), { smallestUnit: "nanoseconds" }, "time units could overflow"],
[new Temporal.Duration(0, 0, 0, 1, 24), { smallestUnit: "nanoseconds" }, "hours-to-days conversion could occur"],
];
for (const [duration, options, descr] of roundingOperationsNotCallingCalendarMethods) {
const result = duration.round(options);
let equal = true;
for (const prop of ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']) {
if (result[prop] !== duration[prop]) {
equal = false;
break;
}
}
assert(!equal, `round result ${result} should be different from ${duration} with ${descr}`);
const negDuration = duration.negated();
const negResult = negDuration.round(options);
equal = true;
for (const prop of ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']) {
if (negResult[prop] !== negDuration[prop]) {
equal = false;
break;
}
}
assert(!equal, `round result ${negResult} should be different from ${negDuration} with ${descr} (negative)`);
}
// These operations should not be short-circuited because they have to call
// calendar methods:
const roundingOperationsCallingCalendarMethods = [
[new Temporal.Duration(0, 0, 1), { smallestUnit: "nanoseconds", relativeTo: plainRelativeTo }, "calendar units present"],
[d, { largestUnit: "days", relativeTo: zonedRelativeTo }, "largestUnit days with zoned relativeTo"],
[new Temporal.Duration(0, 0, 0, 1), { smallestUnit: "nanoseconds", relativeTo: zonedRelativeTo }, "hours-to-days conversion could occur with zoned relativeTo"],
];
for (const [duration, options, descr] of roundingOperationsCallingCalendarMethods) {
assert.throws(Test262Error, () => duration.round(options), `rounding should not be a no-op with ${descr}`);
assert.throws(Test262Error, () => duration.negated().round(options), `rounding should not be a no-op with ${descr} (negative)`);
}

View File

@ -4,27 +4,9 @@
/*--- /*---
esid: sec-temporal.duration.prototype.total esid: sec-temporal.duration.prototype.total
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.Duration(1); const instance = new Temporal.Duration(1);
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
@ -32,6 +14,3 @@ const instance = new Temporal.Duration(1);
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); instance.total({ unit: "months", relativeTo: { year: 2000, month: 5, day: 2, timeZone } });
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -7,13 +7,5 @@ description: Time zone annotation is ignored in input ISO string
features: [Temporal] features: [Temporal]
---*/ ---*/
const dateTimeString = "1975-02-02T14:25:36.123456789"; const instant = Temporal.Instant.from("1975-02-02T14:25:36.123456789+01:00[Invalid/TimeZone]");
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
throw new Test262Error("should not get Temporal.TimeZone.from");
},
});
const instant = Temporal.Instant.from(dateTimeString + "+01:00[Custom/TimeZone]");
assert.sameValue(instant.epochMilliseconds, 160579536123); assert.sameValue(instant.epochMilliseconds, 160579536123);

View File

@ -3,36 +3,20 @@
/*--- /*---
esid: sec-temporal.instant.prototype.tostring esid: sec-temporal.instant.prototype.tostring
includes: [compareArray.js]
description: Verify that undefined options are handled correctly. description: Verify that undefined options are handled correctly.
features: [Temporal] features: [Temporal]
---*/ ---*/
const actual = [];
const expected = [];
const instant = Temporal.Instant.from("1975-02-02T14:25:36.12345Z"); const instant = Temporal.Instant.from("1975-02-02T14:25:36.12345Z");
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
actual.push("get Temporal.TimeZone.from");
return function(identifier) {
actual.push("call Temporal.TimeZone.from");
assert.sameValue(identifier, "UTC");
};
},
});
assert.sameValue( assert.sameValue(
instant.toString(), instant.toString(),
"1975-02-02T14:25:36.12345Z", "1975-02-02T14:25:36.12345Z",
"default time zone is none, precision is auto, and rounding is trunc" "default time zone is none, precision is auto, and rounding is trunc"
); );
assert.compareArray(actual, expected);
assert.sameValue( assert.sameValue(
instant.toString(undefined), instant.toString(undefined),
"1975-02-02T14:25:36.12345Z", "1975-02-02T14:25:36.12345Z",
"default time zone is none, precision is auto, and rounding is trunc" "default time zone is none, precision is auto, and rounding is trunc"
); );
assert.compareArray(actual, expected);

View File

@ -4,27 +4,9 @@
/*--- /*---
esid: sec-temporal.instant.prototype.tostring esid: sec-temporal.instant.prototype.tostring
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.Instant(0n); const instance = new Temporal.Instant(0n);
const result1 = instance.toString({ timeZone: "UTC" }); const result1 = instance.toString({ timeZone: "UTC" });
@ -32,6 +14,3 @@ assert.sameValue(result1.substr(-6), "+00:00", "Time zone created from string 'U
const result2 = instance.toString({ timeZone: "-01:30" }); const result2 = instance.toString({ timeZone: "-01:30" });
assert.sameValue(result2.substr(-6), "-01:30", "Time zone created from string '-01:30'"); assert.sameValue(result2.substr(-6), "-01:30", "Time zone created from string '-01:30'");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -8,29 +8,9 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.Instant(0n); const instance = new Temporal.Instant(0n);
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTimeISO(timeZone); const result = instance.toZonedDateTimeISO(timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,32 +4,11 @@
/*--- /*---
esid: sec-temporal.now.plaindateiso esid: sec-temporal.now.plaindateiso
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateISO(timeZone); Temporal.Now.plainDateISO(timeZone);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,32 +4,17 @@
/*--- /*---
esid: sec-temporal.now.plaindatetimeiso esid: sec-temporal.now.plaindatetimeiso
description: Functions when time zone argument is omitted description: Functions when time zone argument is omitted
includes: [compareArray.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const actual = [];
const expected = [];
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
actual.push("get Temporal.TimeZone.from");
return undefined;
},
});
const resultExplicit = Temporal.Now.plainDateTimeISO(undefined); const resultExplicit = Temporal.Now.plainDateTimeISO(undefined);
assert( assert(
resultExplicit instanceof Temporal.PlainDateTime, resultExplicit instanceof Temporal.PlainDateTime,
'The result of evaluating (resultExplicit instanceof Temporal.PlainDateTime) is expected to be true' 'The result of evaluating (resultExplicit instanceof Temporal.PlainDateTime) is expected to be true'
); );
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');
const resultImplicit = Temporal.Now.plainDateTimeISO(); const resultImplicit = Temporal.Now.plainDateTimeISO();
assert( assert(
resultImplicit instanceof Temporal.PlainDateTime, resultImplicit instanceof Temporal.PlainDateTime,
'The result of evaluating (resultImplicit instanceof Temporal.PlainDateTime) is expected to be true' 'The result of evaluating (resultImplicit instanceof Temporal.PlainDateTime) is expected to be true'
); );
assert.compareArray(actual, expected, 'The value of actual is expected to equal the value of expected');

View File

@ -4,32 +4,11 @@
/*--- /*---
esid: sec-temporal.now.plaindatetimeiso esid: sec-temporal.now.plaindatetimeiso
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainDateTimeISO(timeZone); Temporal.Now.plainDateTimeISO(timeZone);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,32 +4,11 @@
/*--- /*---
esid: sec-temporal.now.plaintimeiso esid: sec-temporal.now.plaintimeiso
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
// The following are all valid strings so should not throw: // The following are all valid strings so should not throw:
["UTC", "+01:00"].forEach((timeZone) => { ["UTC", "+01:00"].forEach((timeZone) => {
Temporal.Now.plainTimeISO(timeZone); Temporal.Now.plainTimeISO(timeZone);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -8,24 +8,10 @@ includes: [compareArray.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const actual = [];
const expected = [];
Object.defineProperty(Temporal.TimeZone, "from", {
get() {
actual.push("get Temporal.TimeZone.from");
return undefined;
},
});
const systemTimeZone = Temporal.Now.timeZoneId(); const systemTimeZone = Temporal.Now.timeZoneId();
const resultExplicit = Temporal.Now.zonedDateTimeISO(undefined); const resultExplicit = Temporal.Now.zonedDateTimeISO(undefined);
assert.sameValue(resultExplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string"); assert.sameValue(resultExplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");
const resultImplicit = Temporal.Now.zonedDateTimeISO(); const resultImplicit = Temporal.Now.zonedDateTimeISO();
assert.sameValue(resultImplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string"); assert.sameValue(resultImplicit.getISOFields().timeZone, systemTimeZone, "time zone slot should store a string");
assert.compareArray(actual, expected, "Temporal.TimeZone.from should not be called");

View File

@ -8,27 +8,7 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.Now.zonedDateTimeISO(timeZone); const result = Temporal.Now.zonedDateTimeISO(timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -8,17 +8,6 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
Object.defineProperty(Temporal.Calendar, "from", { const plainDate = new Temporal.PlainDate(2020, 12, 24, "iso8601");
get() { TemporalHelpers.assertPlainDate(plainDate, 2020, 12, "M12", 24, "with string");
throw new Test262Error("Should not get Calendar.from"); assert.sameValue(plainDate.getISOFields().calendar, "iso8601", "calendar slot should store a string");
},
});
const calendar = new Temporal.Calendar("iso8601");
const plainDateWithObject = new Temporal.PlainDate(2020, 12, 24, calendar);
TemporalHelpers.assertPlainDate(plainDateWithObject, 2020, 12, "M12", 24, "with object");
assert.sameValue(plainDateWithObject.getISOFields().calendar, calendar);
const plainDateWithString = new Temporal.PlainDate(2020, 12, 24, "iso8601");
TemporalHelpers.assertPlainDate(plainDateWithString, 2020, 12, "M12", 24, "with string");
assert.sameValue(plainDateWithString.getISOFields().calendar, "iso8601", "calendar slot should store a string");

View File

@ -9,12 +9,6 @@ features: [Temporal]
const args = [2020, 12, 24]; const args = [2020, 12, 24];
Object.defineProperty(Temporal.Calendar, "from", {
get() {
throw new Test262Error("Should not get Calendar.from");
},
});
const dateExplicit = new Temporal.PlainDate(...args, undefined); const dateExplicit = new Temporal.PlainDate(...args, undefined);
assert.sameValue(dateExplicit.getISOFields().calendar, "iso8601", "calendar slot should store string"); assert.sameValue(dateExplicit.getISOFields().calendar, "iso8601", "calendar slot should store string");

View File

@ -4,19 +4,9 @@
/*--- /*---
esid: sec-temporal.plaindate.compare esid: sec-temporal.plaindate.compare
description: A calendar ID is valid input for Calendar description: A calendar ID is valid input for Calendar
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields");
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up");
},
});
const calendar = "iso8601"; const calendar = "iso8601";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
@ -26,5 +16,3 @@ assert.sameValue(result1, 0, `Calendar created from string "${arg}" (first argum
const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg);
assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`); assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`);
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal);

View File

@ -8,29 +8,9 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.PlainDate(2000, 5, 2); const instance = new Temporal.PlainDate(2000, 5, 2);
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime(timeZone); const result = instance.toZonedDateTime(timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -9,12 +9,6 @@ features: [Temporal]
const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789]; const dateTimeArgs = [2020, 12, 24, 12, 34, 56, 123, 456, 789];
Object.defineProperty(Temporal.Calendar, "from", {
get() {
throw new Test262Error("Should not get Calendar.from");
},
});
const dateTimeExplicit = new Temporal.PlainDateTime(...dateTimeArgs, undefined); const dateTimeExplicit = new Temporal.PlainDateTime(...dateTimeArgs, undefined);
assert.sameValue(dateTimeExplicit.calendarId, "iso8601"); assert.sameValue(dateTimeExplicit.calendarId, "iso8601");

View File

@ -4,19 +4,9 @@
/*--- /*---
esid: sec-temporal.plaindatetime.compare esid: sec-temporal.plaindatetime.compare
description: A calendar ID is valid input for Calendar description: A calendar ID is valid input for Calendar
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields");
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up");
},
});
const calendar = "iso8601"; const calendar = "iso8601";
const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
@ -26,5 +16,3 @@ assert.sameValue(result1, 0, `Calendar created from string "${arg}" (first argum
const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg);
assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`); assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`);
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal);

View File

@ -8,12 +8,10 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const calendar1 = TemporalHelpers.calendarThrowEverything(); const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601");
const calendar2 = TemporalHelpers.calendarThrowEverything(); const dt2 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, "iso8601");
const dt1 = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, calendar1); const dt3 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, "iso8601");
const dt2 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar1); const dt4 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, "gregory");
const dt3 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar1);
const dt4 = new Temporal.PlainDateTime(2019, 10, 29, 10, 46, 38, 271, 986, 102, calendar2);
assert.sameValue(Temporal.PlainDateTime.compare(dt1, dt2), -1, "smaller"); assert.sameValue(Temporal.PlainDateTime.compare(dt1, dt2), -1, "smaller");
assert.sameValue(Temporal.PlainDateTime.compare(dt2, dt3), 0, "equal with same calendar"); assert.sameValue(Temporal.PlainDateTime.compare(dt2, dt3), 0, "equal with same calendar");

View File

@ -8,29 +8,9 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.PlainDateTime(2000, 5, 2); const instance = new Temporal.PlainDateTime(2000, 5, 2);
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.toZonedDateTime(timeZone); const result = instance.toZonedDateTime(timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -9,12 +9,6 @@ features: [Temporal]
const args = [5, 2]; const args = [5, 2];
Object.defineProperty(Temporal.Calendar, "from", {
get() {
throw new Test262Error("Should not get Calendar.from");
},
});
const dateExplicit = new Temporal.PlainMonthDay(...args, undefined); const dateExplicit = new Temporal.PlainMonthDay(...args, undefined);
assert.sameValue(dateExplicit.calendarId, "iso8601"); assert.sameValue(dateExplicit.calendarId, "iso8601");

View File

@ -3,13 +3,11 @@
/*--- /*---
esid: sec-temporal.plainmonthday.prototype.toplaindate esid: sec-temporal.plainmonthday.prototype.toplaindate
description: Throws a TypeError if the argument is not an Object, before any other observable actions description: Throws a TypeError if the argument is not an Object
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
[null, undefined, true, 3.1416, "a string", Symbol("symbol"), 7n].forEach((primitive) => { [null, undefined, true, 3.1416, "a string", Symbol("symbol"), 7n].forEach((primitive) => {
const calendar = TemporalHelpers.calendarThrowEverything(); const plainMonthDay = new Temporal.PlainMonthDay(5, 2);
const plainMonthDay = new Temporal.PlainMonthDay(5, 2, calendar);
assert.throws(TypeError, () => plainMonthDay.toPlainDate(primitive)); assert.throws(TypeError, () => plainMonthDay.toPlainDate(primitive));
}); });

View File

@ -9,12 +9,6 @@ features: [Temporal]
const args = [2000, 5]; const args = [2000, 5];
Object.defineProperty(Temporal.Calendar, "from", {
get() {
throw new Test262Error("Should not get Calendar.from");
},
});
const dateExplicit = new Temporal.PlainYearMonth(...args, undefined); const dateExplicit = new Temporal.PlainYearMonth(...args, undefined);
assert.sameValue(dateExplicit.calendarId, "iso8601"); assert.sameValue(dateExplicit.calendarId, "iso8601");

View File

@ -4,19 +4,9 @@
/*--- /*---
esid: sec-temporal.plainyearmonth.compare esid: sec-temporal.plainyearmonth.compare
description: A calendar ID is valid input for Calendar description: A calendar ID is valid input for Calendar
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields");
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up");
},
});
const calendar = "iso8601"; const calendar = "iso8601";
const arg = { year: 2019, monthCode: "M06", calendar }; const arg = { year: 2019, monthCode: "M06", calendar };
@ -26,5 +16,3 @@ assert.sameValue(result1, 0, `Calendar created from string "${arg}" (first argum
const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg);
assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`); assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`);
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal);

View File

@ -3,13 +3,11 @@
/*--- /*---
esid: sec-temporal.plainyearmonth.prototype.toplaindate esid: sec-temporal.plainyearmonth.prototype.toplaindate
description: Throws a TypeError if the argument is not an Object, before any other observable actions description: Throws a TypeError if the argument is not an Object
includes: [compareArray.js, temporalHelpers.js]
features: [BigInt, Symbol, Temporal] features: [BigInt, Symbol, Temporal]
---*/ ---*/
[null, undefined, true, 3.1416, "a string", Symbol("symbol"), 7n].forEach((primitive) => { [null, undefined, true, 3.1416, "a string", Symbol("symbol"), 7n].forEach((primitive) => {
const calendar = TemporalHelpers.calendarThrowEverything(); const plainYearMonth = new Temporal.PlainYearMonth(2000, 5);
const plainYearMonth = new Temporal.PlainYearMonth(2000, 5, calendar);
assert.throws(TypeError, () => plainYearMonth.toPlainDate(primitive)); assert.throws(TypeError, () => plainYearMonth.toPlainDate(primitive));
}); });

View File

@ -7,12 +7,6 @@ description: Calendar argument defaults to the built-in ISO 8601 calendar
features: [BigInt, Temporal] features: [BigInt, Temporal]
---*/ ---*/
Object.defineProperty(Temporal.Calendar, "from", {
get() {
throw new Test262Error("Should not get Calendar.from");
},
});
const args = [957270896987654321n, "UTC"]; const args = [957270896987654321n, "UTC"];
const explicit = new Temporal.ZonedDateTime(...args, undefined); const explicit = new Temporal.ZonedDateTime(...args, undefined);

View File

@ -4,19 +4,9 @@
/*--- /*---
esid: sec-temporal.zoneddatetime.compare esid: sec-temporal.zoneddatetime.compare
description: A calendar ID is valid input for Calendar description: A calendar ID is valid input for Calendar
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields");
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("dateFromFields should not be looked up");
},
});
const calendar = "iso8601"; const calendar = "iso8601";
const timeZone = "UTC"; const timeZone = "UTC";
@ -28,5 +18,3 @@ assert.sameValue(result1, 0, `Calendar created from string "${arg}" (first argum
const result2 = Temporal.ZonedDateTime.compare(datetime, arg); const result2 = Temporal.ZonedDateTime.compare(datetime, arg);
assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`); assert.sameValue(result2, 0, `Calendar created from string "${arg}" (second argument)`);
Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal);

View File

@ -4,27 +4,9 @@
/*--- /*---
esid: sec-temporal.zoneddatetime.compare esid: sec-temporal.zoneddatetime.compare
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const epoch = new Temporal.ZonedDateTime(0n, timeZone); const epoch = new Temporal.ZonedDateTime(0n, timeZone);
@ -32,6 +14,3 @@ Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, epoch); Temporal.ZonedDateTime.compare({ year: 2020, month: 5, day: 2, timeZone }, epoch);
Temporal.ZonedDateTime.compare(epoch, { year: 2020, month: 5, day: 2, timeZone }); Temporal.ZonedDateTime.compare(epoch, { year: 2020, month: 5, day: 2, timeZone });
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -8,27 +8,7 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone }); const result = Temporal.ZonedDateTime.from({ year: 2000, month: 5, day: 2, timeZone });
assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `Time zone created from string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -4,32 +4,12 @@
/*--- /*---
esid: sec-temporal.zoneddatetime.prototype.equals esid: sec-temporal.zoneddatetime.prototype.equals
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance1 = new Temporal.ZonedDateTime(0n, "UTC"); const instance1 = new Temporal.ZonedDateTime(0n, "UTC");
assert(instance1.equals({ year: 1970, month: 1, day: 1, timeZone: "UTC" }), "Time zone created from string 'UTC'"); assert(instance1.equals({ year: 1970, month: 1, day: 1, timeZone: "UTC" }), "Time zone created from string 'UTC'");
const instance2 = new Temporal.ZonedDateTime(0n, "-01:30"); const instance2 = new Temporal.ZonedDateTime(0n, "-01:30");
assert(instance2.equals({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }), "Time zone created from string '-01:30'"); assert(instance2.equals({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }), "Time zone created from string '-01:30'");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -3,16 +3,11 @@
/*--- /*---
esid: sec-temporal.zoneddatetime.prototype.round esid: sec-temporal.zoneddatetime.prototype.round
description: > description: Circumstances where rounding is a no-op
No calendar or time zone methods are called under circumstances where rounding
is a no-op
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const calendar = TemporalHelpers.calendarThrowEverything(); const instance = new Temporal.ZonedDateTime(0n, "UTC");
const timeZone = TemporalHelpers.timeZoneThrowEverything();
const instance = new Temporal.ZonedDateTime(0n, timeZone, calendar);
const noopRoundingOperations = [ const noopRoundingOperations = [
[{ smallestUnit: "nanoseconds" }, "smallestUnit ns"], [{ smallestUnit: "nanoseconds" }, "smallestUnit ns"],
@ -23,11 +18,3 @@ for (const [options, descr] of noopRoundingOperations) {
assert.notSameValue(result, instance, "rounding result should be a new object"); assert.notSameValue(result, instance, "rounding result should be a new object");
assert.sameValue(result.epochNanoseconds, instance.epochNanoseconds, "instant should be unchanged"); assert.sameValue(result.epochNanoseconds, instance.epochNanoseconds, "instant should be unchanged");
} }
const notNoopRoundingOperations = [
[{ smallestUnit: "microseconds" }, "round to 1 µs"],
[{ smallestUnit: "nanoseconds", roundingIncrement: 2 }, "round to 2 ns"],
];
for (const [options, descr] of notNoopRoundingOperations) {
assert.throws(Test262Error, () => instance.round(options), `rounding should not be a no-op with ${descr}`);
}

View File

@ -4,32 +4,11 @@
/*--- /*---
esid: sec-temporal.zoneddatetime.prototype.until esid: sec-temporal.zoneddatetime.prototype.until
description: Time zone IDs are valid input for a time zone description: Time zone IDs are valid input for a time zone
includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance1 = new Temporal.ZonedDateTime(0n, "UTC"); const instance1 = new Temporal.ZonedDateTime(0n, "UTC");
assert(instance1.until({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'"); assert(instance1.until({ year: 1970, month: 1, day: 1, timeZone: "UTC" }).blank, "Time zone created from string 'UTC'");
const instance2 = new Temporal.ZonedDateTime(0n, "-01:30"); const instance2 = new Temporal.ZonedDateTime(0n, "-01:30");
assert(instance2.until({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'"); assert(instance2.until({ year: 1969, month: 12, day: 31, hour: 22, minute: 30, timeZone: "-01:30" }).blank, "Time zone created from string '-01:30'");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);

View File

@ -8,29 +8,9 @@ includes: [temporalHelpers.js]
features: [Temporal] features: [Temporal]
---*/ ---*/
const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up");
},
});
const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor");
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", {
configurable: true,
enumerable: false,
get() {
TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up");
},
});
const instance = new Temporal.ZonedDateTime(0n, "UTC"); const instance = new Temporal.ZonedDateTime(0n, "UTC");
["UTC", "+01:30"].forEach((timeZone) => { ["UTC", "+01:30"].forEach((timeZone) => {
const result = instance.withTimeZone(timeZone); const result = instance.withTimeZone(timeZone);
assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`); assert.sameValue(result.getISOFields().timeZone, timeZone, `time zone slot should store string "${timeZone}"`);
}); });
Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal);
Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal);