import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } export function capFirstLetter(str: string) { let arr = str.split(""); let first = arr.shift()?.toUpperCase(); return (first || "") + arr.join(""); } export function timeAgo(date: Date) { const seconds = Math.floor((new Date().getTime() - date.getTime()) / 1000); let interval = Math.floor(seconds / 31536000); // return date.toLocaleDateString("en-US"); if (interval > 1) { const formatter = new Intl.DateTimeFormat("en-US", { year: "numeric", month: "short", day: "numeric", hour: "numeric", minute: "numeric", }); return "on " + formatter.format(date); } interval = Math.floor(seconds / 86400); // return date without years if (interval > 1) { const formatter = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", hour: "numeric", minute: "numeric", }); return "on " + formatter.format(date); } interval = Math.floor(seconds / 3600); if (interval > 1) { return interval + " hours ago"; } interval = Math.floor(seconds / 60); if (interval > 1) { return interval + " minutes ago"; } return Math.floor(seconds) + " seconds ago"; }