def human_timedelta(td):
    """Return relative time (past) in human-readable format.

    Example: "10 minutes ago"

    Args:
        td (datetime.timedelta): Time delta to convert.

    Returns:
        unicode: Human-readable time delta.
    """

    output = []
    d = {'day': td.days}
    d['hour'], rem = divmod(td.seconds, 3600)
    d['minute'], d['second'] = divmod(rem, 60)

    for unit in ('day', 'hour', 'minute', 'second'):
        i = d[unit]

        if unit == 'second' and len(output):
            # no seconds unless last update was < 1m ago
            break

        if i == 1:
            output.append('1 %s' % unit)

        elif i > 1:
            output.append('%d %ss' % (i, unit))

    output.append('ago')
    return ' '.join(output)