def FormatTimedelta(time_delta):
  """Formats a time delta into a sentence.

  Args:
    time_delta: A Timedelta object to format.

  Returns:
    A string containing a nicely formatted time delta in the form of
    "HH hours, MM minutes, ss seconds ago".
  """
  seconds = int(time_delta.total_seconds())
  days, time_left = divmod(seconds, 86400)  # 86400: seconds in a day = 24*60*60
  hours, time_left = divmod(time_left, 3600)  # 3600: seconds in an hour = 60*60
  minutes, seconds = divmod(time_left, 60)  # 60: seconds in a minute

  pretty_label = '%ss ago' % seconds
  if days > 0:
    pretty_label = '%sd, %sh, %sm ago' % (days, hours, minutes)
  elif hours > 0:
    pretty_label = '%sh, %sm ago' % (hours, minutes)
  elif minutes > 0:
    pretty_label = '%sm, %ss ago' % (minutes, seconds)
  return pretty_label
dataset/ETHPy150Open googleanalytics/google-analytics-super-proxy/src/controllers/util/models_helper.py/FormatTimedelta/original