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

LibJS: Avoid calling ToString on calendar when calendarName is "never"

This is a normative change in the Temporal spec.

See:
- 6122f4e
- cf586bc
This commit is contained in:
Luke Wilde 2022-08-08 14:48:48 +01:00 committed by Linus Groh
parent 0d7b634313
commit 54bb6bf2c0
8 changed files with 115 additions and 33 deletions

View file

@ -36,6 +36,23 @@ describe("correct behavior", () => {
plainDate = new Temporal.PlainDate(-12345, 1, 1);
expect(plainDate.toString()).toBe("-012345-01-01");
});
test("doesn't call ToString on calendar if calenderName option is 'never'", () => {
let calledToString = false;
const calendar = {
toString() {
calledToString = true;
return "nocall";
},
};
const plainDate = new Temporal.PlainDate(2022, 8, 8, calendar);
const options = {
calendarName: "never",
};
expect(plainDate.toString(options)).toBe("2022-08-08");
expect(calledToString).toBeFalse();
});
});
describe("errors", () => {

View file

@ -52,6 +52,34 @@ describe("correct behavior", () => {
expect(plainDateTime.toString(pluralOptions)).toBe(expected);
}
});
test("doesn't call ToString on calendar if calenderName option is 'never'", () => {
let calledToString = false;
const calendar = {
toString() {
calledToString = true;
return "nocall";
},
};
const plainDateTime = new Temporal.PlainDateTime(
2022,
8,
8,
14,
38,
40,
100,
200,
300,
calendar
);
const options = {
calendarName: "never",
};
expect(plainDateTime.toString(options)).toBe("2022-08-08T14:38:40.1002003");
expect(calledToString).toBeFalse();
});
});
describe("errors", () => {

View file

@ -94,6 +94,37 @@ describe("correct behavior", () => {
expect(zonedDateTime.toString(options)).toBe(expected);
}
});
test("doesn't call ToString on calendar if calenderName option is 'never'", () => {
let calledToString = false;
const calendar = {
toString() {
calledToString = true;
return "nocall";
},
};
const plainDateTime = new Temporal.PlainDateTime(
2022,
8,
8,
14,
38,
40,
100,
200,
300,
calendar
);
const timeZone = new Temporal.TimeZone("UTC");
const zonedDateTime = plainDateTime.toZonedDateTime(timeZone);
const options = {
calendarName: "never",
};
expect(zonedDateTime.toString(options)).toBe("2022-08-08T14:38:40.1002003+00:00[UTC]");
expect(calledToString).toBeFalse();
});
});
describe("errors", () => {