def TimeDelta(delta, separator=' '):
    """Format a datetime.timedelta into a human-readable string.

  Args:
    delta: The datetime.timedelta to format.
    separator: A string separator between days, hours, minutes and seconds.

  Returns:
    Formatted string like '5d 12h 30m 45s'.
  """
    parts = []
    seconds = delta.seconds
    if delta.days:
        parts.append('%dd' % delta.days)
    if seconds >= 3600:
        parts.append('%dh' % (seconds // 3600))
        seconds %= 3600
    if seconds >= 60:
        parts.append('%dm' % (seconds // 60))
        seconds %= 60
    seconds += delta.microseconds / 1000000.0
    if seconds or not parts:
        parts.append('%gs' % seconds)
    return separator.join(parts)
