UNPKG

@modern-kit/utils

Version:
20 lines (16 loc) 594 B
'use strict'; var dateParseDate = require('../parseDate/index.cjs'); require('../parseDateString/index.cjs'); function getAge(birthDate) { const birthDateTime = dateParseDate.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; } exports.getAge = getAge; //# sourceMappingURL=index.cjs.map