mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
31e111e4d8
Introduce a new "date" mention type alongside the existing user, document and collection mentions. Typing @ with a natural language date (e.g. "tomorrow", "next friday", "jan 2") surfaces a date suggestion, parsed via chrono-node. Dates are stored as date-only ISO strings and displayed with increasing granularity (Today / Tomorrow / January 2nd / February 3rd, 2024), recomputed dynamically so relative labels stay fresh. Clicking a date mention opens a Radix popover calendar to change it.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import {
|
|
dateToReadable,
|
|
dateToRelativeReadable,
|
|
parseISODate,
|
|
toISODate,
|
|
} from "./date";
|
|
|
|
describe("toISODate / parseISODate", () => {
|
|
it("round-trips a date through its ISO representation", () => {
|
|
const date = new Date(2024, 1, 3); // Feb 3, 2024
|
|
const iso = toISODate(date);
|
|
expect(iso).toBe("2024-02-03");
|
|
expect(parseISODate(iso)).toEqual(date);
|
|
});
|
|
|
|
it("returns null for an invalid ISO string", () => {
|
|
expect(parseISODate("not-a-date")).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("dateToReadable", () => {
|
|
it("formats an absolute, human-readable date", () => {
|
|
expect(dateToReadable("2024-02-03")).toBe("February 3rd, 2024");
|
|
});
|
|
|
|
it("returns the original string when invalid", () => {
|
|
expect(dateToReadable("nonsense")).toBe("nonsense");
|
|
});
|
|
});
|
|
|
|
describe("dateToRelativeReadable", () => {
|
|
const t = (key: string) => key;
|
|
|
|
it("returns Today for the current date", () => {
|
|
const iso = toISODate(new Date());
|
|
expect(dateToRelativeReadable(iso, t)).toBe("Today");
|
|
});
|
|
|
|
it("returns Tomorrow for the next day", () => {
|
|
const tomorrow = new Date();
|
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
expect(dateToRelativeReadable(toISODate(tomorrow), t)).toBe("Tomorrow");
|
|
});
|
|
|
|
it("returns Yesterday for the previous day", () => {
|
|
const yesterday = new Date();
|
|
yesterday.setDate(yesterday.getDate() - 1);
|
|
expect(dateToRelativeReadable(toISODate(yesterday), t)).toBe("Yesterday");
|
|
});
|
|
|
|
it("omits the year within the current year", () => {
|
|
const date = new Date();
|
|
date.setMonth(date.getMonth() === 0 ? 6 : 0); // a different month, same year
|
|
date.setDate(15);
|
|
const result = dateToRelativeReadable(toISODate(date), t);
|
|
expect(result).not.toContain(`${date.getFullYear()}`);
|
|
});
|
|
|
|
it("includes the year for a date in a different year", () => {
|
|
expect(dateToRelativeReadable("2020-02-03", t)).toBe("February 3rd, 2020");
|
|
});
|
|
});
|