- Introduced "Minhas Intenções" tab visible only to logged-in users. - Integrated MyPurchaseIntentionsPanel and useMyPurchaseIntentions hook. - Added tab badge showing count of pending intentions. - Extended session API to include user’s main character for downstream features.
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import { clsx, type ClassValue } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
/**
|
|
* Formata uma data para string relativa (ex: "há 2 horas")
|
|
*/
|
|
export function formatTimeAgo(date: Date | string): string {
|
|
const dateObj = typeof date === "string" ? new Date(date) : date;
|
|
const seconds = Math.floor((new Date().getTime() - dateObj.getTime()) / 1000);
|
|
if (seconds < 60) return "há alguns segundos";
|
|
const minutes = Math.floor(seconds / 60);
|
|
if (minutes < 60) return `há ${minutes} ${minutes === 1 ? "minuto" : "minutos"}`;
|
|
const hours = Math.floor(minutes / 60);
|
|
if (hours < 24) return `há ${hours} ${hours === 1 ? "hora" : "horas"}`;
|
|
const days = Math.floor(hours / 24);
|
|
if (days < 30) return `há ${days} ${days === 1 ? "dia" : "dias"}`;
|
|
const months = Math.floor(days / 30);
|
|
if (months < 12) return `há ${months} ${months === 1 ? "mês" : "meses"}`;
|
|
const years = Math.floor(months / 12);
|
|
return `há ${years} ${years === 1 ? "ano" : "anos"}`;
|
|
} |