Set type for datetime intervals

Nagy László Zsolt gandalf at shopzeus.com
Mon Apr 4 03:16:55 EDT 2016


>
> On Fri, Apr 1, 2016 at 1:32 AM Nagy László Zsolt <gandalf at shopzeus.com
> <mailto:gandalf at shopzeus.com>> wrote:
>
>     Does anyone know a library that already implements these functions?
>
>
> What do you not like about the ones on PyPI?
> https://pypi.python.org/pypi?%3Aaction=search&term=interval&submit=search
There are a few, but none of them was implementing a set ot
non-intersecting intervals. AFAIK what I needed had no implementation
until now.
>
> Depending on the resolution you want, you might be able to use builtin
> sets for everything.
>
>     def interval(start, stop, precision=60):
>         a = round(start.timestamp(), precision)
>         b = round(stop.timestamp(), precision)
>         return set(range(a, b, precision))
>
I know, I was not clear in my request. A simple set will not unify
overlapping intervals, and cannot do set operations (union,
intersection, difference, symmetric difference).





More information about the Python-list mailing list