def _month_delta(date, delta):
    """
    Generate a date from another date and month offset
    Examples:
        last_month = _month_delta(datetime.today(), -1)
        next_month = _month_delta(datetime.today(), 1)

    Keyword arguments:
    date -- the date to use a datetime
    delta -- the offset as in int
    """
    m, y = (date.month + delta) % 12, date.year + (date.month + delta - 1) // 12
    if not m:
        m = 12
    d = min(
        date.day,
        [
            31,
            29 if y % 4 == 0 and not y % 400 == 0 else 28,
            31,
            30,
            31,
            30,
            31,
            31,
            30,
            31,
            30,
            31,
        ][m - 1],
    )
    return date.replace(day=d, month=m, year=y)