range: Handle zero-length ranges when calculating overlap
Zero length ranges, such as for events without a DTEND could be considered to overlap a range if they were at exactly the end of the range. The end of a range however is the first date that is supposed to not overlap, so a zero-length range on exactly this point should not be considered overlapping. This fixes cases where all-day events from the next month could show up on the same day of the current month if they did not have a DTEND. This also adds tests for all possible cases of such zero-length events overlapping. Fixes https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/701
This commit is contained in:
committed by
Georges Basile Stavracas Neto
parent
ce969c35b7
commit
44e2420645
+19
-1
@@ -320,7 +320,25 @@ gcal_range_calculate_overlap (GcalRange *a,
|
||||
}
|
||||
else if (a_end_b_end_diff == 0)
|
||||
{
|
||||
if (a_start_b_start_diff < 0)
|
||||
gint a_start_b_end_diff;
|
||||
gint a_end_b_start_diff;
|
||||
|
||||
a_start_b_end_diff = compare_func (a->range_start, b->range_end);
|
||||
a_end_b_start_diff = compare_func (a->range_end, b->range_start);
|
||||
|
||||
if (a_start_b_end_diff >= 0)
|
||||
{
|
||||
/* Case 5.i for zero length A */
|
||||
overlap = GCAL_RANGE_NO_OVERLAP;
|
||||
position = GCAL_RANGE_AFTER;
|
||||
}
|
||||
else if (a_end_b_start_diff <= 0)
|
||||
{
|
||||
/* Case 5.ii for zero length B */
|
||||
overlap = GCAL_RANGE_NO_OVERLAP;
|
||||
position = GCAL_RANGE_BEFORE;
|
||||
}
|
||||
else if (a_start_b_start_diff < 0)
|
||||
{
|
||||
/* Case 2.iii */
|
||||
overlap = GCAL_RANGE_SUPERSET;
|
||||
|
||||
@@ -159,6 +159,38 @@ static struct {
|
||||
GCAL_RANGE_NO_OVERLAP,
|
||||
GCAL_RANGE_AFTER,
|
||||
},
|
||||
|
||||
/* Zero length */
|
||||
{
|
||||
{ "2020-03-10T00:00:00", "2020-03-15T00:00:00" },
|
||||
{ "2020-03-15T00:00:00", "2020-03-15T00:00:00" },
|
||||
GCAL_RANGE_NO_OVERLAP,
|
||||
GCAL_RANGE_BEFORE,
|
||||
},
|
||||
{
|
||||
{ "2020-03-10T00:00:00", "2020-03-15T00:00:00" },
|
||||
{ "2020-03-10T00:00:00", "2020-03-10T00:00:00" },
|
||||
GCAL_RANGE_SUPERSET,
|
||||
GCAL_RANGE_AFTER,
|
||||
},
|
||||
{
|
||||
{ "2020-03-15T00:00:00", "2020-03-15T00:00:00" },
|
||||
{ "2020-03-10T00:00:00", "2020-03-15T00:00:00" },
|
||||
GCAL_RANGE_NO_OVERLAP,
|
||||
GCAL_RANGE_AFTER,
|
||||
},
|
||||
{
|
||||
{ "2020-03-10T00:00:00", "2020-03-10T00:00:00" },
|
||||
{ "2020-03-10T00:00:00", "2020-03-15T00:00:00" },
|
||||
GCAL_RANGE_SUBSET,
|
||||
GCAL_RANGE_BEFORE,
|
||||
},
|
||||
{
|
||||
{ "2020-03-10T00:00:00", "2020-03-10T00:00:00" },
|
||||
{ "2020-03-10T00:00:00", "2020-03-10T00:00:00" },
|
||||
GCAL_RANGE_EQUAL,
|
||||
GCAL_RANGE_MATCH,
|
||||
},
|
||||
};
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user