def generate_dates(start_date, end_date, recurrence):
    """
    This function is used to generate the list of schedule times
    for the recurring commands.
    Arguments:
        start_date - datetime object denoting the first occurrence of the command
        stop_date - datetime object denoting the last time the command can be executed
        recurrence - a list of timedelta objects which specify the interval at which jobs take place
    Returns a list of datetime objects
    """
    dates = []
    date = start_date
    for td in recurrence:
        while date <= end_date:
            dates.append(date)
            if td == 'monthly':
                try:
                    date = date.replace(month=date.month + 1)
                except ValueError:
                    date = date.replace(year=date.year + 1, month=1)
            else:
                date += td
    return dates