summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f22e53)
raw | patch | inline | side by side (parent: 3f22e53)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 11 Oct 2002 01:25:40 +0000 (01:25 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Fri, 11 Oct 2002 01:25:40 +0000 (01:25 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1341 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/date.py | patch | blob | history | |
test/test_dates.py | patch | blob | history |
diff --git a/roundup/date.py b/roundup/date.py
index d074064d07447fd6d3a349256d6a501bdcf8ca0b..6299318d0cbbb65a299f61d465e68e01cb885ba6 100644 (file)
--- a/roundup/date.py
+++ b/roundup/date.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: date.py,v 1.34 2002-10-10 08:24:37 richard Exp $
+# $Id: date.py,v 1.35 2002-10-11 01:25:40 richard Exp $
__doc__ = """
Date, time and time interval handling.
l.append('%d:%02d'%(self.hour, self.minute))
return ' '.join(l)
+ def __add__(self, other):
+ if isinstance(other, Date):
+ # the other is a Date - produce a Date
+ return Date(other.addInterval(self))
+ elif isinstance(other, Interval):
+ # add the other Interval to this one
+ a = self.get_tuple()
+ b = other.get_tuple()
+ if b[0] < 0:
+ i = Interval([x-y for x,y in zip(a[1:],b[1:])])
+ else:
+ i = Interval([x+y for x,y in zip(a[1:],b[1:])])
+ return i
+ # nope, no idea what to do with this other...
+ raise TypeError, "Can't add %r"%other
+
def set(self, spec, interval_re=re.compile('''
\s*(?P<s>[-+])? # + or -
\s*((?P<y>\d+\s*)y)? # year
diff --git a/test/test_dates.py b/test/test_dates.py
index 4cbfd706891d47c0064ed6777cbfd3dc93b41b18..88accdba2c34de7d61039762391bd881d1caeb71 100644 (file)
--- a/test/test_dates.py
+++ b/test/test_dates.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: test_dates.py,v 1.13 2002-09-10 00:19:54 richard Exp $
+# $Id: test_dates.py,v 1.14 2002-10-11 01:25:40 richard Exp $
import unittest, time
ae(str(Interval(' 14:00 ')), '+ 14:00')
ae(str(Interval(' 0:04:33 ')), '+ 0:04:33')
+ # __add__
+ # XXX these are fairly arbitrary and need fixing once the __add__
+ # code handles the odd cases more correctly
+ ae(str(Interval('1y') + Interval('1y')), '+ 2y')
+ ae(str(Interval('1y') + Interval('1m')), '+ 1y 1m')
+ ae(str(Interval('1y') + Interval('2:40')), '+ 1y 2:40')
+ ae(str(Interval('1y') + Interval('- 1y')), '+')
+ ae(str(Interval('1y') + Interval('- 1m')), '+ 1y -1m')
+
def suite():
return unittest.makeSuite(DateTestCase, 'test')