Mil*_*ell 6 python datetime parsing iso
I need to convert
FROM
a list of strs
TO
a list of
datetime.datetimedatetime.datetime plus a datetime.timedelta.The input list contains strings in ISO_8601 (wikipedia) format. The strings can either be a date or a time interval. The solution for this, that I came up with is the following:
import dateutil.parser
result = []
for str_ in input_list:
if not is_time_interval_str(str_):
result.append(dateutil.parser.parse(str_))
else:
result.append(parse_time_interval(str_))
Run Code Online (Sandbox Code Playgroud)
What I am stuck with is the two functions is_time_interval_str and parse_time_interval. I have looked for python packages that implement parsing of the time intervals but I couldn't find any yet. I have checked
dateutil.parserpyiso8601isodatearrowciso8601iso8601utils (claims to support time intervals, but does only some)maya (offers the functionality, but the implementation is flawed)pendulum (claims to support time intervals, but does only some)Some may be capable of parsing durations like PnYnMnDTnHnMnS but none is able to parse time intervals like for example <start>/<end>.
6.,7. and 8. work partially also with <start>/<end> but none of them works with a partial <end> description. (example '2007-01-10/27')
I considered writing my own string parser but it feels that such fundamental thing like the implementation of the ISO_8601 should be incorporated by one of the above packages.
Questions
map(dateutil.parser.parser, str_.split("/"))?ISO_8601?str to datetime.datetime, would this be an option for time intervals?