From 8084980f9409e7f711c3a3e72ae1e505b2808a4d Mon Sep 17 00:00:00 2001 From: Peter Byfield Date: Thu, 30 Jan 2025 11:47:27 +0100 Subject: [PATCH] Reverse order of min in FiniteDatetimeRange.intersection In https://github.com/octoenergy/xocto/pull/187 the implementation of FiniteDatetimeRange.intersection was optimised. This introduced a very subtle change in behaviour. Previously when left.end was equal to right.end then the right.end was favoured. In https://github.com/octoenergy/xocto/pull/187 the implementation was (unintentionally) changed to favour left.end. This change reverses that, to again favour right.end. This really shouldn't matter, but it can be signidicant when the TZ of left and right are different. Eventually we'd like to prevent this kind of mixed TZ behaviour (see https://github.com/octoenergy/xocto/issues/192), but in the short term it seems reasonable to make this tiny change to make things consistent again with how they were before. --- xocto/ranges.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xocto/ranges.py b/xocto/ranges.py index 2bd2791..519dfdb 100644 --- a/xocto/ranges.py +++ b/xocto/ranges.py @@ -860,7 +860,7 @@ def intersection( if left.end <= right.start: return None else: - return FiniteDatetimeRange(right.start, min(left.end, right.end)) + return FiniteDatetimeRange(right.start, min(right.end, left.end)) base_intersection = super().intersection(other) if base_intersection is None: