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