Fix Uncaught ReferenceError: calcularEdad is not defined
This commit is contained in:
@@ -24,3 +24,16 @@ export function getNombreProfesional(user?: Usuario | null): string {
|
||||
if (nombre) return nombre;
|
||||
return 'Admin';
|
||||
}
|
||||
|
||||
export function calcularEdad(fechaNacimiento?: string): string | number {
|
||||
if (!fechaNacimiento) return '-';
|
||||
const hoy = new Date();
|
||||
const cumple = new Date(fechaNacimiento);
|
||||
if (isNaN(cumple.getTime())) return '-';
|
||||
let edad = hoy.getFullYear() - cumple.getFullYear();
|
||||
const m = hoy.getMonth() - cumple.getMonth();
|
||||
if (m < 0 || (m === 0 && hoy.getDate() < cumple.getDate())) {
|
||||
edad--;
|
||||
}
|
||||
return edad;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user