feat: add age calculator method

This commit is contained in:
Sebin Nyshkim 2020-12-27 01:11:39 +01:00
parent 3c7723c96a
commit cc601a9f46

View file

@ -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);