[evolution-data-server/gnome-41] I#371 - e-cal-util: Fix timezone clamp with DUE date only



commit 09fe4b4ff541c6a2b1a7a33c81dd8228088a30d7
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jan 4 09:36:39 2022 +0100

    I#371 - e-cal-util: Fix timezone clamp with DUE date only
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/371

 src/calendar/libecal/e-cal-util.c | 31 ++++++++++++++++++++++++++++++-
 tests/libecal/test-cal-utils.c    | 15 +++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
---
diff --git a/src/calendar/libecal/e-cal-util.c b/src/calendar/libecal/e-cal-util.c
index e1b6dbb61..8e064cdfa 100644
--- a/src/calendar/libecal/e-cal-util.c
+++ b/src/calendar/libecal/e-cal-util.c
@@ -3100,9 +3100,16 @@ e_cal_util_clamp_vtimezone (ICalComponent *vtimezone,
        g_return_if_fail (I_CAL_IS_COMPONENT (vtimezone));
        g_return_if_fail (i_cal_component_isa (vtimezone) == I_CAL_VTIMEZONE_COMPONENT);
        g_return_if_fail (I_CAL_IS_TIME ((ICalTime *) from));
-       if (to)
+       if (to) {
                g_return_if_fail (I_CAL_IS_TIME ((ICalTime *) to));
 
+               if (i_cal_time_is_null_time (to) || !i_cal_time_is_valid_time (to))
+                       to = NULL;
+       }
+
+       if (i_cal_time_is_null_time (from) || !i_cal_time_is_valid_time (from))
+               return;
+
        e_cal_util_clamp_vtimezone_subcomps (vtimezone, I_CAL_XSTANDARD_COMPONENT, from, to);
        e_cal_util_clamp_vtimezone_subcomps (vtimezone, I_CAL_XDAYLIGHT_COMPONENT, from, to);
 }
@@ -3139,6 +3146,12 @@ e_cal_util_clamp_vtimezone_by_component (ICalComponent *vtimezone,
                recurid = i_cal_property_get_recurrenceid (prop);
 
                dtend = i_cal_component_get_dtend (component);
+
+               if (dtend && (i_cal_time_is_null_time (dtend) || !i_cal_time_is_valid_time (dtend))) {
+                       g_object_unref (dtend);
+                       dtend = i_cal_component_get_due (component);
+               }
+
                if (dtend && i_cal_time_compare (recurid, dtend) >= 0) {
                        g_clear_object (&dtend);
                        dtend = recurid;
@@ -3149,10 +3162,26 @@ e_cal_util_clamp_vtimezone_by_component (ICalComponent *vtimezone,
                g_object_unref (prop);
        } else if (!e_cal_util_component_has_rrules (component)) {
                dtend = i_cal_component_get_dtend (component);
+
+               if (dtend && (i_cal_time_is_null_time (dtend) || !i_cal_time_is_valid_time (dtend))) {
+                       g_object_unref (dtend);
+                       dtend = i_cal_component_get_due (component);
+               }
+
+               if (dtend && (i_cal_time_is_null_time (dtend) || !i_cal_time_is_valid_time (dtend)))
+                       g_clear_object (&dtend);
+
                if (!dtend)
                        dtend = g_object_ref (dtstart);
        }
 
+       if (i_cal_time_is_null_time (dtstart) || !i_cal_time_is_valid_time (dtstart)) {
+               g_clear_object (&dtstart);
+
+               if (dtend && !i_cal_time_is_null_time (dtend) && i_cal_time_is_valid_time (dtend))
+                       dtstart = g_object_ref (dtend);
+       }
+
        e_cal_util_clamp_vtimezone (vtimezone, dtstart, dtend);
 
        g_clear_object (&dtstart);
diff --git a/tests/libecal/test-cal-utils.c b/tests/libecal/test-cal-utils.c
index 4469e57b2..36b1fe9af 100644
--- a/tests/libecal/test-cal-utils.c
+++ b/tests/libecal/test-cal-utils.c
@@ -203,6 +203,21 @@ test_clamp_vtimezone (ETestServerFixture *fixture,
        g_object_unref (comp);
 
        g_object_unref (vtimezone);
+       vtimezone = i_cal_component_new_from_string (vtimezone_str);
+
+       comp = i_cal_component_new_from_string (
+               "BEGIN:VTODO\r\n"
+               "UID:1\r\n"
+               "DUE:19821004T080000Z\r\n"
+               "END:VTODO\r\n");
+       g_assert_nonnull (comp);
+
+       e_cal_util_clamp_vtimezone_by_component (vtimezone, comp);
+       g_assert_cmpint (i_cal_component_count_components (vtimezone, I_CAL_XDAYLIGHT_COMPONENT), ==, 1);
+       g_assert_cmpint (i_cal_component_count_components (vtimezone, I_CAL_XSTANDARD_COMPONENT), ==, 1);
+
+       g_object_unref (comp);
+       g_object_unref (vtimezone);
 }
 
 gint


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]