Skip to content

The open-source AI voice studio. Clone, dictate, create.

fix(ui): parse naive-UTC timestamps consistently in formatAbsoluteDate (#953)

jojo44ef8daba3ea
diff --git a/app/src/lib/utils/format.ts b/app/src/lib/utils/format.ts
index 6297332a..3650a966 100644
--- a/app/src/lib/utils/format.ts
+++ b/app/src/lib/utils/format.ts
@@ -25,27 +25,28 @@ function getDateLocale() {
}
}
-export function formatDate(date: string | Date): string {
- let dateObj: Date;
- if (typeof date === 'string') {
- const dateStr = date.trim();
- if (!dateStr.includes('Z') && !dateStr.match(/[+-]\d{2}:\d{2}$/)) {
- dateObj = new Date(`${dateStr}Z`);
- } else {
- dateObj = new Date(dateStr);
- }
- } else {
- dateObj = date;
+// Backend timestamps are naive UTC — append `Z` so JS doesn't parse a
+// timezone-less date-time string as local time.
+function parseServerDate(date: string | Date): Date {
+ if (typeof date !== 'string') {
+ return date;
+ }
+ const dateStr = date.trim();
+ if (!dateStr.includes('Z') && !dateStr.match(/[+-]\d{2}:\d{2}$/)) {
+ return new Date(`${dateStr}Z`);
}
+ return new Date(dateStr);
+}
- return formatDistance(dateObj, new Date(), {
+export function formatDate(date: string | Date): string {
+ return formatDistance(parseServerDate(date), new Date(), {
addSuffix: true,
locale: getDateLocale(),
}).replace(/^about /i, '');
}
export function formatAbsoluteDate(date: string | Date): string {
- const dateObj = typeof date === 'string' ? new Date(date) : date;
+ const dateObj = parseServerDate(date);
return dateObj.toLocaleString(i18n.language, {
month: 'short',
day: 'numeric',