I am asking end user to put numerical age of the user. For example user inputs 31.
Behind the scene I convert this to the year and store it. The logic is below to convert:
(moment().subtract(age, 'years')).year();
Which returns the value 1993
Good so far. However, in the other part of the UI where i show this age as number it shows 30 rather 31. The code that converts it back is like below:
let birthYear = this.userData.profile.birthYear
let currYear = moment().year()
let currDate = moment([currYear, 1, 1])
let birthDate = moment([birthYear, 1, 1])
var diffDuration = moment.duration(currDate.diff(birthDate));
age = diffDuration.years()
I am lost why the age year becomes 30 rather 31.