Add ``months`` months to ``date``.

        Unfortunately we can't use timedeltas to add months because timedelta counts in days
        and there's no foolproof way to add N months in days without counting the number of
        days per month.
772432
def _add_months(self, date, months):
        
        year = date.year + (date.month + months - 1) // 12
        month = (date.month + months - 1) % 12 + 1
        return datetime.date(year=year, month=month, day=1)
1143785
def _adjust_n_months(other_day, n, reference_day):
    
    if n > 0 and other_day < reference_day:
        n = n - 1
    elif n <= 0 and other_day > reference_day:
        n = n + 1
    return n
1036313
function incrementDays(date, numberOfDays) {
      return new Date(date.getFullYear(), date.getMonth(), date.getDate() + numberOfDays);
    }
326834
function SimpleDate(){
    this._monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    this._monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

    var tempDate = new Date();
    this.setYear(tempDate.getFullYear());
    this.setMonth(tempDate.getMonth());
    this.setDate(tempDate.getDate());

    if(arguments[0] != null) {
        if (arguments[0] instanceof Date) {
            tempDate = arguments[0];

            this.setYear(tempDate.getFullYear());
            this.setMonth(tempDate.getMonth());
            this.setDate(tempDate.getDate());
        } else if(arguments[0] instanceof SimpleDate) {
            this.setYear(arguments[0].getYear());
            this.setMonth(arguments[0].getMonth());
            this.setDate(arguments[0].getDate());
        } else if(arguments[0] instanceof Object) {
            var obj = arguments[0];
            if(obj.year != null && obj.month != null && obj.date != null) {
                this.setYear(obj.year);
                this.setMonth(obj.month);
                this.setDate(obj.date);
            } else {
                this.setYear(tempDate.getFullYear());
                this.setMonth(tempDate.getMonth());
                this.setDate(tempDate.getDate());
            }
        }else {
            try {
                this.setYear(parseInt(arguments[0]));
                this.setMonth(parseInt(arguments[1]));
                this.setDate(parseInt(arguments[2]));
            }catch(e) {
                this.setYear(tempDate.getFullYear());
                this.setMonth(tempDate.getMonth());
                this.setDate(tempDate.getDate());
            }
        }
    }
}
899141
def *(other)
      case other
      when Integer
        Duration.new(
          seconds: @seconds * other,
          months: @months * other
        )
      else
        raise ArgumentError, "Cannot multiply Duration #{self} by #{other.inspect}"
      end
    end
685662
function getWhatMonth (date, month, day) {
  var monthOffset = month && !isNaN(month) ? month : 0
  date = toStringDate(date)
  if (baseExports.isDate(date)) {
    if (day || !isNaN(day)) {
      if (day === STRING_FIRST) {
        return new Date(_dateFullYear(date), _dateMonth(date) + monthOffset, 1)
      } else if (day === STRING_LAST) {
        return new Date(getDateTime(getWhatMonth(date, monthOffset + 1, STRING_FIRST)) - 1)
      } else {
        date.setDate(day)
      }
    }
    if (monthOffset) {
      date.setMonth(_dateMonth(date) + monthOffset)
    }
  }
  return date
}
1322041
function(year, month, date) {

    // change value from to zero-based
    date--;
    year--;

    // combine year and month to get the actual year and month
    // this allows user to set a negative month number
    var months = year2months(year) + month;
    year = months2year(months);
    month = months - year2months(year);
    months -= month;

    var days = getNewYearInDays(months);

    var leap = isLeap(year);
    var nextYear = getNextYearInDays(months, leap);
    var mode = getYearMode(days, nextYear, leap);

    days += Math.ceil(month * 29.5);
    if(month > 1 && mode == 1 || month > 2) days += mode;
    if(month > 5) days += leap;

    days += date;

    return days - DISTANCE;
  }
1186226
def end_of_month(self) -> datetime:
        
        # Increase month by 1,
        result = self.value + relativedelta(months=1)
        # take the 1st day of the (next) month,
        result = result.replace(day=1)
        # subtract one day
        result = result - relativedelta(days=1)
        self.value = result
        return self.value
395826
def months_ago(date, nb_months=1):
    
    nb_years = nb_months // 12
    nb_months = nb_months % 12

    month_diff = date.month - nb_months

    if month_diff > 0:
        new_month = month_diff
    else:
        new_month = 12 + month_diff
        nb_years += 1

    return date.replace(day=1, month=new_month, year=date.year - nb_years)
