feat: ✨ add age calculator method
This commit is contained in:
parent
3c7723c96a
commit
cc601a9f46
1 changed files with 19 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue