def _add_deprecation_to_docstring(doc, date, instructions):
  """Adds a deprecation notice to a docstring."""
  if not doc:
    lines = ['DEPRECATED FUNCTION']
  else:
    lines = doc.splitlines()
    lines[0] += ' (deprecated)'

  notice = [
      '',
      'THIS FUNCTION IS DEPRECATED. It will be removed after %s.' % date,
      'Instructions for updating:',
      '%s' % instructions,
  ]

  if len(lines) > 1:
    # Make sure that we keep our distance from the main body
    if lines[1].strip():
      notice += ['']

    lines = [lines[0]] + notice + lines[1:]
  else:
    lines += notice

  return '\n'.join(lines)