// * Packages import useI18nStore, { Timezone } from "@/store/i18n-store"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; /** * Merge classes. * @param inputs ClassValue[] * @returns string */ export function cn(...inputs: ClassValue[]): string { return twMerge(clsx(inputs)); } /** * Get the formated date. * * @param string date * @param string timezone * @param boolean time * @returns string */ export function formatDate( date?: string | Date | null, timezone?: Timezone, time: boolean = true, ): string { if (!date) return ""; const parsed = typeof date === "string" ? new Date(date) : date; if (Number.isNaN(parsed.getTime())) { return typeof date === "string" ? date : ""; } const currentTimezone = timezone ?? useI18nStore.getState().timezone; const options: Intl.DateTimeFormatOptions = { day: "2-digit", month: "long", year: "numeric", }; if (time) { options.minute = "2-digit"; options.hour = "2-digit"; } return parsed.toLocaleDateString(currentTimezone, options); }