Hi,
Lately I discovered some inaccuracy bugs in timesince (and timeuntil), and I created a ticket (
#33879). In short, the problems are when calculating a year minus one week, 2 weeks, one day etc. and also 2 years minus one or 2 days. In all such cases, Django's implementation of timesince is inaccurate, in some cases resulting in "1 year, 12 months" (for 2 years minus one or 2 days) or adding a week (for a year minus one or 2 weeks). I read the code of Django's timesince implementation and it's quite long, and I searched and found that python-dateutil already have such methods, which is possible to calculate exactly the number of days between two dates like this:
from dateutil.relativedelta import relativedelta
diff = relativedelta(date2, date1)
years = diff.years
months = diff.months
weeks = diff.days // 7
days = diff.days - weeks * 7 # ("diff.days % 7" will also work here)
This calculates exactly the number of years, months, weeks and days and not an approximation like Django's implementation. And python-dateutil is stable and I think exists even before Django. I recently started using Django's timesince function in my own website, and I like the way it's translated (currently only to English and Hebrew). Do you think it's worth using python-dateutil in the Django implementation of timesince and timeuntil?
Of course, I can also implement my own version of timesince which uses python-dateutil and doesn't use Django. But since timesince and timeuntil are built-in tags in Django, I guess many websites are using them. Isn't it better to use a more precise implementation and avoid something like "1 year, 12 months"?
Thanks,