feat: use friendly event date labels

This commit is contained in:
2026-04-09 17:41:37 -04:00
parent 12f2fd95dc
commit e01a7ed1ad
4 changed files with 94 additions and 31 deletions

View File

@@ -0,0 +1,32 @@
import { describe, expect, test } from "bun:test";
import { addDays } from "date-fns";
import { formatEventRangeLabel, formatEventStartLabel } from "@/lib/event-date-format";
describe("event-date-format", () => {
test("formats a timed start-only event with a friendly day label", () => {
const today = new Date();
today.setHours(10, 0, 0, 0);
expect(formatEventStartLabel(today.toISOString(), false)).toContain("Today · 10:00");
});
test("formats a same-day timed range without native locale helpers", () => {
const today = new Date();
today.setHours(10, 0, 0, 0);
const end = new Date(today);
end.setHours(11, 30, 0, 0);
expect(
formatEventRangeLabel({ start: today.toISOString(), end: end.toISOString(), allDay: false }),
).toContain("10:0011:30");
});
test("formats all-day events with tomorrow labels when applicable", () => {
const tomorrow = addDays(new Date(), 1);
tomorrow.setHours(0, 0, 0, 0);
expect(
formatEventRangeLabel({ start: tomorrow.toISOString(), end: undefined, allDay: true }),
).toBe("Tomorrow");
});
});