Skip to content

A simple utility that lets you easily compare spans (ranges) of time in Python.

License

Notifications You must be signed in to change notification settings

appointlet/span

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Span

Span is a simply utility that lets you easily compare spans (ranges) of time in Python. It let's you determine if span touch, intersect, etc.

Installation

Span can be installed from pip:

pip install span

Intersects

Check to see if two spans intersect:

>>> from span import Span
>>> from datetime import datetime, timedelta

>>> now = datetime.now()

>>> s1 = Span(start=now, end=now+timedelta(minutes=60))
>>> s2 = Span(start=now+timedelta(minutes=30), end=now+timedelta(minutes=90))

>>> s1.lintersects(s2) #check if s1 intersects the left (start) side of s2
True

>>> s1.rintersects(s2) #check if s1 intersects the right (end) side of s2
False

>>> s1.intersects(s2) #check if s1 intersects either side of s2
True

Touches

Check to see if two spans touch:

>>> from span import Span
>>> from datetime import datetime, timedelta

>>> now = datetime.now()

>>> s1 = Span(now, now + timedelta(minutes=60))
>>> s2 = Span(now + timedelta(minutes=60), now + timedelta(minutes=120))

>>> s1.ltouches(s2) #check if s1 touches the left (start) side of s2
True

>>> s1.rtouches(s2) #check if s1 touches the right (end) side of s2
False

>>> s1.touches(s2) #check if s1 touches either side of s2
True

Encompasses

Check to see if one span encompasses another:

>>> from span import Span
>>> from datetime import datetime, timedelta

>>> now = datetime.now()

>>> s1 = Span(now, now + timedelta(minutes=60))
>>> s2 = Span(now, now + timedelta(minutes=60))
>>> s3 = Span(now, now + timedelta(minutes=59))

>>> s1.encompasses(s2)
True

>>> s1.encompassed_by(s2)
False

About

A simple utility that lets you easily compare spans (ranges) of time in Python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages