#37578 new Bug

timesince() counts an extra day when a calendar month ends on February 29

Reported by: Pranjul Gupta Owned by:
Component: Utilities Version: dev
Severity: Low Keywords:
Cc: Pranjul Gupta Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

i reproduced this on django main at commit 6627fe5101. Starting from jan 29, 2024 timesince() reports “1 month, 2 weeks” on both March 13 and March 14.

from datetime import date
from django.conf import settings
from django.utils.timesince import timesince

settings.configure(USE_I18N=False)
start = date(2024, 1, 29)
print(timesince(start, date(2024, 3, 13)))  # 1 month, 2 weeks
print(timesince(start, date(2024, 3, 14)))  # 1 month, 2 weeks

i expected "1 month, 1 week" on march 13. One calendar month after jan 29 is feb 29. From there, March 13 is only 13 days . March 14 is the first date that reaches two full weeks.

Two earlier PRs proposed a fix for this and were closed: ​PR 20868 and ​PR 20870.

I’d be happy to write a regression test for the March 13/14 boundary and submit a patch if this ticket is accepted.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top