Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various changes to Temporal tests #3909

Merged
merged 7 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion harness/temporalHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1734,7 +1734,7 @@ var TemporalHelpers = {
}

getPossibleInstantsFor(plainDateTime) {
this.getPossibleInstantsForCalledWith.push(plainDateTime.toString());
this.getPossibleInstantsForCalledWith.push(plainDateTime.toString({ calendarName: "never" }));
const [instant] = super.getPossibleInstantsFor(plainDateTime);
if (this._shiftNanoseconds > 0) {
if (this._isBeforeShift(instant)) return [instant];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

/*---
esid: sec-temporal.duration.prototype.add
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
description: A number cannot be used in place of a relativeTo
features: [Temporal]
---*/

const instance = new Temporal.Duration(1, 0, 0, 1);

const relativeTo = 20191101;

const numbers = [
1,
-20191101,
Expand All @@ -22,6 +20,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

/*---
esid: sec-temporal.duration.prototype.add
description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar
description: A number as calendar in relativeTo property bag is invalid
features: [Temporal]
---*/

Expand All @@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"days < 0 and sign = 1"
);

// NanosecondsToDays.20: days > 0 and sign = -1
Expand All @@ -87,7 +88,8 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"days > 0 and sign = -1"
);

// NanosecondsToDays.22: nanoseconds > 0 and sign = -1
Expand Down Expand Up @@ -115,5 +117,6 @@ assert.throws(RangeError, () =>
// Adding day to day sets largestUnit to 'day', avoids having any week/month/year components in differences
dayDuration.add(dayDuration, {
relativeTo: zdt,
})
}),
"nanoseconds > 0 and sign = -1"
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

/*---
esid: sec-temporal.duration.prototype.round
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
description: A number cannot be used in place of a relativeTo
features: [Temporal]
---*/

const instance = new Temporal.Duration(1, 0, 0, 0, 24);

const relativeTo = 20191101;

const numbers = [
1,
20191101,
Expand All @@ -22,6 +20,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

/*---
esid: sec-temporal.duration.prototype.subtract
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
description: A number cannot be used in place of a relativeTo
features: [Temporal]
---*/

const instance = new Temporal.Duration(1, 0, 0, 1);

const relativeTo = 20191101;

const numbers = [
1,
20191101,
Expand All @@ -22,6 +20,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ features: [Temporal]

const instance = new Temporal.Duration(1, 0, 0, 1);

const calendar = 19970327;

const numbers = [
1,
19970327,
Expand All @@ -23,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

/*---
esid: sec-temporal.duration.prototype.total
description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate
description: A number cannot be used in place of a relativeTo
features: [Temporal]
---*/

const instance = new Temporal.Duration(1, 0, 0, 0, 24);

const relativeTo = 20191101;

const numbers = [
1,
20191101,
Expand All @@ -22,6 +20,6 @@ for (const relativeTo of numbers) {
assert.throws(
TypeError,
() => instance.total({ unit: "days", relativeTo }),
`Number ${relativeTo} does not convert to a valid ISO string for relativeTo`
`A number (${relativeTo}) is not a valid ISO string for relativeTo`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ for (const calendar of numbers) {
assert.throws(
TypeError,
() => instance.total({ unit: "days", relativeTo }),
"A number is not a valid ISO string for relativeTo.calendar"
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.toPlainDateTime(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
"A number is not a valid ISO string for PlainDateTime (first argument)"
`A number (${arg}) is not a valid ISO string for PlainDateTime (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
"A number is not a valid ISO string for PlainDateTime (second argument)"
`A number (${arg}) is not a valid ISO string for PlainDateTime (second argument)`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainDateTime.from(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.withPlainTime(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ description: A number is invalid in place of an ISO string for Temporal.PlainMon
features: [Temporal]
---*/

const arg = 1118;

const numbers = [
1,
1118,
Expand All @@ -20,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainMonthDay.from(arg),
"A number is not a valid ISO string for PlainMonthDay"
`A number (${arg}) is not a valid ISO string for PlainMonthDay`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainMonthDay"
`A number (${arg}) is not a valid ISO string for PlainMonthDay`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)),
"A number is not a valid ISO string for PlainTime (first argument)"
`A number (${arg}) is not a valid ISO string for PlainTime (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg),
"A number is not a valid ISO string for PlainTime (second argument)"
`A number (${arg}) is not a valid ISO string for PlainTime (second argument)`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainTime.from(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainTime"
`A number (${arg}) is not a valid ISO string for PlainTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
"A number is not a valid ISO string for PlainYearMonth (first argument)"
`A number (${arg}) is not a valid ISO string for PlainYearMonth (first argument)`
);
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
"A number is not a valid ISO string for PlainYearMonth (first argument)"
`A number (${arg}) is not a valid ISO string for PlainYearMonth (first argument)`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => Temporal.PlainYearMonth.from(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.equals(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.since(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.until(arg),
"A number is not a valid ISO string for PlainYearMonth"
`A number (${arg}) is not a valid ISO string for PlainYearMonth`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.getInstantFor(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ for (const arg of numbers) {
assert.throws(
TypeError,
() => instance.getPossibleInstantsFor(arg),
"A number is not a valid ISO string for PlainDateTime"
`A number (${arg}) is not a valid ISO string for PlainDateTime`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ features: [Temporal]
let str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35]";

const result = Temporal.ZonedDateTime.from(str);
assert.sameValue(result.timeZoneId, "+01:35", "Time zone determined from bracket name");
assert.sameValue(result.timeZoneId, "+01:35", "ISO offset, sub-minute offset trailing-zeroes");

str = "1970-01-01T01:35:30+01:35:00.000000000[+01:35:00.000000000]";
assert.throws(
Expand Down
Loading