core/event: Fix schedule comparison function

Fixes a few problems in the schedule comparison code:

- Same recurrence pointer short-circuits to TRUE: a pointer to the
  same recurrence is not a sufficient condition, because the dates
  could still be different (this is especially true if the recurrence
  is NULL for both events, but also holds if that is not the case).
  Also deleted the explicit check if only one of the recurrence
  pointers is NULL, because that is the first thing that is checked
  in `gcal_recurrence_is_equal()` anyway.
- Date comparisons only check if the date moved into a specific
  direction: the correct logic is to check if they are not the same,
  no matter in which direction the date moved.
- The time is not compared: for non all-day events, it is necessary
  to compare the time values too. The glib function that is now used
  for that also checks the date, so these checks can be collapsed
  into one.

For the second and third point it seems like some things got a bit
mixed up in
https://gitlab.gnome.org/GNOME/gnome-calendar/-/commit/2ee6dfc5e7bd5823bee5029a7ac3a32d3c247ba9:

- The `gcal_schedule_section_changed()` implementation already used the
  `g_date_time_equal()` function (which is now used again).
- It was `gcal_schedule_section_day_changed()` which only compared the
  dates using `gcal_date_time_compare_date()`, but this function was
  only used for edits to recurring events to determine whether to
  allow changing all instances. This commit now exposes a regression
  in this part of the code, which is tracked separately in
  https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1613.

Fixes: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1612>
See: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/783>
See: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/work_items/1613>
Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/792>
This commit is contained in:
Niklas Wimmer
2026-07-22 10:27:57 -04:00
committed by Hari Rana
parent a1b55b5ca9
commit 81954048f9
+7 -7
View File
@@ -1755,11 +1755,6 @@ gcal_event_schedule_equal (GcalEvent *event1,
recurrence1 = gcal_event_get_recurrence (event1);
recurrence2 = gcal_event_get_recurrence (event2);
if (recurrence1 == recurrence2)
GCAL_RETURN (TRUE);
if (!recurrence1 != !recurrence2)
GCAL_RETURN (FALSE);
if (!gcal_recurrence_is_equal (recurrence1, recurrence2))
GCAL_RETURN (FALSE);
if (gcal_event_get_all_day (event1) != gcal_event_get_all_day (event2))
@@ -1771,8 +1766,13 @@ gcal_event_schedule_equal (GcalEvent *event1,
date_end1 = gcal_event_get_date_end (event1);
date_end2 = gcal_event_get_date_end (event2);
if (gcal_date_time_compare_date (date_start1, date_start2) < 0 ||
gcal_date_time_compare_date (date_end1, date_end2) > 0)
/*
* The same time instant in two different time zones will compare
* equal, so timezones are checked separately below to catch a
* manual timezone conversion.
*/
if (!g_date_time_equal (date_start1, date_start2) ||
!g_date_time_equal (date_end1, date_end2))
GCAL_RETURN (FALSE);
date_start_tz1 = g_date_time_get_timezone (date_start1);