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: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1615>
See: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/770>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/798>
This commit is contained in:
Niklas Wimmer
2026-07-22 14:13:36 +00:00
committed by Marge Bot
parent 173d8a1d67
commit ea2c637b35
2 changed files with 10 additions and 5 deletions
+8 -3
View File
@@ -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;
}
/**
+2 -2
View File
@@ -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
{