1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:57:35 +00:00

LibJS: Don't accept UTC designators in strings for plain Temporal types

This is a normative change in the Temporal spec.

See: cd2dc7d
This commit is contained in:
Linus Groh 2021-11-24 08:56:03 +00:00
parent 836ce8ee5d
commit 78724fdd33
6 changed files with 87 additions and 16 deletions

View file

@ -96,7 +96,7 @@ describe("correct behavior", () => {
});
test("PlainDateTime string argument", () => {
const plainDateTime = Temporal.PlainDateTime.from("2021-07-06T23:42:01Z");
const plainDateTime = Temporal.PlainDateTime.from("2021-07-06T23:42:01");
expect(plainDateTime.year).toBe(2021);
expect(plainDateTime.month).toBe(7);
expect(plainDateTime.day).toBe(6);
@ -177,4 +177,13 @@ describe("errors", () => {
Temporal.PlainDateTime.from(zonedDateTime);
}).toThrowWithMessage(TypeError, "null is not a function");
});
test("string must not contain a UTC designator", () => {
expect(() => {
Temporal.PlainDateTime.from("2021-07-06T23:42:01Z");
}).toThrowWithMessage(
RangeError,
"Invalid date time string '2021-07-06T23:42:01Z': must not contain a UTC designator"
);
});
});

View file

@ -42,7 +42,7 @@ describe("correct behavior", () => {
});
test("from date time string", () => {
const plainMonthDay = Temporal.PlainMonthDay.from("2021-07-06T23:42:01Z");
const plainMonthDay = Temporal.PlainMonthDay.from("2021-07-06T23:42:01");
expect(plainMonthDay.monthCode).toBe("M07");
expect(plainMonthDay.day).toBe(6);
});
@ -66,4 +66,13 @@ describe("errors", () => {
Temporal.PlainMonthDay.from("foo");
}).toThrowWithMessage(RangeError, "Invalid month day string 'foo'");
});
test("string must not contain a UTC designator", () => {
expect(() => {
Temporal.PlainMonthDay.from("2021-07-06T23:42:01Z");
}).toThrowWithMessage(
RangeError,
"Invalid month day string '2021-07-06T23:42:01Z': must not contain a UTC designator"
);
});
});

View file

@ -38,7 +38,7 @@ describe("correct behavior", () => {
});
test("PlainTime string argument", () => {
const createdPlainTime = Temporal.PlainTime.from("2021-08-27T18:44:11Z");
const createdPlainTime = Temporal.PlainTime.from("2021-08-27T18:44:11");
expect(createdPlainTime.hour).toBe(18);
expect(createdPlainTime.minute).toBe(44);
expect(createdPlainTime.second).toBe(11);
@ -55,4 +55,13 @@ describe("errors", () => {
Temporal.PlainTime.from(zonedDateTime);
}).toThrowWithMessage(TypeError, "null is not a function");
});
test("string must not contain a UTC designator", () => {
expect(() => {
Temporal.PlainTime.from("2021-07-06T23:42:01Z");
}).toThrowWithMessage(
RangeError,
"Invalid time string '2021-07-06T23:42:01Z': must not contain a UTC designator"
);
});
});

View file

@ -63,7 +63,7 @@ describe("correct behavior", () => {
});
test("from date time string", () => {
const plainYearMonth = Temporal.PlainYearMonth.from("2021-07-06T23:42:01Z");
const plainYearMonth = Temporal.PlainYearMonth.from("2021-07-06T23:42:01");
expect(plainYearMonth.year).toBe(2021);
expect(plainYearMonth.month).toBe(7);
expect(plainYearMonth.monthCode).toBe("M07");
@ -92,4 +92,13 @@ describe("errors", () => {
Temporal.PlainYearMonth.from("foo");
}).toThrowWithMessage(RangeError, "Invalid year month string 'foo'");
});
test("string must not contain a UTC designator", () => {
expect(() => {
Temporal.PlainYearMonth.from("2021-07-06T23:42:01Z");
}).toThrowWithMessage(
RangeError,
"Invalid year month string '2021-07-06T23:42:01Z': must not contain a UTC designator"
);
});
});