Skip to content

Commit

Permalink
Make duration logic more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Jul 14, 2023
1 parent a37377f commit 615cb0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/undate/undate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tests/test_undate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 615cb0d

Please sign in to comment.