From ea2c637b356150794c11e758c51030a3b6ef396e Mon Sep 17 00:00:00 2001 From: Niklas Wimmer Date: Wed, 8 Jul 2026 11:27:57 +0200 Subject: [PATCH] core/range: Fix compare function Fixes a regression from https://gitlab.gnome.org/GNOME/gnome-calendar/-/commit/62345668748b571939c1c7b441e44664a05a0287 Essentially, `gcal_range_compare()` is just a faster subset of `gcal_range_calculate_overlap()`. The commit that introduced this regression accidentally flipped the sign of the compare function, which made it no longer match with the implementation of overlap. The function's implementation also did not match its doc comment, returning any integer instead of only `-1`, `0` or `1`. Since the behavior described in the doc comment is more commonly used for comparison functions, the implementation was adjusted to match it. To avoid any such failures in the future, the next commits will add tests to validate. Fixes: See: Part-of: --- src/core/gcal-range.c | 11 ++++++++--- src/core/gcal-range.h | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/gcal-range.c b/src/core/gcal-range.c index f9b4cde8..8360466a 100644 --- a/src/core/gcal-range.c +++ b/src/core/gcal-range.c @@ -507,12 +507,17 @@ gcal_range_compare (GcalRange *a, &start_timestamp_a, &end_timestamp_a, &start_timestamp_b, &end_timestamp_b); - result = start_timestamp_b - start_timestamp_a; + result = start_timestamp_a - start_timestamp_b; if (result == 0) - result = end_timestamp_b - end_timestamp_a; + result = end_timestamp_a - end_timestamp_b; - return result; + if (result < 0) + return GCAL_RANGE_BEFORE; + else if (result > 0) + return GCAL_RANGE_AFTER; + else + return GCAL_RANGE_MATCH; } /** diff --git a/src/core/gcal-range.h b/src/core/gcal-range.h index e967ba34..3c1b8373 100644 --- a/src/core/gcal-range.h +++ b/src/core/gcal-range.h @@ -51,10 +51,10 @@ typedef enum * GcalRangePosition: * * @GCAL_RANGE_BEFORE: range @a is before @b + * @GCAL_RANGE_MATCH: range @a is equal to @b * @GCAL_RANGE_AFTER: range @a is after @b * - * The position of @a relative to @b. When the ranges are exactly equal, it - * is undefined. + * The position of @a relative to @b. */ typedef enum {