code: def rfc2822_format(val):
      
      if isinstance(val, six.string_types):
          return val
      elif isinstance(val, (datetime.datetime, datetime.date)):
          # Convert to a timestamp
          val = time.mktime(val.timetuple())
      if isinstance(val, numbers.Number):
          return email.utils.formatdate(val)
      else:
          # Bail
          return val
docs: Takes either a date, a datetime, or a string, and returns a string that
      represents the value in RFC 2822 format. If a string is passed it is
      returned unchanged.