Open schlos opened 3 years ago
db migration script - draft:
class Volunteer{ constructor(fname, lname, dob){ this.name = fname + ' ' + lname this.identificatorName = lname + ', ' + fname this.dob = dob } get getAge(){ var now = new Date(); var today = new Date(now.getYear(),now.getMonth(),now.getDate()); var yearNow = now.getYear(); var monthNow = now.getMonth(); var dateNow = now.getDate(); var dob = new Date("2 January 2010") var yearDob = dob.getYear(); var monthDob = dob.getMonth(); var dateDob = dob.getDate(); var age = {}; var ageString = ""; var yearString = ""; var monthString = ""; var dayString = ""; yearAge = yearNow - yearDob; if (monthNow >= monthDob) { var monthAge = monthNow - monthDob + 1; } else { yearAge--; var monthAge = 12 + monthNow -monthDob; } if (dateNow >= dateDob) { var dateAge = dateNow - dateDob; } else { monthAge--; var dateAge = 31 + dateNow - dateDob; if (monthAge < 0) { monthAge = 11; yearAge--; } } age = { years: yearAge, months: monthAge, days: dateAge }; if ( age.years > 1 ) { yearString = " years"; } else { yearString = " year"; } if ( age.months> 1 ) { monthString = " months"; } else { monthString = " month"; } if ( age.days > 1 ) { dayString = " days"; } else { dayString = " day"; } if ( (age.years > 0) && (age.months > 0) && (age.days > 0) ) { ageString = age.years + yearString + ", " + age.months + monthString + ", and " + age.days + dayString + " old."; } else if ( (age.years == 0) && (age.months == 0) && (age.days > 0) ) { ageString = "Only " + age.days + dayString + " old!"; } else if ( (age.years > 0) && (age.months == 0) && (age.days == 0) ) { ageString = age.years + yearString + " old. Happy Birthday!!"; } else if ( (age.years > 0) && (age.months > 0) && (age.days == 0) ) { ageString = age.years + yearString + " and " + age.months + monthString + " old."; } else if ( (age.years == 0) && (age.months > 0) && (age.days > 0) ) { ageString = age.months + monthString + " and " + age.days + dayString + " old."; } else if ( (age.years > 0) && (age.months == 0) && (age.days > 0) ) { ageString = age.years + yearString + " and " + age.days + dayString + " old."; } else if ( (age.years == 0) && (age.months > 0) && (age.days == 0) ) { ageString = age.months + monthString + " old."; } else { ageString = "Oops! Could not calculate age!"; }; return ageString; } } function testAge() { let p1 = new Volunteer("FName", "LName", 44) console.log(p1.getAge) } //alert(getAge('09/09/1989'));
db migration script - draft: