1.6.0
$ npm install -g cordova
$ git clone https://github.com/codemons/age-calculator-cordova.git age-calculator
$ cd age-calculator
$ cordova platform add [android/ios/windows]
$ cordova build
var getAge = (function(){
function difference(d1, d2) {
var m = moment(d1);
var years = m.diff(d2, 'years');
m.add(-years, 'years');
var months = m.diff(d2, 'months');
m.add(-months, 'months');
var days = m.diff(d2, 'days');
return {years: years, months: months, days: days,
toString: function(){
var age= [];
if(this.years > 0) age.push(this.years+ ' year'+(this.years> 1? 's ':' '));
if(this.months > 0) age.push(months+ ' month'+(this.months> 1? 's':''));
if(this.days > 0) age.push(this.days+ ' day'+(this.days> 1? 's':''));
if(age.length > 1)
age.splice(age.length-1,0,' and ');
return age.join('');
}
};
}
return function(dob){
return difference(new Date(), dob);
};
}());