4 ms·
You don't need to convert them to UTC, just one to the timezone of the other, but yes. "a.is_same_instant(b)" is a lot more clear to me than "a == b", especiall
by nly 4y ago
You don't need to convert them to UTC, just one to the timezone of the other, but yes. "a.is_same_instant(b)" is a lot more clear to me than "a == b", especially in a dynamic language where it might not be obvious what the types involved are.
- stavros 4y agoHm, I don't know, I guess == on datetimes means "is the same instant" to me.
- rzzzt 4y agoNoone else has to guess (or go and inspect what an overloaded comparison operator actually does) if there is a meaningful name attached to the comparison, like in the parent comment.
- stavros 4y agoSure, but there's also a reason we don't have `x.is_numerically_equal_to(3)`.
- fdupress 4y agoAnd that reason is that there is a canonical definition of what it means for two numbers to be equal. The fact that your intuition of "these two timestamps are equal" is "these two timestamps denotes the same instant" seems problematic when we know that the notions of timestamps and time are not in fact aligned (because, for example, of leap seconds).
- ur-whale 4y agoThat's what it means to you But an API should never get into a place where your personal choices should matter and various incompatible interpretations potentially make sense to different people.
- raverbashing 4y agoThis sounds like turning a good API into an unreadable mess. And no, it is not pythonic No, most people do want to compare times in different TZs without the extra cruft.
- sanderjd 4y agoIt would be turning a really bad API that is a constant source of errors into a slightly better and less error prone API. It's totally possible that "pythonic" means "error prone", but that would not be something to tout proudly if so. I think a better API would be to have a different types for timezone- naive vs. aware datetimes, and a canonical way to convert either of those types into an instant in time (requiring a timezone be attached for the naive type). Then the instants in time could be compared with the equals operator without confusion.
- raverbashing 4y ago> It's totally possible that "pythonic" means "error prone" Those who say that don't know what it means. And given how much I have to deal with crap APIs that disregard those principles it's safe to ignore discussions leading elsewhere
- sanderjd 4y agoOk, let me take this a bit more seriously. What "pythonic" principles does the existing API maintain that the proposed "crap API" disregards?