LibJS: Implement Temporal.PlainDate.prototype.toPlainMonthDay/YearMonth

This commit is contained in:
Timothy Flynn 2024-11-22 15:17:11 -05:00 committed by Andreas Kling
commit f8b593a7df
Notes: github-actions[bot] 2024-11-23 13:47:41 +00:00
4 changed files with 76 additions and 0 deletions

View file

@ -0,0 +1,17 @@
describe("correct behavior", () => {
test("length is 0", () => {
expect(Temporal.PlainDate.prototype.toPlainMonthDay).toHaveLength(0);
});
test("basic functionality", () => {
const plainDate = new Temporal.PlainDate(2021, 7, 6);
const plainMonthDay = plainDate.toPlainMonthDay();
expect(plainMonthDay.calendar).toBe(plainDate.calendar);
expect(plainMonthDay.monthCode).toBe("M07");
expect(plainMonthDay.day).toBe(6);
const fields = plainMonthDay.toString({ calendarName: "always" });
const year = fields.split("-")[0];
expect(year).toBe("1972");
});
});

View file

@ -0,0 +1,13 @@
describe("correct behavior", () => {
test("length is 0", () => {
expect(Temporal.PlainDate.prototype.toPlainYearMonth).toHaveLength(0);
});
test("basic functionality", () => {
const plainDate = new Temporal.PlainDate(2021, 7, 6);
const plainYearMonth = plainDate.toPlainYearMonth();
expect(plainYearMonth.calendar).toBe(plainDate.calendar);
expect(plainYearMonth.year).toBe(2021);
expect(plainYearMonth.month).toBe(7);
});
});