Code

Simplify and fix interval comparison.
[roundup.git] / roundup / date.py
index f857bf7c969103488280ffa7777a8352a6248607..af8d1d533c155a4bf2c6ca055a640f342cc6c5ef 100644 (file)
@@ -522,6 +522,7 @@ class Date:
 
     def local(self, offset):
         """ Return this date as yyyy-mm-dd.hh:mm:ss in a local time zone.
+            The offset is a pytz tz offset if pytz is installed.
         """
         y, m, d, H, M, S = _utc_to_local(self.year, self.month, self.day,
                 self.hour, self.minute, self.second, offset)
@@ -718,14 +719,11 @@ class Interval:
 
     def __cmp__(self, other):
         """Compare this interval to another interval."""
+
         if other is None:
             # we are always larger than None
             return 1
-        for attr in 'sign year month day hour minute second'.split():
-            r = cmp(getattr(self, attr), getattr(other, attr))
-            if r:
-                return r
-        return 0
+        return cmp(self.as_seconds(), other.as_seconds())
 
     def __str__(self):
         """Return this interval as a string."""