diff --git a/metomi/isodatetime/data.py b/metomi/isodatetime/data.py index bf14e28..bef2a3e 100644 --- a/metomi/isodatetime/data.py +++ b/metomi/isodatetime/data.py @@ -552,19 +552,17 @@ def minutes(self): return self._minutes @property def seconds(self): return self._seconds - def _copy(self): + def _copy(self) -> 'Duration': """Return an (unlinked) copy of this instance.""" new = self.__class__(_is_empty_instance=True) for attr in self.__slots__: setattr(new, attr, getattr(self, attr)) return new - def is_exact(self): + def is_exact(self) -> bool: """Return True if the instance is defined in non-nominal/exact units (weeks, days, hours, minutes or seconds) only.""" - if self._years or self._months: - return False - return True + return not (self._years or self._months) def get_days_and_seconds(self): """Return a roughly-converted duration in days and seconds. diff --git a/metomi/isodatetime/tests/test_01.py b/metomi/isodatetime/tests/test_01.py index 7adab88..e562b6b 100644 --- a/metomi/isodatetime/tests/test_01.py +++ b/metomi/isodatetime/tests/test_01.py @@ -612,6 +612,13 @@ def test_duration_subtract(self): self.assertEqual(test_subtract, end_point, "%s - %s" % (start_point, test_duration)) + def test_duration_is_exact(self): + """Test Duration.is_exact().""" + duration = data.Duration(weeks=1, days=1) + assert duration.is_exact() + for duration in (data.Duration(months=1), data.Duration(years=1)): + assert not duration.is_exact() + def test_timepoint_comparison(self): """Test the TimePoint rich comparison methods and hashing.""" run_comparison_tests(data.TimePoint, get_timepoint_comparison_tests())