[california] Revert to type-specific retrieval of date/times from iCal: Bug #733319



commit fadd2c0b2bf89293ca9ac192591a8a907b23ca9c
Author: Jim Nelson <jim yorba org>
Date:   Wed Dec 3 19:23:30 2014 -0800

    Revert to type-specific retrieval of date/times from iCal: Bug #733319
    
    To prevent having a big switch-case table pulling out DATE/DATE-TIME
    values from properties, some time back changed to getting the property
    value, seeing if it was a date or date-time, and fetching that.  Nice
    and generic.
    
    However, since then there's been a number of reports of well-formed
    timed-based properties (notably DTSTAMP) as being of type DURATION or
    iCal's fall-back "X-VALUE", meaning it wasn't transformed into the
    data structure we need.  Looking through Evolution and EDS' code, it
    appears they don't use a generic access method, and I worry this is
    broken under certain use cases.
    
    So, this reverts back to the old way of looking up DATE/DATE-TIME
    directly depending on the property type.  Hopefully this will solve
    the issue some people are seeing (as I cannot reproduce it here).

 src/component/component-date-time.vala |   46 +++++++++++++++++++++++---------
 1 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/src/component/component-date-time.vala b/src/component/component-date-time.vala
index a4cf2b8..8a87907 100644
--- a/src/component/component-date-time.vala
+++ b/src/component/component-date-time.vala
@@ -47,6 +47,9 @@ public class DateTime : BaseObject, Gee.Hashable<DateTime>, Gee.Comparable<DateT
     /**
      * Returns the original iCalendar string representing the DATE/DATE-TIME property value.
      *
+     * Will be the empty string if created directly from the iCal timetype or from the result
+     * of { link adjust_duration}.
+     *
      * This does not include the iCal key string preceding the value, i.e. "DTSTAMP:"
      */
     public string value { get; private set; }
@@ -87,24 +90,41 @@ public class DateTime : BaseObject, Gee.Hashable<DateTime>, Gee.Comparable<DateT
     }
     
     private void init_from_property(iCal.icalproperty prop) throws ComponentError {
-        unowned iCal.icalvalue? prop_value = prop.get_value();
-        if (prop_value == null) {
-            throw new ComponentError.UNAVAILABLE("Property of kind %s has no associated value",
-                prop.isa().to_string());
-        }
-        
-        switch (prop_value.isa()) {
-            case iCal.icalvalue_kind.DATE_VALUE:
-                dt = prop_value.get_date();
+        // Would prefer to simply get the libical value object, determine if it's a date or date-time,
+        // and fetch it that way, but have run into repeated problems with valid DTSTAMP's returning
+        // as DURATION or X_VALUE's (even though they're properly formed in the VEVENT) ... so,
+        // going back to original strategy of pulling out the values directly based on their
+        // property type.  See https://bugzilla.gnome.org/show_bug.cgi?id=733319 for more information
+        switch (prop.isa()) {
+            case iCal.icalproperty_kind.DTSTAMP_PROPERTY:
+                dt = prop.get_dtstamp();
+            break;
+            
+            case iCal.icalproperty_kind.DTSTART_PROPERTY:
+                dt = prop.get_dtstart();
+            break;
+            
+            case iCal.icalproperty_kind.DTEND_PROPERTY:
+                dt = prop.get_dtend();
+            break;
+            
+            case iCal.icalproperty_kind.EXDATE_PROPERTY:
+                dt = prop.get_exdate();
+            break;
+            
+            case iCal.icalproperty_kind.RECURRENCEID_PROPERTY:
+                dt = prop.get_recurrenceid();
             break;
             
-            case iCal.icalvalue_kind.DATETIME_VALUE:
-                dt = prop_value.get_datetime();
+            // TODO: Better support for RDATE; see https://tools.ietf.org/html/rfc5545#section-3.8.5.2
+            case iCal.icalproperty_kind.RDATE_PROPERTY:
+                iCal.icaldatetimeperiodtype dtperiod = prop.get_rdate();
+                dt = dtperiod.time;
             break;
             
             default:
-                throw new ComponentError.INVALID("%s not a DATE/DATE-TIME value: %s (%s)",
-                    prop.isa().to_string(), prop_value.isa().to_string(), prop.as_ical_string());
+                throw new ComponentError.INVALID("%s not a known DATE/DATE-TIME property type: %s (%s)",
+                    prop.isa().to_string(), prop.get_value().isa().to_string(), prop.as_ical_string());
         }
         
         if (iCal.icaltime_is_null_time(dt) != 0)


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