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

Function parse

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

Parse a string in one of the supported formats, using the ``parserinfo`` parameters. :param timestr: A string containing a date/time stamp. :param parserinfo: A :class:`parserinfo` object containing parameters for the parser. If ``None``, the default argum

(timestr, parserinfo=None, **kwargs)

Source from the content-addressed store, hash-verified

1262
1263
1264def parse(timestr, parserinfo=None, **kwargs):
1265 """
1266
1267 Parse a string in one of the supported formats, using the
1268 ``parserinfo`` parameters.
1269
1270 :param timestr:
1271 A string containing a date/time stamp.
1272
1273 :param parserinfo:
1274 A :class:`parserinfo` object containing parameters for the parser.
1275 If ``None``, the default arguments to the :class:`parserinfo`
1276 constructor are used.
1277
1278 The ``**kwargs`` parameter takes the following keyword arguments:
1279
1280 :param default:
1281 The default datetime object, if this is a datetime object and not
1282 ``None``, elements specified in ``timestr`` replace elements in the
1283 default object.
1284
1285 :param ignoretz:
1286 If set ``True``, time zones in parsed strings are ignored and a naive
1287 :class:`datetime` object is returned.
1288
1289 :param tzinfos:
1290 Additional time zone names / aliases which may be present in the
1291 string. This argument maps time zone names (and optionally offsets
1292 from those time zones) to time zones. This parameter can be a
1293 dictionary with timezone aliases mapping time zone names to time
1294 zones or a function taking two parameters (``tzname`` and
1295 ``tzoffset``) and returning a time zone.
1296
1297 The timezones to which the names are mapped can be an integer
1298 offset from UTC in seconds or a :class:`tzinfo` object.
1299
1300 .. doctest::
1301 :options: +NORMALIZE_WHITESPACE
1302
1303 >>> from dateutil.parser import parse
1304 >>> from dateutil.tz import gettz
1305 >>> tzinfos = {"BRST": -7200, "CST": gettz("America/Chicago")}
1306 >>> parse("2012-01-19 17:21:00 BRST", tzinfos=tzinfos)
1307 datetime.datetime(2012, 1, 19, 17, 21, tzinfo=tzoffset(u'BRST', -7200))
1308 >>> parse("2012-01-19 17:21:00 CST", tzinfos=tzinfos)
1309 datetime.datetime(2012, 1, 19, 17, 21,
1310 tzinfo=tzfile('/usr/share/zoneinfo/America/Chicago'))
1311
1312 This parameter is ignored if ``ignoretz`` is set.
1313
1314 :param dayfirst:
1315 Whether to interpret the first value in an ambiguous 3-integer date
1316 (e.g. 01/05/09) as the day (``True``) or month (``False``). If
1317 ``yearfirst`` is set to ``True``, this distinguishes between YDM and
1318 YMD. If set to ``None``, this value is retrieved from the current
1319 :class:`parserinfo` object (which itself defaults to ``False``).
1320
1321 :param yearfirst:

Callers 15

test_parserFunction · 0.90
test_parser_defaultFunction · 0.90
test_parse_dayfirstFunction · 0.90
test_parse_yearfirstFunction · 0.90
test_parse_ignoretzFunction · 0.90
test_parse_with_tzoffsetFunction · 0.90
test_ybdMethod · 0.90
test_none_invalidMethod · 0.90
test_int_invalidMethod · 0.90
test_duck_typingMethod · 0.90

Calls 2

parserClass · 0.85
parseMethod · 0.45

Tested by 15

test_parserFunction · 0.72
test_parser_defaultFunction · 0.72
test_parse_dayfirstFunction · 0.72
test_parse_yearfirstFunction · 0.72
test_parse_ignoretzFunction · 0.72
test_parse_with_tzoffsetFunction · 0.72
test_ybdMethod · 0.72
test_none_invalidMethod · 0.72
test_int_invalidMethod · 0.72
test_duck_typingMethod · 0.72