Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(history): group UTC timestamps by local date (#1272)
Henry Su269e1b3346cb
diff --git a/src/utils/dateFormatting.ts b/src/utils/dateFormatting.tsindex 1764877e1..aa80072a6 100644--- a/src/utils/dateFormatting.ts+++ b/src/utils/dateFormatting.ts@@ -1,5 +1,6 @@export function normalizeDbDate(dateStr: string): Date {- const source = dateStr.endsWith("Z") ? dateStr : `${dateStr}Z`;+ const hasExplicitZone = /(?:Z|[+-]\d{2}:?\d{2})$/i.test(dateStr);+ const source = hasExplicitZone ? dateStr : `${dateStr}Z`;return new Date(source);}@@ -17,7 +18,7 @@ export function formatUpcomingDateGroup(date: Date | string, t: (key: string) =>}export function formatDateGroup(date: Date | string, t: (key: string) => string): string {- const d = typeof date === "string" ? new Date(date) : date;+ const d = typeof date === "string" ? normalizeDbDate(date) : date;const now = new Date();const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());const yesterday = new Date(today);diff --git a/test/helpers/dateGroupFormatting.test.js b/test/helpers/dateGroupFormatting.test.jsindex 16dce1f41..a32f965c7 100644--- a/test/helpers/dateGroupFormatting.test.js+++ b/test/helpers/dateGroupFormatting.test.js@@ -27,6 +27,15 @@ test("SQLite timestamps without a zone are treated as UTC", async () => {assert.equal(alreadyUtc.toISOString(), "2024-01-15T10:30:00.000Z");});+test("database timestamps with an explicit numeric offset keep that offset", async () => {+ const { normalizeDbDate } = await load();++ assert.equal(+ normalizeDbDate("2024-01-15T10:30:00+02:00").toISOString(),+ "2024-01-15T08:30:00.000Z"+ );+});+test("history groups label today's and yesterday's dates by calendar day", async (t2) => {const { formatDateGroup } = await load();t2.mock.timers.enable({ apis: ["Date"], now: NOON_JUNE_15 });@@ -49,8 +58,24 @@ test("string dates are accepted", async (t2) => {const { formatDateGroup } = await load();t2.mock.timers.enable({ apis: ["Date"], now: NOON_JUNE_15 });- // No zone suffix: parsed as local time, same day as the mocked clock.- assert.equal(formatDateGroup("2024-06-15T08:00:00", t), "Today");+ // Serializing the local mocked time gives an explicit-zone string for any host timezone.+ assert.equal(formatDateGroup(new Date(NOON_JUNE_15).toISOString(), t), "Today");+});++test("history groups zone-less SQLite timestamps as UTC near a local day boundary", async (t2) => {+ const { formatDateGroup } = await load();+ const previousTimezone = process.env.TZ;+ process.env.TZ = "America/Los_Angeles";++ try {+ t2.mock.timers.enable({ apis: ["Date"], now: new Date("2024-06-15T01:00:00Z") });++ // 00:30 UTC is 17:30 on June 14 in Los Angeles, thirty minutes before now.+ assert.equal(formatDateGroup("2024-06-15 00:30:00", t), "Today");+ } finally {+ if (previousTimezone === undefined) delete process.env.TZ;+ else process.env.TZ = previousTimezone;+ }});test("upcoming groups label today and tomorrow by calendar day", async (t2) => {