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

Class parser

src/dateutil/parser/_parser.py:568–1264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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