The Python Oracle

Comparing dateutil.relativedelta

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: RPG Blues Looping

--

Chapters
00:00 Comparing Dateutil.Relativedelta
00:30 Accepted Answer Score 11
00:58 Thank you

--

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

--

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.