[CalendarServer-changes] [5216] CalendarServer/trunk/twext/python
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 24 22:49:40 PST 2010
Revision: 5216
http://trac.macosforge.org/projects/calendarserver/changeset/5216
Author: wsanchez at apple.com
Date: 2010-02-24 22:49:38 -0800 (Wed, 24 Feb 2010)
Log Message:
-----------
Add rich comparison to timerange.
Modified Paths:
--------------
CalendarServer/trunk/twext/python/datetime.py
CalendarServer/trunk/twext/python/test/test_datetime.py
Modified: CalendarServer/trunk/twext/python/datetime.py
===================================================================
--- CalendarServer/trunk/twext/python/datetime.py 2010-02-25 05:58:39 UTC (rev 5215)
+++ CalendarServer/trunk/twext/python/datetime.py 2010-02-25 06:49:38 UTC (rev 5216)
@@ -185,6 +185,51 @@
def __repr__(self):
return "timerange(%r, %s)" % (self.start(), self.end())
+ def __eq__(self, other):
+ if not isinstance(other, timerange):
+ return NotImplemented
+ if self.start() != other.start():
+ return False
+ return self.end() == other.end()
+
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def __lt__(self, other):
+ if not isinstance(other, timerange):
+ return NotImplemented
+ if self.start() == other.start():
+ return self.end() < other.end()
+ else:
+ return self.start() < other.start()
+
+ def __le__(self, other):
+ if not isinstance(other, timerange):
+ return NotImplemented
+ if self.start() == other.start():
+ return self.end() <= other.end()
+ else:
+ return self.start() <= other.start()
+
+ def __gt__(self, other):
+ if not isinstance(other, timerange):
+ return NotImplemented
+ if self.start() == other.start():
+ return self.end() > other.end()
+ else:
+ return self.start() > other.start()
+
+ def __ge__(self, other):
+ if not isinstance(other, timerange):
+ return NotImplemented
+ if self.start() == other.start():
+ return self.end() >= other.end()
+ else:
+ return self.start() >= other.start()
+
+ def __hash__(self, other):
+ return hash((self.start(), self.end()))
+
def start(self):
return self._start
Modified: CalendarServer/trunk/twext/python/test/test_datetime.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_datetime.py 2010-02-25 05:58:39 UTC (rev 5215)
+++ CalendarServer/trunk/twext/python/test/test_datetime.py 2010-02-25 06:49:38 UTC (rev 5216)
@@ -21,7 +21,7 @@
from twext.python.datetime import dateordatetime, timerange, utc
-from twistedcaldav.test.util import TestCase, featureUnimplemented
+from twistedcaldav.test.util import TestCase, featureUnimplemented, testUnimplemented
tzUSEastern = tzstr("EST5EDT")
@@ -229,6 +229,10 @@
tr = timerange(start=start, end=end)
self.assertEquals(tr.duration(), duration)
+ @testUnimplemented
+ def test_compare(self):
+ raise NotImplemented
+
@featureUnimplemented
def test_overlapsWith(self):
t1, t2, t3, t4 = timeSeries(4)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100224/66cd899e/attachment-0001.html>
More information about the calendarserver-changes
mailing list