Interval equals in case of timezones #1349
-
This should be a passing test, correct? (it doesn't at the moment) I expected that equals compares two intervals regardless of timezones, so that it would tell me if two intervals are the same, regardless of timezones. So I ended up using something like this instead in my project, to compare if two intervals are the same regardless of TZ:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
An interval is equal to another interval if both their starts and ends are equal, and two datetimes are equal if they represent the same time in the same zone. So that nets out to your intervals not being equal. I think this is the right behavior for intervals to have, because the two intervals will have different results for the same methods As a simple example, consider the methods that format intervals to strings. It would be weird if two objects that considered themselves equal had divergent behavior. I would support adding a separate equality operator that only compared the epoch millis of the start and end. We don't have one for datetimes because it's easy enough to do You probably didn't want to use |
Beta Was this translation helpful? Give feedback.
An interval is equal to another interval if both their starts and ends are equal, and two datetimes are equal if they represent the same time in the same zone. So that nets out to your intervals not being equal.
I think this is the right behavior for intervals to have, because the two intervals will have different results for the same methods As a simple example, consider the methods that format intervals to strings. It would be weird if two objects that considered themselves equal had divergent behavior.
I would support adding a separate equality operator that only compared the epoch millis of the start and end. We don't have one for datetimes because it's easy enough to do
+d1 == +d2
bu…