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

Method _parse

src/dateutil/parser/_parser.py:660–867  ·  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

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