Is date 18+ years old? Considering that:


the passed parameters are all numbers
the passed date is a valid date


It should return:


true if the date is 18 or more years old
false otherwise




function isDate18orMoreYearsOld(day, month, year) {
    var maxBirthDate = new Date();
    maxBirthDate = new Date(maxBirthDate.setYear(maxBirthDate.getYear() - 18));
    var maxYear = maxBirthDate.getYear();
    var maxMonthOnMaxYear = maxBirthDate.getMonth() + 1;
    var maxDayOnMaxMonthOnMaxYear = maxBirthDate.getDate();
    if (year &gt; maxYear) {
        return true;
    }
    if (year == maxYear) {
        if (month &gt; maxMonthOnMaxYear) {
            return true;
        }
        if (month == maxMonthOnMaxYear) {
            if (day &gt;= maxDayOnMaxMonthOnMaxYear) {
                return true;
            }
        }
    }
    return false;
}




Despite I don't want to lose maintainability and readability, I feel it could possibly have a lesser number of conditional statements.

Is there any improvement you suggest?

Also, if you spot any cases that the function fails it's very welcome.
What about this:

function isDate18orMoreYearsOld(day, month, year) {
    return new Date(year+18, month-1, day) &lt;= new Date();
}


The month - 1 is required because JS months start at 0.