ANN: intervalset Was: Set type for datetime intervals
Nagy László Zsolt
gandalf at shopzeus.com
Mon Apr 4 03:12:11 EDT 2016
Hi All,
If anyone is interested, a module was born:
https://bitbucket.org/nagylzs/intervalset
https://pypi.python.org/pypi/intervalset/0.1.1
I have some unit tests, but testers and comments are welcome.
Also see below.
>>
>> Hello,
>>
>> I need to compare sets of datetime intervals, and make set operations on
>> them: intersect, union, difference etc. One element of a set would be an
>> interval like this:
> Two thoughts on this: Such an object is not precisely a set* of
> datetimes, rather it is a set of nonintersecting intervals.
Yes, you are right. It is a set of non-intersecting intervals.
> It could
> also be useful to have one for numbers (the datetime version could even
> maybe be implemented in terms of it)
Well, please check sources on bitbucket. You are more than welcome to
join the project.
>
>> element ::= (start_point_in_time, end_point_in_time)
>> intervalset ::= { element1, element2, .... }
> Are these open intervals or closed intervals?
Closed. In my particular implementation, there is a singleton for all
empty intervals. It is not possible to create an arbitrary interval with
the same starting and ending time (the singleton being the only
exception). I think that implementing open intervals would be much more
difficult, and we would have to know and use the smallest possible
increment (resolution) of the date/time type. Which may be platform
dependent.
>
> Also, how are you going to handle daylight savings?
Well, this little module only uses datetime instances and relies on the
datetime module for comparison. As far as datetime instances compare
correctly, this module will also work correctly.
Best,
Laszlo
More information about the Python-list
mailing list