diff options
author | Gerhard Weis <gweis@gmx.at> | 2009-02-09 12:11:42 +1000 |
---|---|---|
committer | Gerhard Weis <gweis@gmx.at> | 2009-02-09 12:11:42 +1000 |
commit | de8b4fcb5b87c03ee175fa7649b6bbb4cdee20a5 (patch) | |
tree | 1d8e11ea5b5e8bfa964b085808b7620ca64c6b94 | |
parent | 14f2ed8f0f1ad356194e4d5684c80e644517927c (diff) | |
download | isodate-de8b4fcb5b87c03ee175fa7649b6bbb4cdee20a5.tar.gz |
* fixed bug in comparison between timedelta and Duration.
-rw-r--r-- | CHANGES.txt | 7 | ||||
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | src/isodate/duration.py | 4 | ||||
-rw-r--r-- | src/tests/test_duration.py | 2 |
4 files changed, 13 insertions, 2 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index dcb9df3..b4e6f89 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -2,7 +2,12 @@ CHANGES ======= -0.4.0 (unreleased) +0.4.1 (unreleased) +------------------ + +- fixed bug in comparison between timedelta and Duration. + +0.4.0 (2009-02-09) ------------------ - added method to parse ISO 8601 time zone strings @@ -34,7 +34,7 @@ def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() setup(name = 'isodate', - version = '0.4.0', + version = '0.4.1', packages = find_packages('src', exclude=["tests"]), package_dir={'': 'src'}, diff --git a/src/isodate/duration.py b/src/isodate/duration.py index 25d94af..007c0cc 100644 --- a/src/isodate/duration.py +++ b/src/isodate/duration.py @@ -209,6 +209,8 @@ class Duration(object): If the years, month part and the timedelta part are both equal, then the two Durations are considered equal. ''' + if isinstance(other, timedelta) and self.years==0 and self.months==0: + return self.tdelta == other if not isinstance(other, Duration): return NotImplemented if ((self.years * 12 + self.months) == @@ -221,6 +223,8 @@ class Duration(object): If the years, month part or the timedelta part is not equal, then the two Durations are considered not equal. ''' + if isinstance(other, timedelta) and self.years==0 and self.months==0: + return self.tdelta != other if not isinstance(other, Duration): return NotImplemented if ((self.years * 12 + self.months) != diff --git a/src/tests/test_duration.py b/src/tests/test_duration.py index d8244b5..6a32d97 100644 --- a/src/tests/test_duration.py +++ b/src/tests/test_duration.py @@ -277,6 +277,8 @@ class DurationTest(unittest.TestCase): Duration(years=1, months=1)) self.assertTrue(Duration(years=1, months=1) != Duration(months=14)) self.assertTrue(Duration(years=1) != timedelta(days=365)) + self.assertEqual(Duration(days=1), timedelta(days=1)) + self.assertNotEqual(timedelta(days=1), Duration(days=1)) def create_parsetestcase(durationstring, expectation, format, altstr): ''' |