public/javascripts/yui/calendar/calendar.js
function(date, field, amount) {
        var d = new Date(date.getTime());
        switch (field) {
            case this.MONTH:
                var newMonth = date.getMonth() + amount;
                var years = 0;

                if (newMonth < 0) {
                    while (newMonth < 0) {
                        newMonth += 12;
                        years -= 1;
                    }
                } else if (newMonth > 11) {
                    while (newMonth > 11) {
                        newMonth -= 12;
                        years += 1;
                    }
                }

                d.setMonth(newMonth);
                d.setFullYear(date.getFullYear() + years);
                break;
            case this.DAY:
                this._addDays(d, amount);
                // d.setDate(date.getDate() + amount);
                break;
            case this.YEAR:
                d.setFullYear(date.getFullYear() + amount);
                break;
            case this.WEEK:
                this._addDays(d, (amount * 7));
                // d.setDate(date.getDate() + (amount * 7));
                break;
        }
        return d;
    }
function(date, field, amount) {
        var d = new Date(date.getTime());
        switch (field) {
            case this.MONTH:
                var newMonth = date.getMonth() + amount;
                var years = 0;

                if (newMonth < 0) {
                    while (newMonth < 0) {
                        newMonth += 12;
                        years -= 1;
                    }
                } else if (newMonth > 11) {
                    while (newMonth > 11) {
                        newMonth -= 12;
                        years += 1;
                    }
                }

                d.setMonth(newMonth);
                d.setFullYear(date.getFullYear() + years);
                break;
            case this.DAY:
                this._addDays(d, amount);
                // d.setDate(date.getDate() + amount);
                break;
            case this.YEAR:
                d.setFullYear(date.getFullYear() + amount);
                break;
            case this.WEEK:
                this._addDays(d, (amount * 7));
                // d.setDate(date.getDate() + (amount * 7));
                break;
        }
        return d;
    }
function ( date , field , amount ) { var d = new Date ( date . getTime ( ) ) ; switch ( field ) { case this . MONTH : var newMonth = date . getMonth ( ) + amount ; var years = 0 ; if ( newMonth < 0 ) { while ( newMonth < 0 ) { newMonth += 12 ; years -= 1 ; } } else if ( newMonth > 11 ) { while ( newMonth > 11 ) { newMonth -= 12 ; years += 1 ; } } d . setMonth ( newMonth ) ; d . setFullYear ( date . getFullYear ( ) + years ) ; break ; case this . DAY : this . _addDays ( d , amount ) ; // d.setDate(date.getDate() + amount); break ; case this . YEAR : d . setFullYear ( date . getFullYear ( ) + amount ) ; break ; case this . WEEK : this . _addDays ( d , ( amount * 7 ) ) ; // d.setDate(date.getDate() + (amount * 7)); break ; } return d ; }
Adds the specified amount of time to the this instance.
@method add
@param {Date} date The JavaScript Date object to perform addition on
@param {String} field The field constant to be used for performing addition.
@param {Number} amount The number of units (measured in the field constant) to add to the date.
@return {Date} The resulting Date object
Adds the specified amount of time to the this instance .