uataq.timerange.TimeRange.parse_iso#

static TimeRange.parse_iso(string, inclusive=False)[source]#

Parse an ISO 8601 time string into a datetime.

Accepts YYYY, YYYY-MM, YYYY-MM-DD, then a T or space and HH, HH:MM, HH:MM:SS or HH:MM:SS.ffffff. Dashes and colons may be left out (20240115), and a trailing Z or +00:00 is allowed; times are UTC.

Parameters:
  • string (str) – The ISO 8601 formatted time string.

  • inclusive (bool) – If False (default), return the start of the period the string names. If True, return its end: one unit of the finest component given past the start, so "2024-01" ends at 2024-02-01, "2024-01-15T12:30" at 12:31, and "12:30:45.5" at 12:30:45.6 (one unit of the last fractional digit).

Returns:

The parsed datetime.

Return type:

datetime

Raises:

ValueError – If the string is not in one of the accepted forms, carries a non-UTC offset, or names an impossible date.