Spaces:
Running

axeronis
fix: correctly parse UTC timestamps to display in user's local timezone
08ac9eb
Raw History Blame Contribute Delete
1.14 kB
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
export function formatDate(date: string | Date): string {
// Backend sends UTC times without 'Z' suffix, so JavaScript parses as local time
// We need to explicitly treat them as UTC
let dateStr = typeof date === 'string' ? date : date.toISOString()
// If no timezone info, assume UTC
if (!dateStr.endsWith('Z') && !dateStr.includes('+') && !dateStr.includes('-', 10)) {
dateStr = dateStr + 'Z'
}
const d = new Date(dateStr)
return d.toLocaleDateString('ru-RU', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
})
}
export function getHeatColor(score: number): string {
if (score >= 70) return 'bg-red-500'
if (score >= 50) return 'bg-orange-500'
if (score >= 30) return 'bg-yellow-500'
return 'bg-gray-400'
}
export function getHeatLabel(score: number): string {
if (score >= 70) return 'HOT'
if (score >= 50) return 'WARM'
if (score >= 30) return 'COLD'
return 'JUNK'
}