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_date(literal, *additional_formats[, ...])

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 into datetime.date or datetime.datetime objects 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.date object can be created/returned automatically if no time info is specified in the date string/literal (see ret_date parameter).

Parameters:
  • literal (str) – date literal string in the format of DATE_ISO, DATE_TIME_ISO or in one of the additional formats passed into the additional_formats arguments.

  • additional_formats (str) – additional date literal format string masks (supported mask characters are documented at the format argument of the python method strptime()).

  • replace (Optional[Dict[str, Any]]) – dict of replace keyword arguments for datetime.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.

  • ms_sep (str) – microseconds separator character.

  • tz_sep (str) – time-zone separator character.

Return type:

Union[date, datetime, None]

Returns:

represented date/datetime or None if date literal is invalid.