diff --git a/frontend/src/components/ui/DateDisplay.tsx b/frontend/src/components/ui/DateDisplay.tsx index c3343db..47602f8 100644 --- a/frontend/src/components/ui/DateDisplay.tsx +++ b/frontend/src/components/ui/DateDisplay.tsx @@ -1,3 +1,5 @@ +import { useEffect, useState } from "react"; + interface DateDisplayProps { date?: Date; className?: string; @@ -13,15 +15,30 @@ export default function DateDisplay({ year: "numeric", }); + const [now, setNow] = useState(new Date()); + + useEffect(() => { + const timer = setInterval(() => { + setNow(new Date()); + }, 1000); + + return () => clearInterval(timer); + }, []); + + const hours = now.getHours(); + const minutes = now.getMinutes(); + const seconds = now.getSeconds(); + return ( -
+
Date - {formattedDate} + {formattedDate}
+ + {hours}:{minutes}:{seconds} +
); diff --git a/frontend/src/utils/dateFormat.test.ts b/frontend/src/utils/dateFormat.test.ts new file mode 100644 index 0000000..3eedd91 --- /dev/null +++ b/frontend/src/utils/dateFormat.test.ts @@ -0,0 +1,37 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { formatRelativeDate } from "./dateFormat"; + +describe("formatRelativeDate", () => { + beforeEach(() => { + vi.useFakeTimers(); + vi.setSystemTime(new Date("2026-04-14T15:30:00Z")); + }); + + afterEach(() => { + vi.useRealTimers(); + }); + + it("should format a same-day timestamp as Today,