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

Class parser

src/dateutil/parser/_parser.py:562–1258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560
561
562class parser:
563 def __init__(self, info=None):
564 self.info = info or parserinfo()
565
566 def parse(self, timestr, default=None,
567 ignoretz=False, tzinfos=None, **kwargs):
568 """
569 Parse the date/time string into a :class:`datetime.datetime` object.
570
571 :param timestr:
572 Any date/time string using the supported formats.
573
574 :param default:
575 The default datetime object, if this is a datetime object and not
576 ``None``, elements specified in ``timestr`` replace elements in the
577 default object.
578
579 :param ignoretz:
580 If set ``True``, time zones in parsed strings are ignored and a
581 naive :class:`datetime.datetime` object is returned.
582
583 :param tzinfos:
584 Additional time zone names / aliases which may be present in the
585 string. This argument maps time zone names (and optionally offsets
586 from those time zones) to time zones. This parameter can be a
587 dictionary with timezone aliases mapping time zone names to time
588 zones or a function taking two parameters (``tzname`` and
589 ``tzoffset``) and returning a time zone.
590
591 The timezones to which the names are mapped can be an integer
592 offset from UTC in seconds or a :class:`tzinfo` object.
593
594 .. doctest::
595 :options: +NORMALIZE_WHITESPACE
596
597 >>> from dateutil.parser import parse
598 >>> from dateutil.tz import gettz
599 >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")}
600 >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos)
601 datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200))
602 >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos)
603 datetime.datetime(2012, 1, 19, 17, 21,
604 tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago'))
605
606 This parameter is ignored if ``ignoretz`` is set.
607
608 :param \\*\\*kwargs:
609 Keyword arguments as passed to ``_parse()``.
610
611 :return:
612 Returns a :class:`datetime.datetime` object or, if the
613 ``fuzzy_with_tokens`` option is ``True``, returns a tuple, the
614 first element being a :class:`datetime.datetime` object, the second
615 a tuple containing the fuzzy tokens.
616
617 :raises ParserError:
618 Raised for invalid or unknown string format, if the provided
619 :class:`tzinfo` is not in a valid format, or if an invalid date

Callers 5

testParserParseStrMethod · 0.90
testCustomParserInfoMethod · 0.90
_parser.pyFile · 0.85
parseFunction · 0.85

Calls

no outgoing calls

Tested by 3

testParserParseStrMethod · 0.72
testCustomParserInfoMethod · 0.72