examples/requirejs/scripts/nools.js
function (/*Date*/date, /*String*/interval, /*int*/amount) {
                var res = addTransform(interval, date, amount || 0);
                amount = res[0];
                var property = res[1];
                var sum = new Date(+date);
                var fixOvershoot = res[2];
                if (property) {
                    sum["set" + property](sum["get" + property]() + amount);
                }

                if (fixOvershoot && (sum.getDate() < date.getDate())) {
                    sum.setDate(0);
                }

                return sum; // Date
            }
function (/*Date*/date, /*String*/interval, /*int*/amount) {
                var res = addTransform(interval, date, amount || 0);
                amount = res[0];
                var property = res[1];
                var sum = new Date(+date);
                var fixOvershoot = res[2];
                if (property) {
                    sum["set" + property](sum["get" + property]() + amount);
                }

                if (fixOvershoot && (sum.getDate() < date.getDate())) {
                    sum.setDate(0);
                }

                return sum; // Date
            }
function ( /*Date*/ date , /*String*/ interval , /*int*/ amount ) { var res = addTransform ( interval , date , amount || 0 ) ; amount = res [ 0 ] ; var property = res [ 1 ] ; var sum = new Date ( + date ) ; var fixOvershoot = res [ 2 ] ; if ( property ) { sum [ "set" + property ] ( sum [ "get" + property ] ( ) + amount ) ; } if ( fixOvershoot && ( sum . getDate ( ) < date . getDate ( ) ) ) { sum . setDate ( 0 ) ; } return sum ; // Date }
Adds a specified interval and amount to a date

@example
var dtA = new Date(2005, 11, 27);
dateExtender.add(dtA, "year", 1); //new Date(2006, 11, 27);
dateExtender.add(dtA, "years", 1); //new Date(2006, 11, 27);

dtA = new Date(2000, 0, 1);
dateExtender.add(dtA, "quarter", 1); //new Date(2000, 3, 1);
dateExtender.add(dtA, "quarters", 1); //new Date(2000, 3, 1);

dtA = new Date(2000, 0, 1);
dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 1);
dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 1);

dtA = new Date(2000, 0, 31);
dateExtender.add(dtA, "month", 1); //new Date(2000, 1, 29);
dateExtender.add(dtA, "months", 1); //new Date(2000, 1, 29);

dtA = new Date(2000, 0, 1);
dateExtender.add(dtA, "week", 1); //new Date(2000, 0, 8);
dateExtender.add(dtA, "weeks", 1); //new Date(2000, 0, 8);

dtA = new Date(2000, 0, 1);
dateExtender.add(dtA, "day", 1); //new Date(2000, 0, 2);

dtA = new Date(2000, 0, 1);
dateExtender.add(dtA, "weekday", 1); //new Date(2000, 0, 3);

dtA = new Date(2000, 0, 1, 11);
dateExtender.add(dtA, "hour", 1); //new Date(2000, 0, 1, 12);

dtA = new Date(2000, 11, 31, 23, 59);
dateExtender.add(dtA, "minute", 1); //new Date(2001, 0, 1, 0, 0);

dtA = new Date(2000, 11, 31, 23, 59, 59);
dateExtender.add(dtA, "second", 1); //new Date(2001, 0, 1, 0, 0, 0);

dtA = new Date(2000, 11, 31, 23, 59, 59, 999);
dateExtender.add(dtA, "millisecond", 1); //new Date(2001, 0, 1, 0, 0, 0, 0);

@param {Date} date
@param {String} interval the interval to add
<ul>
<li>day | days</li>
<li>weekday | weekdays</li>
<li>year | years</li>
<li>week | weeks</li>
<li>quarter | quarters</li>
<li>months | months</li>
<li>hour | hours</li>
<li>minute | minutes</li>
<li>second | seconds</li>
<li>millisecond | milliseconds</li>
</ul>
@param {Number} [amount=0] the amount to add
Adds a specified interval and amount to a date