diff --git a/src/mixins/Helper.js b/src/mixins/Helper.js index f8a2f18..394eceb 100644 --- a/src/mixins/Helper.js +++ b/src/mixins/Helper.js @@ -12,6 +12,25 @@ export default { } }, + getAge(dateOfBirth) { + const today = new Date(); + + const thisYear = today.getFullYear(); + const thisMonth = today.getMonth(); + const thisDay = today.getDate(); + + const dobYear = dateOfBirth.getFullYear(); + const dobMonth = dateOfBirth.getMonth(); + const dobDay = dateOfBirth.getDate(); + + let age = thisYear - dobYear; + + if (thisMonth < dobMonth) age--; + if (thisMonth === dobMonth && thisDay < dobDay) age--; + + return age; + }, + toImperial(cm) { const realFeet = (cm * 0.3937) / 12; const feet = Math.floor(realFeet);