def format_sec(sec):
  """Format seconds in a human-readable format."""
  sec = round(sec)
  output = ''
  if sec >= 86400 * 7:
    value = int(sec / (86400 * 7))
    sec -= value * 86400 * 7
    output += '%d week%s ' % (value, 's' if value != 1 else '')
  if sec >= 86400:
    value = int(sec / 86400)
    sec -= value * 86400
    output += '%d day%s ' % (value, 's' if value != 1 else '')
  if sec >= 3600:
    value = int(sec / 3600)
    sec -= value * 3600
    output += '%d hour%s ' % (value, 's' if value != 1 else '')
  if sec >= 60:
    value = int(sec / 60)
    sec -= value * 60
    output += '%d minute%s ' % (value, 's' if value != 1 else '')
  value = sec
  if value > 0 or output == '':
    output += '%d second%s ' % (value, 's' if value != 1 else '')
  return output.rstrip()