isodate icon indicating copy to clipboard operation
isodate copied to clipboard

Parse time interval

Open danvk opened this issue 7 years ago • 3 comments

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?

danvk avatar Jan 30 '18 17:01 danvk

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.

theferrit32 avatar Jan 30 '18 20:01 theferrit32

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.

gweis avatar Jan 31 '18 01:01 gweis

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!

danvk avatar Jan 31 '18 17:01 danvk