Skip to content

Instantly share code, notes, and snippets.

@erajabzadeh
Created February 6, 2025 08:25
Show Gist options
  • Save erajabzadeh/fe900bd5bc68734c9f0b1ea910a3db9f to your computer and use it in GitHub Desktop.
Save erajabzadeh/fe900bd5bc68734c9f0b1ea910a3db9f to your computer and use it in GitHub Desktop.
Allen Interval Rules
class AllenIntervalRules(object):
@staticmethod
def ContainedBy(x, y):
return (x.UtcStartTime > y.UtcStartTime) and (x.UtcEndTime < y.UtcEndTime)
@staticmethod
def Contains(x, y):
return (y.UtcStartTime > x.UtcStartTime) and (y.UtcEndTime < x.UtcEndTime)
@staticmethod
def FinishedBy(x, y):
return (y.UtcEndTime == x.UtcEndTime) and (y.UtcStartTime > x.UtcStartTime)
@staticmethod
def Finishes(x, y):
return (x.UtcEndTime == y.UtcEndTime) and (x.UtcStartTime > y.UtcStartTime)
@staticmethod
def IsEqualTo(x, y):
return (x.UtcStartTime == y.UtcStartTime) and (x.UtcEndTime == y.UtcEndTime)
@staticmethod
def Meets(x, y):
return (x.UtcEndTime == y.UtcStartTime)
@staticmethod
def MetBy(x, y):
return (y.UtcEndTime == x.UtcStartTime)
@staticmethod
def OverlapedBy(x, y):
return (y.UtcStartTime < x.UtcStartTime) and ((y.UtcEndTime > x.UtcStartTime) and (y.UtcEndTime < x.UtcEndTime))
@staticmethod
def Overlaps(x, y):
return (x.UtcStartTime < y.UtcStartTime) and ((x.UtcEndTime > y.UtcStartTime) and (x.UtcEndTime < y.UtcEndTime))
@staticmethod
def StartedBy(x, y):
return (y.UtcStartTime == x.UtcStartTime) and (y.UtcEndTime < x.UtcEndTime)
@staticmethod
def Starts(x, y):
return (x.UtcStartTime == y.UtcStartTime) and (x.UtcEndTime < y.UtcEndTime)
@staticmethod
def TakesPlaceAfter(x, y):
return x.UtcStartTime > y.UtcEndTime
@staticmethod
def TakesPlaceBefore(x, y):
return x.UtcEndTime < y.UtcStartTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment