feat: use friendly event date labels
This commit is contained in:
32
tests/event-date-format.test.ts
Normal file
32
tests/event-date-format.test.ts
Normal 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:00–11: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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user