Skip to content

Commit

Permalink
fix: fix toRelativeCalendar tests depending on current time
Browse files Browse the repository at this point in the history
Fixes #1677
  • Loading branch information
diesieben07 committed Jan 26, 2025
1 parent 0d267fa commit 42a4699
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions test/datetime/relative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,32 @@ test("DateTime#toRelativeCalendar uses the calendar", () => {
expect(end.toRelativeCalendar({ base })).toBe("tomorrow");
});

test("DateTime#toRelativeCalendar picks the correct unit with no options", () => {
const now = DateTime.now();
const isLastDayOfMonth = now.endOf("month").day === now.day;
expect(now.plus({ days: 1 }).toRelativeCalendar()).toBe(
isLastDayOfMonth ? "next month" : "tomorrow"
);
});
Helpers.withNow(
"DateTime#toRelativeCalendar picks the correct unit with no options",
DateTime.fromObject({ year: 1983, month: 10, day: 14 }),
() => {
const now = DateTime.now();
expect(now.plus({ days: 1 }).toRelativeCalendar()).toBe("tomorrow");
}
);

Helpers.withNow(
"DateTime#toRelativeCalendar picks the correct unit with no options at last day of month",
DateTime.fromObject({ year: 1983, month: 10, day: 31 }),
() => {
const now = DateTime.now();
expect(now.plus({ days: 1 }).toRelativeCalendar()).toBe("next month");
}
);

Helpers.withNow(
"DateTime#toRelativeCalendar picks the correct unit with no options at least day of year",
DateTime.fromObject({ year: 1983, month: 12, day: 31 }),
() => {
const now = DateTime.now();
expect(now.plus({ days: 1 }).toRelativeCalendar()).toBe("next year");
}
);

test("DateTime#toRelativeCalendar returns null when used on an invalid date", () => {
expect(DateTime.invalid("not valid").toRelativeCalendar()).toBe(null);
Expand Down

0 comments on commit 42a4699

Please sign in to comment.