UNPKG

@modern-kit/utils

Version:
18 lines (15 loc) 554 B
import { parseDate } from '../parseDate/index.mjs'; import '../parseDateString/index.mjs'; function getAge(birthDate) { const birthDateTime = parseDate(birthDate); const today = /* @__PURE__ */ new Date(); const age = today.getFullYear() - birthDateTime.getFullYear(); const monthDiff = today.getMonth() - birthDateTime.getMonth(); const dayDiff = today.getDate() - birthDateTime.getDate(); if (monthDiff < 0 || monthDiff === 0 && dayDiff < 0) { return age - 1; } return age; } export { getAge }; //# sourceMappingURL=index.mjs.map