human
I wrote the below code

    attributes = dict(attr)
    calendar = attributes.pop('calendar', None)
    limits = {}
    for keyword in ('past', 'future', 'min', 'max'):
        if (keyword in attributes):
            limits[keyword] = attributes[keyword]
            del attributes[keyword]
    widget = attributes.pop('widget', None)
    now = current.request.utcnow
    if (widget == 'date'):
        def limit(delta):
            current_month = now.month
            (years, hours) = divmod((- delta), 8760)
            months = divmod(hours, 744)[0]
            if (months > current_month):
                years += 1
            month = divmod(((current_month - months) + 12), 12)[1]
            year = (now.year - years)
            return now.replace(month=month, year=year)
        earliest = limits.get('min')
        if (not earliest):
            past = limits.get('past')
            if (past is not None):
                earliest = limit((- past))
        latest = limits.get('max')
        if (not latest):
            future = limits.get('future')
            if (future is not None):
                latest = limit(future)
    else:
        earliest = limits.get('min')
        if (not earliest):
            past = limits.get('past')
            if (past is not None):
                earliest = (now - datetime.timedelta(hours=past))
        latest = limits.get('max')
        if (not latest):
            future = limits.get('future')
            if (future is not None):
                latest = (now + datetime.timedelta(hours=future))
    if ('label' not in attributes):
        attributes['label'] = current.T('Date')
    set_min = attributes.pop('set_min', None)
    set_max = attributes.pop('set_max', None)
    date_only = False
    if (widget == 'date'):
        date_only = True
        widget = S3CalendarWidget(calendar=calendar, timepicker=False, minimum=earliest, maximum=latest, set_min=set_min, set_max=set_max)
    elif ((widget is None) or (widget == 'datetime')):
        widget = S3CalendarWidget(calendar=calendar,...

What's a good function header?
 Here's a good function header?
assistant
#Here's a good function header.

def s3_datetime(name='date', **attr):