Spaces:
Running
Running
axeronis commited on
Commit ·
08ac9eb
1
Parent(s): f524df8
fix: correctly parse UTC timestamps to display in user's local timezone
Browse files- frontend/lib/utils.ts +8 -1
frontend/lib/utils.ts
CHANGED
|
@@ -6,7 +6,14 @@ export function cn(...inputs: ClassValue[]) {
|
|
| 6 |
}
|
| 7 |
|
| 8 |
export function formatDate(date: string | Date): string {
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
return d.toLocaleDateString('ru-RU', {
|
| 11 |
day: '2-digit',
|
| 12 |
month: '2-digit',
|
|
|
|
| 6 |
}
|
| 7 |
|
| 8 |
export function formatDate(date: string | Date): string {
|
| 9 |
+
// Backend sends UTC times without 'Z' suffix, so JavaScript parses as local time
|
| 10 |
+
// We need to explicitly treat them as UTC
|
| 11 |
+
let dateStr = typeof date === 'string' ? date : date.toISOString()
|
| 12 |
+
// If no timezone info, assume UTC
|
| 13 |
+
if (!dateStr.endsWith('Z') && !dateStr.includes('+') && !dateStr.includes('-', 10)) {
|
| 14 |
+
dateStr = dateStr + 'Z'
|
| 15 |
+
}
|
| 16 |
+
const d = new Date(dateStr)
|
| 17 |
return d.toLocaleDateString('ru-RU', {
|
| 18 |
day: '2-digit',
|
| 19 |
month: '2-digit',
|