﻿// Non js months used unless noted. js months are 0 based.
var DateHelper = {
    isFutureDate: function isFutureDate(month, day, year) {
        var today = new Date();

        var inputDate = new Date();
        // use js month
        inputDate.setFullYear(year, month - 1, day);

        return (inputDate > today);
    },

    isValidDate: function isValidDate(month, day, year) {
        var isValid = true;

        var daysInMonth = DateHelper.getDaysInMonth(month, year);
        if (day > daysInMonth) {
            isValid = false;
        }

        return isValid;
    },

    getDaysInMonth: function getDaysInMonth(month, year) {
        var daysInMonth = 0;
        
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                daysInMonth = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                daysInMonth = 30;
                break;
            case 2:
                daysInMonth = DateHelper.getDaysInFebruary(year);
                break;
            default:
                daysInMonth = 0;

        }

        return daysInMonth;
    },

    getDaysInFebruary: function getDaysInFebruary(year) {
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also evenly divisible by 400.
        return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
    }
}