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)
| 1262 | |
| 1263 | |
| 1264 | def 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: |