﻿var DateDiff = {

    inDays: function (d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2 - t1) / (24 * 3600 * 1000));
    },

    inWeeks: function (d1, d2) {
        var t2 = d2.getTime();
        var t1 = d1.getTime();

        return parseInt((t2 - t1) / (24 * 3600 * 1000 * 7));
    },

    inMonths: function (d1, d2) {
        var d1Y = d1.getFullYear();
        var d2Y = d2.getFullYear();
        var d1M = d1.getMonth();
        var d2M = d2.getMonth();

        return (d2M + 12 * d2Y) - (d1M + 12 * d1Y);
    },

    inYears: function (d1, d2) {
        return d2.getFullYear() - d1.getFullYear();
    },

    monthIsLessThan: function (d1, d2) {
        if (d1.getMonth() == d2.getMonth()) {
            return DateDiff.dayIsLessThan(d1, d2);
        }
        else {
            return d1.getMonth() < d2.getMonth()
        }
    },

    dayIsLessThan: function (d1, d2) {
        if (d1.getDate() == d2.getDate()) {
            return DateDiff.hourIsLessThan(d1, d2);
        }
        else {
            return d1.getDate() < d2.getDate()
        }
    },

    hourIsLessThan: function (d1, d2) {
        if (d1.getHours() == d2.getHours()) {
            return DateDiff.minuteIsLessThan(d1, d2);
        }
        else {
            return d1.getHours() < d2.getHours()
        }
    },

    minuteIsLessThan: function (d1, d2) {
        if (d1.getMinutes() == d2.getMinutes()) {
            return DateDiff.secondIsLessThan(d1, d2);
        }
        else {
            return d1.getMinutes() < d2.getMinutes()
        }
    },

    secondIsLessThan: function (d1, d2) {
        if (d1.getSeconds() == d2.getSeconds()) {
            return false;
        }
        else {
            return d1.getSeconds() < d2.getSeconds()
        }
    },

    dayIsGreaterThan: function (d1, d2) {
        if (d1.getDate() == d2.getDate()) {
            return DateDiff.hourIsLessThan(d1, d2);
        }
        else {
            return d1.getDate() > d2.getDate()
        }
    },

    hourIsGreaterThan: function (d1, d2) {
        if (d1.getHours() == d2.getHours()) {
            return DateDiff.minuteIsLessThan(d1, d2);
        }
        else {
            return d1.getHours() > d2.getHours()
        }
    },

    minuteIsGreaterThan: function (d1, d2) {
        if (d1.getMinutes() == d2.getMinutes()) {
            return DateDiff.secondIsLessThan(d1, d2);
        }
        else {
            return d1.getMinutes() > d2.getMinutes()
        }
    },

    secondIsGreaterThan: function (d1, d2) {
        if (d1.getSeconds() == d2.getSeconds()) {
            return false;
        }
        else {
            return d1.getSeconds() > d2.getSeconds()
        }
    }

}

function daysInMonth(month, year) {
    var dd = new Date(year, month, 0);
    return dd.getDate();
} 
            

