17 lines
488 B
TypeScript
17 lines
488 B
TypeScript
|
|
import { clsx, type ClassValue } from "clsx";
|
||
|
|
|
||
|
|
export function cn(...inputs: ClassValue[]) {
|
||
|
|
return clsx(inputs);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function calcAge(birthDate?: string): number | null {
|
||
|
|
if (!birthDate) return null;
|
||
|
|
const b = new Date(birthDate);
|
||
|
|
if (Number.isNaN(b.getTime())) return null;
|
||
|
|
const now = new Date();
|
||
|
|
let age = now.getFullYear() - b.getFullYear();
|
||
|
|
const m = now.getMonth() - b.getMonth();
|
||
|
|
if (m < 0 || (m === 0 && now.getDate() < b.getDate())) age--;
|
||
|
|
return age;
|
||
|
|
}
|