MCPcopy Create free account
hub / github.com/dateutil/dateutil / _parse

Method _parse

src/dateutil/parser/_parser.py:666–873  ·  view source on GitHub ↗

Private method which performs the heavy lifting of parsing, called from ``parse()``, which passes on its ``kwargs`` to this function. :param timestr: The string to parse. :param dayfirst: Whether to interpret the first value in an ambiguous

(self, timestr, dayfirst=None, yearfirst=None, fuzzy=False,
               fuzzy_with_tokens=False)

Source from the content-addressed store, hash-verified

664 "tzname", "tzoffset", "ampm","any_unused_tokens"]
665
666 def _parse(self, timestr, dayfirst=None, yearfirst=None, fuzzy=False,
667 fuzzy_with_tokens=False):
668 """
669 Private method which performs the heavy lifting of parsing, called from
670 ``parse()``, which passes on its ``kwargs`` to this function.
671
672 :param timestr:
673 The string to parse.
674
675 :param dayfirst:
676 Whether to interpret the first value in an ambiguous 3-integer date
677 (e.g. 01/05/09) as the day (``True``) or month (``False``). If
678 ``yearfirst`` is set to ``True``, this distinguishes between YDM
679 and YMD. If set to ``None``, this value is retrieved from the
680 current :class:`parserinfo` object (which itself defaults to
681 ``False``).
682
683 :param yearfirst:
684 Whether to interpret the first value in an ambiguous 3-integer date
685 (e.g. 01/05/09) as the year. If ``True``, the first number is taken
686 to be the year, otherwise the last number is taken to be the year.
687 If this is set to ``None``, the value is retrieved from the current
688 :class:`parserinfo` object (which itself defaults to ``False``).
689
690 :param fuzzy:
691 Whether to allow fuzzy parsing, allowing for string like "Today is
692 January 1, 2047 at 8:21:00AM".
693
694 :param fuzzy_with_tokens:
695 If ``True``, ``fuzzy`` is automatically set to True, and the parser
696 will return a tuple where the first element is the parsed
697 :class:`datetime.datetime` datetimestamp and the second element is
698 a tuple containing the portions of the string which were ignored:
699
700 .. doctest::
701
702 >>> from dateutil.parser import parse
703 >>> parse("Today is January 1, 2047 at 8:21:00AM", fuzzy_with_tokens=True)
704 (datetime.datetime(2047, 1, 1, 8, 21), (u'Today is ', u' ', u'at '))
705
706 """
707 if fuzzy_with_tokens:
708 fuzzy = True
709
710 info = self.info
711
712 if dayfirst is None:
713 dayfirst = info.dayfirst
714
715 if yearfirst is None:
716 yearfirst = info.yearfirst
717
718 res = self._result()
719 l = _timelex.split(timestr) # Splits the timestr into tokens
720
721 skipped_idxs = []
722
723 # year/month/day list

Callers 1

parseMethod · 0.95

Calls 15

_parse_numeric_tokenMethod · 0.95
_ampm_validMethod · 0.95
_adjust_ampmMethod · 0.95
_could_be_tznameMethod · 0.95
_recombine_skippedMethod · 0.95
_ymdClass · 0.85
splitMethod · 0.80
weekdayMethod · 0.80
monthMethod · 0.80
appendMethod · 0.80
pertainMethod · 0.80
convertyearMethod · 0.80

Tested by

no test coverage detected