def add_months(dateobj, nb_months: int):
nb_years, nb_months = divmod(nb_months, <NUM_LIT:12>)<EOL>month = dateobj.month + nb_months<EOL>if month > <NUM_LIT:12>:<EOL><INDENT>nb_years += <NUM_LIT:1><EOL>month -= <NUM_LIT:12><EOL><DEDENT>year = dateobj.year + nb_years<EOL>lastday = monthrange(year, month)[<NUM_LIT:1>]<EOL>return dateobj.replace(year=year, month=month, day=min(lastday, dateobj.day))<EOL>
return `dateobj` + `nb_months`

    If landing date doesn't exist (e.g. february, 30th), return the last
    day of the landing month.

    >>> add_months(date(2018, 1, 1), 1)
    datetime.date(2018, 1, 1)
    >>> add_months(date(2018, 1, 1), -1)
    datetime.date(2017, 12, 1)
    >>> add_months(date(2018, 1, 1), 25)
    datetime.date(2020, 2, 1)
    >>> add_months(date(2018, 1, 1), -25)
    datetime.date(2015, 12, 1)
    >>> add_months(date(2018, 1, 31), 1)
    datetime.date(2018, 2, 28)