Comparisons of Time and TimeDelta#1171
Conversation
|
@taldcroft - Should have ping you in the commit and shold also have added hat without this commit, comparisons are already defined, but give output I do not understand the logic of. e.g., |
|
@mhvk - I took a quick look at your compare operations, and it's probably OK but I'll need to think about it a little (and some other obligations are pressing). See also #601. In quick response to the question about the current behavior of compare, this is just something that is in the object base class. I remember reading what's actually being compared, but I forget, maybe |
|
@taldcroft - OK, no hurry, and sorry I missed #601. The fact that objects already allow comparisons seems all the more reason to implement something that at least does it more or less right! As you'll have seen, I do the comparison on tai, which is hopefully what people would expect. |
|
@taldcroft - also for these time comparisons, OK to go in? |
There was a problem hiding this comment.
This seems a bit redundant. Assuming you didn't want an object with a class that is a subclass of the other object to be comparable, this is equivalent to self.__class__ is other.__class__.
|
@iguananaut - agreed on the simplification; done. |
There was a problem hiding this comment.
Can you just do:
self_tai = self.tai
other_tai = other.tai
return (self_tai.jd1 - other_tai.jd1 + self_tai.jd2 - other_tai.jd2)
I think this should work, but maybe there is something I'm missing. Using those properties instead of the internal _time attributes does the shaped_like_input already, so you could remove the method below and clean up the code a lot. But like I said maybe there was something I didn't think of.
|
@taldcroft - yes, much nicer. Now done. Also added some tests for all comparisons to ensure I didn't miss one in the cut-and-paste actions. |
Add comparisons of Time and TimeDelta. Closes #601.
Procrastinating on things I should really be doing, I implemented comparisons of
TimeandTimeDeltaobjects, with comparisons only possible if the two are the same type (when it seemed without ambiguity). Setting up with:One gets: