code: def extract(cls, timestamp_str):
          
          if not timestamp_str:
              raise DateTimeFormatterException(
                  'timestamp_str must a valid string {}'.format(timestamp_str))
  
          if isinstance(timestamp_str, (date, datetime)):
              return timestamp_str
  
          try:
              return cls.extract_datetime(timestamp_str)
          except DateTimeFormatterException:
              pass
  
          try:
              return cls.extract_datetime_hour(timestamp_str)
          except DateTimeFormatterException:
              pass
  
          try:
              return cls.extract_date(timestamp_str)
          except DateTimeFormatterException as e:
              raise DateTimeFormatterException(e)
docs: Tries to extract a `datetime` object from the given string. First the
          datetime format is tried, if it fails, the date format is used for
          extraction.
  
          Raises `DateTimeFormatterException` if the extraction fails.