def end_of_month(val):
    """
    Return a new datetime.datetime object with values that represent
    a end of a month.
    :param val: Date to ...
    :type val: datetime.datetime | datetime.date
    :rtype: datetime.datetime
    """
    if type(val) == date:
        val = datetime.fromordinal(val.toordinal())
    if val.month == 12:
        return start_of_month(val).replace(year=val.year + 1, month=1) \
               - timedelta(microseconds=1)
    else:
        return start_of_month(val).replace(month=val.month + 1) \
               - timedelta(microseconds=1)
Return a new datetime.datetime object with values that represent
    a end of a month.
    :param val: Date to ...
    :type val: datetime.datetime | datetime.date
    :rtype: datetime.datetime