Fix timedelta_string showing 12 months instead of 1 year (#187648)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Raman Gupta
2026-10-20 22:31:52 -04:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 1c57f2e7b8
commit 17652e4760
2 changed files with 7 additions and 2 deletions
+3 -2
View File
@@ -337,8 +337,9 @@ def _get_timestring(timediff: float, precision: int = 1) -> str:
if current_precision == precision:
months = (timediff % factors[0]) // factors[1]
timediff += round(remainder / current_factor) * current_factor - remainder
# 12 months are 5 days short of a year, so rounding up to them ends the year
if months < 12 <= (timediff % factors[0]) // factors[1]:
rounded_months = (timediff % factors[0]) // factors[1]
# 12 months are 5 days short of a year, so rounding to them ends the year
if rounded_months >= 12 and (months < 12 or current_factor == factors[1]):
timediff += factors[0] - timediff % factors[0]
break
remainder %= current_factor
+4
View File
@@ -320,6 +320,10 @@ def test_time_remaining() -> None:
(timedelta(days=29, hours=13), 1, "1 month"),
(timedelta(days=364, hours=13), 2, "1 year"),
(timedelta(days=350), 1, "1 year"),
(timedelta(days=360), 1, "1 year"),
(timedelta(days=364), 1, "1 year"),
(timedelta(days=365, hours=-1), 1, "1 year"),
(timedelta(days=729), 2, "2 years"),
(timedelta(days=724, hours=23, minutes=59, seconds=50), 2, "2 years"),
(timedelta(days=724, hours=13), 3, "2 years"),
(timedelta(days=380, hours=23, minutes=59, seconds=50), 2, "1 year 16 days"),