mirror of
https://github.com/ferdzo/iotDashboard.git
synced 2026-06-04 00:16:46 +00:00
30 lines
915 B
TypeScript
30 lines
915 B
TypeScript
import { type ClassValue, clsx } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
export function formatDate(date: Date | string): string {
|
|
const d = typeof date === 'string' ? new Date(date) : date
|
|
return d.toLocaleDateString() + ' ' + d.toLocaleTimeString()
|
|
}
|
|
|
|
export function formatRelativeTime(date: Date | string): string {
|
|
const d = typeof date === 'string' ? new Date(date) : date
|
|
const now = new Date()
|
|
const diff = now.getTime() - d.getTime()
|
|
|
|
const seconds = Math.floor(diff / 1000)
|
|
const minutes = Math.floor(seconds / 60)
|
|
const hours = Math.floor(minutes / 60)
|
|
const days = Math.floor(hours / 24)
|
|
|
|
if (seconds < 60) return `${seconds}s ago`
|
|
if (minutes < 60) return `${minutes}m ago`
|
|
if (hours < 24) return `${hours}h ago`
|
|
if (days < 30) return `${days}d ago`
|
|
|
|
return formatDate(d)
|
|
}
|