2021-09-10 03:44:34 +01:00
|
|
|
|
describe("correct behavior", () => {
|
|
|
|
|
|
test("length is 1", () => {
|
|
|
|
|
|
expect(Temporal.PlainMonthDay.from).toHaveLength(1);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("PlainDate instance argument", () => {
|
|
|
|
|
|
const plainDate = new Temporal.PlainDate(2021, 7, 6);
|
|
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from(plainDate);
|
|
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("PlainMonthDay instance argument", () => {
|
|
|
|
|
|
const plainMonthDay_ = new Temporal.PlainMonthDay(7, 6);
|
|
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from(plainMonthDay_);
|
|
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("ZonedDateTime instance argument", () => {
|
|
|
|
|
|
const timeZone = new Temporal.TimeZone("UTC");
|
|
|
|
|
|
const zonedDateTime = new Temporal.ZonedDateTime(1625614921000000000n, timeZone);
|
|
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from(zonedDateTime);
|
|
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("fields object argument", () => {
|
|
|
|
|
|
const object = {
|
|
|
|
|
|
month: 7,
|
|
|
|
|
|
day: 6,
|
|
|
|
|
|
};
|
|
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from(object);
|
|
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-19 19:05:17 +00:00
|
|
|
|
test("from month day string", () => {
|
|
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from("--07-06");
|
|
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2021-11-19 20:53:07 +00:00
|
|
|
|
test("from date time string", () => {
|
2021-11-24 08:56:03 +00:00
|
|
|
|
const plainMonthDay = Temporal.PlainMonthDay.from("2021-07-06T23:42:01");
|
2021-09-10 03:44:34 +01:00
|
|
|
|
expect(plainMonthDay.monthCode).toBe("M07");
|
|
|
|
|
|
expect(plainMonthDay.day).toBe(6);
|
|
|
|
|
|
});
|
2023-02-11 01:05:28 +00:00
|
|
|
|
|
|
|
|
|
|
test("compares calendar name in month day string in lowercase", () => {
|
|
|
|
|
|
const values = [
|
|
|
|
|
|
"02-10[u-ca=iso8601]",
|
|
|
|
|
|
"02-10[u-ca=isO8601]",
|
|
|
|
|
|
"02-10[u-ca=iSo8601]",
|
|
|
|
|
|
"02-10[u-ca=iSO8601]",
|
|
|
|
|
|
"02-10[u-ca=Iso8601]",
|
|
|
|
|
|
"02-10[u-ca=IsO8601]",
|
|
|
|
|
|
"02-10[u-ca=ISo8601]",
|
|
|
|
|
|
"02-10[u-ca=ISO8601]",
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
for (const value of values) {
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from(value);
|
|
|
|
|
|
}).not.toThrowWithMessage(
|
|
|
|
|
|
RangeError,
|
|
|
|
|
|
"MM-DD string format can only be used with the iso8601 calendar"
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-09-10 03:44:34 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("errors", () => {
|
|
|
|
|
|
test("missing fields", () => {
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from({});
|
2022-06-15 00:45:31 +01:00
|
|
|
|
}).toThrowWithMessage(TypeError, "Required property day is missing or undefined");
|
2021-09-10 03:44:34 +01:00
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from({ month: 1 });
|
|
|
|
|
|
}).toThrowWithMessage(TypeError, "Required property day is missing or undefined");
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from({ day: 1 });
|
|
|
|
|
|
}).toThrowWithMessage(TypeError, "Required property month is missing or undefined");
|
|
|
|
|
|
});
|
2021-11-19 19:05:17 +00:00
|
|
|
|
|
|
|
|
|
|
test("invalid month day string", () => {
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("foo");
|
|
|
|
|
|
}).toThrowWithMessage(RangeError, "Invalid month day string 'foo'");
|
|
|
|
|
|
});
|
2021-11-24 08:56:03 +00:00
|
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
2022-02-02 14:36:55 +00:00
|
|
|
|
|
|
|
|
|
|
test("extended year must not be negative zero", () => {
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("-000000-01-01");
|
2022-03-10 18:10:11 +01:00
|
|
|
|
}).toThrowWithMessage(RangeError, "Invalid month day string '-000000-01-01'");
|
2022-03-09 22:06:19 +01:00
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("−000000-01-01"); // U+2212
|
2022-03-10 18:10:11 +01:00
|
|
|
|
}).toThrowWithMessage(RangeError, "Invalid month day string '−000000-01-01'");
|
2022-02-02 14:36:55 +00:00
|
|
|
|
});
|
2023-02-11 01:05:28 +00:00
|
|
|
|
|
|
|
|
|
|
test("can only use iso8601 calendar with month day strings", () => {
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("02-10[u-ca=iso8602]");
|
|
|
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
|
RangeError,
|
|
|
|
|
|
"MM-DD string format can only be used with the iso8601 calendar"
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("02-10[u-ca=SerenityOS]");
|
|
|
|
|
|
}).toThrowWithMessage(
|
|
|
|
|
|
RangeError,
|
|
|
|
|
|
"MM-DD string format can only be used with the iso8601 calendar"
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
test("doesn't throw non-iso8601 calendar error when using a superset format string such as DateTime", () => {
|
|
|
|
|
|
// NOTE: This will still throw, but only because "serenity" is not a recognised calendar, not because of the string format restriction.
|
|
|
|
|
|
try {
|
|
|
|
|
|
Temporal.PlainMonthDay.from("2023-02-10T22:56[u-ca=serenity]");
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
expect(e).toBeInstanceOf(RangeError);
|
|
|
|
|
|
expect(e.message).not.toBe(
|
|
|
|
|
|
"MM-DD string format can only be used with the iso8601 calendar"
|
|
|
|
|
|
);
|
|
|
|
|
|
expect(e.message).toBe("Invalid calendar identifier 'serenity'");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2021-09-10 03:44:34 +01:00
|
|
|
|
});
|