You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

72 lines
2.0 KiB

  1. from datetime import datetime
  2. class IntervalException(Exception):
  3. pass
  4. class Interval(object):
  5. """Represents an interval of time"""
  6. def __init__(self, start, end):
  7. self.start = start
  8. self.end = end
  9. def __repr__(self):
  10. return "Interval(" + repr(self.start) + ", " + repr(self.end) + ")"
  11. def __str__(self):
  12. return "[" + str(self.start) + " -> " + str(self.end) + "]"
  13. def __getattr__(self, name):
  14. return { }
  15. def __setattr__(self, name, value):
  16. if (type(value).__name__ != 'datetime'):
  17. raise IntervalException("Must set datetime values")
  18. self.__dict__[name] = value
  19. if (type(self.start) is type(self.end)):
  20. if (self.start > self.end):
  21. raise IntervalException("Interval start must precede interval end")
  22. def intersects(self, other):
  23. if (self.end <= other.start or
  24. self.start >= other.end):
  25. return False;
  26. else:
  27. return True;
  28. """hi
  29. if (self.start < other.start &&
  30. self.end > other.start &&
  31. self.end < other.end)
  32. start-other.start start-other.end end-other.start end-other.end
  33. ---- < < > <
  34. ----
  35. ---- < < < < n
  36. -----
  37. --- > < > <
  38. --------
  39. ------- < < > >
  40. ---
  41. ---- > < > >
  42. -----
  43. ----------- > > > > n
  44. -----
  45. """
  46. class IntervalSet(object):
  47. """A non-intersecting set of intervals"""
  48. def __init__(self, value):
  49. print "hello" + value