1206316
public long add(long instant, long months) {
        int i_months = (int)months;
        if (i_months == months) {
            return add(instant, i_months);
        }

        // Copied from add(long, int) and modified slightly:

        long timePart = iChronology.getMillisOfDay(instant);

        int thisYear = iChronology.getYear(instant);
        int thisMonth = iChronology.getMonthOfYear(instant, thisYear);

        long yearToUse;
        long monthToUse = thisMonth - 1 + months;
        if (monthToUse >= 0) {
            yearToUse = thisYear + (monthToUse / iMax);
            monthToUse = (monthToUse % iMax) + 1;
        } else {
            yearToUse = thisYear + (monthToUse / iMax) - 1;
            monthToUse = Math.abs(monthToUse);
            int remMonthToUse = (int)(monthToUse % iMax);
            if (remMonthToUse == 0) {
                remMonthToUse = iMax;
            }
            monthToUse = iMax - remMonthToUse + 1;
            if (monthToUse == 1) {
                yearToUse += 1;
            }
        }

        if (yearToUse < iChronology.getMinYear() ||
            yearToUse > iChronology.getMaxYear()) {

            throw new IllegalArgumentException
                ("Magnitude of add amount is too large: " + months);
        }

        int i_yearToUse = (int)yearToUse;
        int i_monthToUse = (int)monthToUse;

        int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
        int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
        if (dayToUse > maxDay) {
            dayToUse = maxDay;
        }

        long datePart =
            iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
        return datePart + timePart;
    }
621042
def days_in_month(month = self.month, year = self.year)
      (month == 12 && kabisa?(year) || month.odd?) ? 30 : 29
    end
1177845
def _ndays(self, start_date, ndays):
        
        if not getattr(self.args, 'start-date') and not self.config.get('start-date', None):
            raise Exception('start-date must be provided when ndays is used.')

        d = date(*map(int, start_date.split('-')))
        d += timedelta(days=ndays)

        return d.strftime('%Y-%m-%d')
1246011
def get_month_list(to_date, from_date):
    

    num_months = get_months_apart(to_date, from_date)
    month_offset = from_date.month
    month_list = []
    for month in range(month_offset-1, month_offset+num_months):
        year = from_date.year+(month/12)
        real_month = (month % 12) + 1
        month_list.append((year, real_month))

    return month_list
1024434
def edate(ctx, date, months):
    
    return conversions.to_date_or_datetime(date, ctx) + relativedelta(months=conversions.to_integer(months, ctx))
984909
function addTerm (date, value) {
  if ('d' in value || 'h' in value || 'i' in value ||
      's' in value || 'ms' in value) {
    return new Date(
      date.getFullYear()     + (value.y  || 0),
      date.getMonth()        + (value.m  || 0),
      date.getDate()         + (value.d  || 0),
      date.getHours()        + (value.h  || 0),
      date.getMinutes()      + (value.i  || 0),
      date.getSeconds()      + (value.s  || 0),
      date.getMilliseconds() + (value.ms || 0)
    );
  } else if ('y' in value || 'm' in value) {
    var y = date.getFullYear() + (value.y  || 0);
    var m = date.getMonth() + (value.m  || 0);
    var d = Math.min(new Date(y, m + 1, 0).getDate(), date.getDate());
    return new Date(
      y,
      m,
      d,
      date.getHours(),
      date.getMinutes(),
      date.getSeconds(),
      date.getMilliseconds()
    );
  } else {
    return date;
  }
}
190918
def subtract_months(self, months: int) -> datetime:
        
        self.value = self.value - relativedelta(months=months)
        return self.value
328707
def add_datepart(df:DataFrame, field_name:str, prefix:str=None, drop:bool=True, time:bool=False):
    ""
    make_date(df, field_name)
    field = df[field_name]
    prefix = ifnone(prefix, re.sub('[Dd]ate$', '', field_name))
    attr = ['Year', 'Month', 'Week', 'Day', 'Dayofweek', 'Dayofyear', 'Is_month_end', 'Is_month_start', 
            'Is_quarter_end', 'Is_quarter_start', 'Is_year_end', 'Is_year_start']
    if time: attr = attr + ['Hour', 'Minute', 'Second']
    for n in attr: df[prefix + n] = getattr(field.dt, n.lower())
    df[prefix + 'Elapsed'] = field.astype(np.int64) // 10 ** 9
    if drop: df.drop(field_name, axis=1, inplace=True)
    return df