Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Martin A. Brown" Newsgroups: comp.lang.python Subject: Re: Set type for datetime intervals Date: Mon, 4 Apr 2016 08:46:52 -0700 Lines: 43 Message-ID: References: <56FE0625.5030901@shopzeus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT X-Trace: news.uni-berlin.de ASzW6MXEmGbOnyhV+hWEtA96mffIzCf+3cy2aYpaLcig== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'url:pypi': 0.03; 'implements': 0.07; 'nicely': 0.07; 'cc:addr:python-list': 0.09; '::=': 0.16; '>does': 0.16; 'applaud': 0.16; 'element2,': 0.16; 'from:addr:martin': 0.16; 'morning,': 0.16; 'posted,': 0.16; 'received:hsd1.or.comcast.net': 0.16; 'received:io': 0.16; 'received:or.comcast.net': 0.16; 'received:psf.io': 0.16; 'skip:> 20': 0.16; 'subject:type': 0.16; 'element': 0.18; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'handles': 0.20; 'posted': 0.21; 'martin': 0.22; 'sets': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'compare': 0.27; 'received:24': 0.28; 'skip:( 20': 0.28; 'charset:iso-8859-15': 0.28; 'occurred': 0.29; 'checked': 0.31; 'anyone': 0.32; 'posting': 0.32; 'url:python': 0.33; 'received:comcast.net': 0.33; 'could': 0.35; 'something': 0.35; 'problem.': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'subject:: ': 0.37; 'difference': 0.38; 'late': 0.38; 'some': 0.40; 'your': 0.60; 'received:network': 0.61; 'skip:u 10': 0.61; 'managing': 0.66; 'greetings': 0.71; 'ranges': 0.76; '>of': 0.84; 'crafted': 0.84; 'elements:': 0.84; 'union,': 0.84; 'subject:Set': 0.91 X-X-Sender: mabrown@macron.wonderfrog.net In-Reply-To: <56FE0625.5030901@shopzeus.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <56FE0625.5030901@shopzeus.com> Xref: csiph.com comp.lang.python:106450 Greetings László, >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: > >element ::= (start_point_in_time, end_point_in_time) >intervalset ::= { element1, element2, .... } > >Operations on elements: > >element1.intersect(element2) >element1.union(element2) >element1.minus(element2) > >Operations on sets: > >intervalset1.intersect(intervalset2) >intervalset1.union(intervalset2) >intervalset1.minus(intervalset2) > >Does anyone know a library that already implements these functions? Sorry to be late to the party--I applaud that you have already crafted something to attack your problem. When you first posted, there was a library that was tickling my memory, but I could not remember its (simple) name. It occurred to me this morning, after you posted your new library: https://pypi.python.org/pypi/intervaltree This handles overlapping ranges nicely and provides some tools for managing them. Before posting this, I checked that it works with datetime types, and, unsurprisingly, it does. Happy trails! -Martin -- Martin A. Brown http://linux-ip.net/