def human_time(sec):
    """Format @sec as a human-readable time string."""
    seconds = abs(int(sec))
    d, h, m = seconds // 86400, seconds % 86400 // 3600, seconds % 3600 // 60
    if d:
        if h:
            return '%ud %uh' % (d, h)
        elif m:
            return '%ud %um' % (d, m)
        return '%u day%s' % (d, '' if d == 1 else 's')
    elif h:
        return '%u:%02uh' % (h, m)
    elif m:
        return '%u:%02um' % (m, seconds % 60)
    elif isinstance(sec, float):
        return '%.2g sec' % sec
    else:
        return '%d sec' % seconds
