class_docstr: Data representing dates alone.
  
  :param date_format:
      A formatting string for :meth:`datetime.datetime.strptime` to use
      instead of using regex-based parsing.
  :param locale:
      A locale specification such as :code:`en_US` or :code:`de_DE` to use
      for parsing formatted dates.
class_docstr_tok: ["Data","representing","dates","alone",".",":","param","date_format",":","A","formatting","string","for",":","meth",":","`","datetime.datetime.strptime","`","to","use","instead","of","using","regex-based","parsing",".",":","param","locale",":","A","locale","specification","such","as",":","code",":","`","en_US","`","or",":","code",":","`","de_DE","`","to","use","for","parsing","formatted","dates","."]
docstr: Cast a single value to a :class:`datetime.date`.
  
  If both `date_format` and `locale` have been specified
  in the `agate.Date` instance, the `cast()` function
  is not thread-safe.
  :returns: :class:`datetime.date` or :code:`None`.
docstr_tok: ["Cast","a","single","value","to","a",":","class",":","`","datetime.date","`",".","If","both","`","date_format","`","and","`","locale","`","have","been","specified","in","the","`","agate.Date","`","instance",",","the","`","cast","(",")","`","function","is","not","thread-safe",".",":","returns",":",":","class",":","`","datetime.date","`","or",":","code",":","`","None","`","."]
code: def cast(self, d):
      """
      Cast a single value to a :class:`datetime.date`.
  
      If both `date_format` and `locale` have been specified
      in the `agate.Date` instance, the `cast()` function
      is not thread-safe.
      :returns: :class:`datetime.date` or :code:`None`.
      """
      if type(d) is date or d is None:
          return d
  
      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 date.' % d)
  
      if self.date_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.strptime(d, self.date_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.date()
  
      try:
          ((value, ctx, _, _, matched_text),) = self._parser.nlp(
              d, sourceTime=ZERO_DT
          )
      except (TypeError, ValueError, OverflowError):
          raise CastError('Value "%s" does not match date format.' % d)
      else:
          if matched_text == d and ctx.hasDate and not ctx.hasTime:
              return value.date()
  
      raise CastError('Can not parse value "%s" as date.' % d)
  
file_path: agate/agate/data_types/date.py
imports: import locale
  from datetime import date, datetime, time
  import parsedatetime
  from agate.data_types.base import DataType
  from agate.exceptions import CastError
label_desc: Use image node_id 4 for calling the Date obj's underlying member method code with example usage: obj.cast(d) and returns: d, dt, None, value