Parse the date and return a datetime object

        The heuristic for determining the date is:
         - if ``date_format`` is set, parse using strptime
         - if one field of 8 digits, YYYYMMDD
         - split by '-' or '/'
         - (TODO: substitute string months with their numbers)
         - if (2, 2, 4), DD-MM-YYYY (not the peculiar US order)
         - if (4, 2, 2), YYYY-MM-DD
         - ka-boom!

        The issue of reliably discerning between DD-MM-YYYY (sane) vs.
        MM-DD-YYYY (absurd, but Big In America), without being told what's
        being used,  is intractable.

        Return a datetime.date object.

def parse_date(self, date):
        """Parse the date and return a datetime object

        The heuristic for determining the date is:
         - if ``date_format`` is set, parse using strptime
         - if one field of 8 digits, YYYYMMDD
         - split by '-' or '/'
         - (TODO: substitute string months with their numbers)
         - if (2, 2, 4), DD-MM-YYYY (not the peculiar US order)
         - if (4, 2, 2), YYYY-MM-DD
         - ka-boom!

        The issue of reliably discerning between DD-MM-YYYY (sane) vs.
        MM-DD-YYYY (absurd, but Big In America), without being told what's
        being used,  is intractable.

        Return a datetime.date object.

        """
        if self.date_format is not None:
            return datetime.datetime.strptime(date, self.date_format).date()

        if re.match('\d{8}$', date):
            # assume YYYYMMDD
            return datetime.date(*map(int, (date[:4], date[4:6], date[6:])))
        try:
            # split by '-' or '/'
            parts = date_delim.split(date, 2)   # maxsplit=2
            if len(parts) == 3:
                if len(parts[0]) == 4:
                    # YYYY, MM, DD
                    return datetime.date(*map(int, parts))
                elif len(parts[2]) == 4:
                    # DD, MM, YYYY
                    return datetime.date(*map(int, reversed(parts)))
        # fail
        except TypeError, ValueError:
            raise reader.DataError('Bad date format: "{}"'.format(date))