You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
naturaldelta() renders negative timedeltas as positive durations #535
naturaldelta() silently erases the sign of negative timedeltas, rendering them as positive durations.
Reproduction (humanize 4.16.0)
importdatetime, humanizehumanize.naturaldelta(datetime.timedelta(days=-400))
# '1 year, 1 month' <-- no negative indication; 400 days in the PAST# renders identically to +400 dayshumanize.naturaldelta(datetime.timedelta(seconds=-1))
# 'a second' <-- again positive rendering
Why this seems wrong
-400 days and +400 days are opposite-signed durations but render identically. As with precisedelta() (filed separately), this arises naturally from swapped-operand arithmetic (end - start) and the sign erasure hides the error.
Possible resolutions
Render negative durations with a sign or negative phrasing; or
Document negatives as out of domain and raise rather than emit a wrong positive duration.
If a behavior change is welcome, I’d be happy to implement it with tests. If negative-timedelta normalization is intentional, I can instead prepare a narrow documentation clarification. I’ll wait for maintainer direction before opening a PR.
I re-checked both issues and PR history. For naturaldelta, #18 and #171 were earlier negative-timedelta reports, and merged #173 deliberately normalized the whole timedelta with abs(). I missed that context. Sorry for the noise. I’m closing this and won’t pursue a behavior-change or further PR without maintainer invitation.
Activity
SonicHedghog commentedon Dec 2, 2026
If a behavior change is welcome, I’d be happy to implement it with tests. If negative-timedelta normalization is intentional, I can instead prepare a narrow documentation clarification. I’ll wait for maintainer direction before opening a PR.
SonicHedghog commentedon Dec 2, 2026
I re-checked both issues and PR history. For
naturaldelta, #18 and #171 were earlier negative-timedelta reports, and merged #173 deliberately normalized the whole timedelta withabs(). I missed that context. Sorry for the noise. I’m closing this and won’t pursue a behavior-change or further PR without maintainer invitation.