class_docstr: Data representing dates with times.
  
  :param datetime_format:
      A formatting string for :meth:`datetime.datetime.strptime` to use
      instead of using regex-based parsing.
  :param timezone:
      A ``ZoneInfo`` timezone to apply to each parsed date.
  :param locale:
      A locale specification such as :code:`en_US` or :code:`de_DE` to use
      for parsing formatted datetimes.
docstr: Cast a single value to a :class:`datetime.datetime`.
  
  If both `date_format` and `locale` have been specified
  in the `agate.DateTime` instance, the `cast()` function
  is not thread-safe.
  :returns: :class:`datetime.datetime` or :code:`None`.
docstr_tok: ["Cast","a","single","value","to","a",":","class",":","`","datetime.datetime","`",".","If","both","`","date_format","`","and","`","locale","`","have","been","specified","in","the","`","agate.DateTime","`","instance",",","the","`","cast","(",")","`","function","is","not","thread-safe",".",":","returns",":",":","class",":","`","datetime.datetime","`","or",":","code",":","`","None","`","."]
code: def cast(self, d):
      """
      Cast a single value to a :class:`datetime.datetime`.
  
      If both `date_format` and `locale` have been specified
      in the `agate.DateTime` instance, the `cast()` function
      is not thread-safe.
      :returns: :class:`datetime.datetime` or :code:`None`.
      """
      if isinstance(d, datetime.datetime) or d is None:
          return d
      if isinstance(d, datetime.date):
          return datetime.datetime.combine(d, datetime.time(0, 0, 0))
      if isinstance(d, str):
          d = d.strip()
  
          if d.lower() in self.null_values:
              return None
      else:
          raise CastError('Can not parse value "%s" as datetime.' % d)
  
      if self.datetime_format:
          orig_locale = None
          if self.locale:
              orig_locale = locale.getlocale(locale.LC_TIME)
              locale.setlocale(locale.LC_TIME, (self.locale, "UTF-8"))
  
          try:
              dt = datetime.datetime.strptime(d, self.datetime_format)
          except (ValueError, TypeError):
              raise CastError(
                  'Value "%s" does not match date format.' % d
              )
          finally:
              if orig_locale:
                  locale.setlocale(locale.LC_TIME, orig_locale)
  
          return dt
  
      try:
          ((_, _, _, _, matched_text),) = self._parser.nlp(
              d, sourceTime=self._source_time
          )
      except Exception:
          matched_text = None
      else:
          value, ctx = self._parser.parseDT(
              d, sourceTime=self._source_time, tzinfo=self.timezone
          )
  
          if matched_text == d and ctx.hasDate and ctx.hasTime:
              return value
          if matched_text == d and ctx.hasDate and not ctx.hasTime:
              return datetime.datetime.combine(
                  value.date(), datetime.time.min
              )
  
      try:
          dt = isodate.parse_datetime(d)
  
          return dt
      except Exception:
          pass
  
      raise CastError('Can not parse value "%s" as datetime.' % d)
  
file_path: agate/agate/data_types/date_time.py
imports: import datetime
  import locale
  import isodate
  import parsedatetime
  from agate.data_types.base import DataType
  from agate.exceptions import CastError
label_desc: Use image node_id 4 for calling the DateTime obj's underlying member method code with example usage: obj.cast(d) and returns: d, datetime, dt, dt, None, value, datetime