code: def add_months(datetime_like_object, n, return_date=False):
      
      a_datetime = parser.parse_datetime(datetime_like_object)
      month_from_ordinary = a_datetime.year * 12 + a_datetime.month
      month_from_ordinary += n
      year, month = divmod(month_from_ordinary, 12)
  
      # try assign year, month, day
      try:
          a_datetime = datetime(
              year, month, a_datetime.day,
              a_datetime.hour, a_datetime.minute, a_datetime.second,
              a_datetime.microsecond, tzinfo=a_datetime.tzinfo,
          )
      # 肯定是由于新的月份的日子不够, 所以肯定是月底,
      # 那么直接跳到下一个月的第一天, 再回退一天
      except ValueError:
          month_from_ordinary += 1
          year, month = divmod(month_from_ordinary, 12)
          a_datetime = datetime(
              year, month, 1,
              a_datetime.hour, a_datetime.minute, a_datetime.second,
              a_datetime.microsecond, tzinfo=a_datetime.tzinfo,
          )
          a_datetime = add_days(a_datetime, -1)
  
      if return_date:  # pragma: no cover
          return a_datetime.date()
      else:
          return a_datetime
docs: Returns a time that n months after a time.
  
      Notice: for example, the date that one month after 2015-01-31 supposed
      to be 2015-02-31. But there's no 31th in Feb, so we fix that value to
      2015-02-28.
  
      :param datetimestr: a datetime object or a datetime str
      :param n: number of months, value can be negative
      :param return_date: returns a date object instead of datetime
  
      **中文文档**
  
      返回给定日期N月之后的时间。