From 615cb0d9af313128a562107305d1b7c2eddd9535 Mon Sep 17 00:00:00 2001 From: rlskoeser Date: Fri, 14 Jul 2023 08:51:12 -0400 Subject: [PATCH] Make duration logic more consistent --- src/undate/undate.py | 4 ++-- tests/test_undate.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/undate/undate.py b/src/undate/undate.py index 96dd346..e816adb 100644 --- a/src/undate/undate.py +++ b/src/undate/undate.py @@ -331,8 +331,8 @@ def duration(self) -> datetime.timedelta: duration = end - self.earliest.earliest # add the additional day *after* checking for a negative - else: - duration += ONE_DAY + # or after recalculating with adjusted year + duration += ONE_DAY return duration diff --git a/tests/test_undate.py b/tests/test_undate.py index 7293553..d02c3d2 100644 --- a/tests/test_undate.py +++ b/tests/test_undate.py @@ -264,11 +264,12 @@ def test_duration(self): month_noyear_duration = UndateInterval( Undate(None, 12, 1), Undate(None, 1, 1) ).duration() - assert month_noyear_duration.days == 31 + assert month_noyear_duration.days == 32 + # this seems wrong, but we currently count both start and dates # real case from Shakespeare and Company Project data; # second date is a year minus one day in the future month_noyear_duration = UndateInterval( Undate(None, 6, 7), Undate(None, 6, 6) ).duration() - assert month_noyear_duration.days == 364 + assert month_noyear_duration.days == 365