isodate
isodate copied to clipboard
Parse time interval
The Wikipedia article on ISO 8601 mentions time intervals, e.g. "2008-02-15/03-14". Is there a facility in isodate
for parsing these?
I'm not sure there is a single function for parsing those complex date interval notations. There are a lot of cases to handle there, and inferring when the second value is a partial datetime, but it could be a nice possible feature enhancement.
For now you can sort of work around it if you can make both values be a full date, time, or datetime string:
s = "2008-02-15/2008-03-14"
interval = isodate.parse_date(s.split("/")[1]) - isodate.parse_date(s.split("/")[0])
The interval variable will be a datetime.timedelta object. If the values in the string are datetimes and not just dates, then use parse_datetime instead of parse_date.
No, time interval is not supported yet.
Could be interesting though, just not sure how to map that onto python native date/time types.
@theferrit32 suggestion is probably a reasonable workaround for now, given that iso time intervals and recurring time intervals can be quite complex to interpret correctly.
The workaround is fine for now, but I agree that a parse_interval
method would be a nice enhancement to isodate
. Handling those complexities is one of the reasons to use a library like this, after all!