The Python Oracle

Comparing dateutil.relativedelta

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC D Schuberts Piano Sonata D 850 in D

--

Chapters
00:00 Question
00:35 Accepted answer (Score 10)
01:11 Thank you

--

Full question
https://stackoverflow.com/questions/1170...

Question links:
[image]: https://i.stack.imgur.com/Tddqy.png

Accepted answer links:
[open bug]: https://bugs.launchpad.net/dateutil/+bug...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python

#avk47



ACCEPTED ANSWER

Score 11


dateutil.relativedelta doesn't implement __cmp__ sensibly, so instances can't be compared. There's an open bug on the issue; the argument that it doesn't make sense to say whether 29 days or 1 month is greater, and that therefore the whole thing falls back on python's default comparisons seems a bit flimsy to me, but that's just an opinion.

Depending on what you're actually doing, using datetime.timedelta may be a better solution.