ae.parse_date
parse date strings more flexible and less strict
this module is pure python and has no namespace external dependencies.
the parse_date() helper function is converting a wide range of date and datetime string literal formats into the
built-in types datetime.datetime and datetime.date.
this function extends (and fully replaces) Pythons standard method strptime() and supports
multiple date formats which are much more flexible interpreted.
Functions
|
parse a date literal string, returning the represented date/datetime or None if date literal is invalid. |
- parse_date(literal, *additional_formats, replace=None, ret_date=False, dt_seps=('T', ' '), ti_sep=':', ms_sep='.', tz_sep='+')[source]
parse a date literal string, returning the represented date/datetime or None if date literal is invalid.
this function checks/corrects the passed date/time literals to support a wider range of ISO and additional date/time formats as Pythons
strptime().Hint
Pythons
strptime()to parse date and time strings intodatetime.dateordatetime.datetimeobjects is very strict and does not respect the formatting alternatives of ISO8601 (see https://bugs.python.org/issue15873 and https://github.com/boxed/iso8601).additionally a
datetime.dateobject can be created/returned automatically if no time info is specified in the date string/literal (seeret_dateparameter).- Parameters:
literal¶ (
str) – date literal string in the format ofDATE_ISO,DATE_TIME_ISOor in one of the additional formats passed into theadditional_formatsarguments.additional_formats¶ (
str) – additional date literal format string masks (supported mask characters are documented at the format argument of the python methodstrptime()).replace¶ (
Optional[Dict[str,Any]]) – dict of replace keyword arguments fordatetime.datetime.replace()call. pass e.g. dict(microsecond=0, tzinfo=None) to set the microseconds of the resulting date to zero and to remove the timezone info.ret_date¶ (
Optional[bool]) – request return value type: True=datetime.date, False=datetime.datetime (the default) or None=determine type from literal (short date if dt_seps are not in literal).dt_seps¶ (
Tuple[str,...]) – tuple of supported separator characters between the date and time literal parts.ti_sep¶ (
str) – separator character of the time parts (hours/minutes/seconds) in literal.
- Return type:
- Returns:
represented date/datetime or None if date literal is invalid.