mirror of https://github.com/tc39/test262.git
Temporal: Move ZonedDateTime property bag tests out of staging
This commit is contained in:
parent
87344d96f2
commit
a93fe76f52
|
@ -0,0 +1,11 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Temporal.ZonedDateTime.from({}) throws.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// Temporal.ZonedDateTime.from({}) throws
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({}))
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Options may be a function object.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1976-11-18T00:00:00+01:00[+01:00]"
|
||||
const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00");
|
||||
|
||||
TemporalHelpers.assertZonedDateTimesEqual( Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}, () => {
|
||||
}), expected);
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Incorrectly-spelled properties are ignored.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1976-11-18T00:00:00+01:00[+01:00]"
|
||||
const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00");
|
||||
|
||||
// can be constructed with monthCode and without month
|
||||
TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00",
|
||||
hours: 12
|
||||
}), expected);
|
|
@ -19,14 +19,17 @@ const badOffsets = [
|
|||
null, // must be a string
|
||||
true, // must be a string
|
||||
1000n, // must be a string
|
||||
{}, // must be a string
|
||||
Symbol() // must be a string
|
||||
];
|
||||
offsetOptions.forEach((offsetOption) => {
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(
|
||||
typeof(offset) === 'string' ? RangeError : TypeError,
|
||||
typeof(offset) === 'string' || (typeof offset === "object" && offset !== null) ? RangeError : TypeError,
|
||||
() => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }),
|
||||
`"${offset} is not a valid offset string (with offset option ${offsetOption})`
|
||||
typeof(offset) === 'symbol' ? "symbol is not a valid offset string"
|
||||
: `"${offset} is not a valid offset string (with offset option ${offsetOption})`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: ZonedDateTime can be constructed with monthCode or month; must agree.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// "1976-11-18T00:00:00+01:00[+01:00]"
|
||||
const expected = new Temporal.ZonedDateTime(217119600000000000n, "+01:00");
|
||||
|
||||
// can be constructed with monthCode and without month
|
||||
TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
monthCode: "M11",
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}), expected);
|
||||
|
||||
// can be constructed with month and without monthCode
|
||||
TemporalHelpers.assertZonedDateTimesEqual(Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}), expected)
|
||||
|
||||
// month and monthCode must agree
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
monthCode: "M12",
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}));
|
|
@ -11,3 +11,4 @@ const timeZone = "+01:00";
|
|||
|
||||
const properties = { year: 2021, month: 10, day: 28, offset: "-07:00", timeZone };
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(properties), "offset property not matching time zone is rejected");
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(properties, { offset: "reject" }), "offset property not matching time zone is rejected");
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Options must contain at least the required correctly-spelled properties.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// object must contain at least the required correctly-spelled properties
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
years: 1976,
|
||||
months: 11,
|
||||
days: 18,
|
||||
timeZone: "+01:00"
|
||||
}));
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Temporal.ZonedDateTime.from({}) throws.
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// Temporal.ZonedDateTime.from(required prop undefined) throws
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: undefined,
|
||||
monthCode: undefined,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
|
|
@ -25,4 +25,13 @@ const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
|||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(datetime, { disambiguation: "other string" }));
|
||||
|
||||
const propertyBag = { timeZone: "UTC", year: 2001, month: 9, day: 9, hour: 1, minute: 46, second: 40, millisecond: 987, microsecond: 654, nanosecond: 321 };
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(propertyBag, { disambiguation: "other string" }));
|
||||
[
|
||||
"",
|
||||
"EARLIER",
|
||||
"balance",
|
||||
"other string",
|
||||
3,
|
||||
null
|
||||
].forEach(disambiguation => {
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(propertyBag, { disambiguation }))
|
||||
});
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: With offset 'reject', throws if offset does not match IANA time zone
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const obj = {
|
||||
year: 2020,
|
||||
month: 3,
|
||||
day: 8,
|
||||
hour: 1,
|
||||
offset: "-04:00",
|
||||
timeZone: "UTC"
|
||||
};
|
||||
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: Overflow options.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const bad = {
|
||||
year: 2019,
|
||||
month: 1,
|
||||
day: 32,
|
||||
timeZone: "+01:00"
|
||||
};
|
||||
// "2019-01-31T00:00:00+01:00[+01:00]"
|
||||
const expected = new Temporal.ZonedDateTime(1548889200000000000n, "+01:00");
|
||||
|
||||
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(bad, { overflow: "reject" }));
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
Temporal.ZonedDateTime.from(bad),
|
||||
expected);
|
||||
TemporalHelpers.assertZonedDateTimesEqual(
|
||||
Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }),
|
||||
expected);
|
|
@ -1,142 +0,0 @@
|
|||
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal-zoneddatetime-objects
|
||||
description: property bags
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
// can be constructed with monthCode and without month
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
monthCode: "M11",
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// can be constructed with month and without monthCode
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// month and monthCode must agree
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
monthCode: "M12",
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
|
||||
// Temporal.ZonedDateTime.from({}) throws
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({}))
|
||||
|
||||
// Temporal.ZonedDateTime.from(required prop undefined) throws
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: undefined,
|
||||
monthCode: undefined,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}))
|
||||
|
||||
// options may be a function object
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00"
|
||||
}, () => {
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// object must contain at least the required correctly-spelled properties
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.from({
|
||||
years: 1976,
|
||||
months: 11,
|
||||
days: 18,
|
||||
timeZone: "+01:00"
|
||||
}));
|
||||
|
||||
// incorrectly-spelled properties are ignored
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
timeZone: "+01:00",
|
||||
hours: 12
|
||||
}) }`, "1976-11-18T00:00:00+01:00[+01:00]");
|
||||
|
||||
// does not accept non-string offset property
|
||||
[
|
||||
null,
|
||||
true,
|
||||
1000,
|
||||
1000n,
|
||||
Symbol(),
|
||||
{}
|
||||
].forEach(offset => {
|
||||
assert.throws(
|
||||
typeof offset === "string" || (typeof offset === "object" && offset !== null) || typeof offset === "function"
|
||||
? RangeError
|
||||
: TypeError,
|
||||
() => Temporal.ZonedDateTime.from({
|
||||
year: 1976,
|
||||
month: 11,
|
||||
day: 18,
|
||||
offset: offset,
|
||||
timeZone: "+10:00"
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
// overflow options
|
||||
var bad = {
|
||||
year: 2019,
|
||||
month: 1,
|
||||
day: 32,
|
||||
timeZone: "+01:00"
|
||||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(bad, { overflow: "reject" }));
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad) }`, "2019-01-31T00:00:00+01:00[+01:00]");
|
||||
assert.sameValue(`${ Temporal.ZonedDateTime.from(bad, { overflow: "constrain" }) }`, "2019-01-31T00:00:00+01:00[+01:00]");
|
||||
|
||||
// Offset options
|
||||
|
||||
// { offset: 'reject' } throws if offset does not match offset time zone
|
||||
var obj = {
|
||||
year: 2020,
|
||||
month: 3,
|
||||
day: 8,
|
||||
hour: 1,
|
||||
offset: "-04:00",
|
||||
timeZone: "-08:00"
|
||||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
||||
|
||||
// { offset: 'reject' } throws if offset does not match IANA time zone
|
||||
var obj = {
|
||||
year: 2020,
|
||||
month: 3,
|
||||
day: 8,
|
||||
hour: 1,
|
||||
offset: "-04:00",
|
||||
timeZone: "UTC"
|
||||
};
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj));
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from(obj, { offset: "reject" }));
|
||||
// throw when bad disambiguation
|
||||
[
|
||||
"",
|
||||
"EARLIER",
|
||||
"balance",
|
||||
3,
|
||||
null
|
||||
].forEach(disambiguation => {
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.from("2020-11-01T04:00[UTC]", { disambiguation }));
|
||||
});
|
Loading…
Reference in New Issue