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

LibJS: Allow string as parameter in Temporal's round() / total()

This is a normative change in the Temporal spec.

See: 1f0c586
This commit is contained in:
Linus Groh 2021-11-19 00:50:31 +00:00
parent 93ee922027
commit d0c29c9735
9 changed files with 199 additions and 89 deletions

View file

@ -21,6 +21,13 @@ describe("correct behavior", () => {
}).epochNanoseconds
).toBe(1800000000000n);
});
test("string argument is implicitly converted to options object", () => {
const instant = new Temporal.Instant(1111111111111n);
expect(
instant.round("second").equals(instant.round({ smallestUnit: "second" }))
).toBeTrue();
});
});
describe("errors", () => {

View file

@ -81,6 +81,13 @@ describe("correct behavior", () => {
expect(fifthRoundedPlainDateTime.microsecond).toBe(0);
expect(fifthRoundedPlainDateTime.nanosecond).toBe(0);
});
test("string argument is implicitly converted to options object", () => {
const plainDateTime = new Temporal.PlainDateTime(2021, 11, 3, 18, 8, 10, 100, 200, 300);
expect(
plainDateTime.round("minute").equals(plainDateTime.round({ smallestUnit: "minute" }))
).toBeTrue();
});
});
describe("errors", () => {

View file

@ -61,6 +61,13 @@ describe("correct behavior", () => {
expect(fifthRoundedPlainTime.microsecond).toBe(0);
expect(fifthRoundedPlainTime.nanosecond).toBe(0);
});
test("string argument is implicitly converted to options object", () => {
const plainTime = new Temporal.PlainTime(18, 15, 9, 100, 200, 300);
expect(
plainTime.round("minute").equals(plainTime.round({ smallestUnit: "minute" }))
).toBeTrue();
});
});
describe("errors", () => {

View file

@ -29,6 +29,16 @@ describe("correct behavior", () => {
}).epochNanoseconds
).toBe(1800000000000n);
});
test("string argument is implicitly converted to options object", () => {
const zonedDateTime = new Temporal.ZonedDateTime(
1111111111111n,
new Temporal.TimeZone("UTC")
);
expect(
zonedDateTime.round("second").equals(zonedDateTime.round({ smallestUnit: "second" }))
).toBeTrue();
});
});
describe("errors", () => {