Logo Search packages:      
Sourcecode: libical version File versions  Download package

static char * icaltimezone_get_tznames_from_vtimezone ( icalcomponent *  component  )  [static]

Gets the TZNAMEs used for the last STANDARD & DAYLIGHT components in a VTIMEZONE. If both STANDARD and DAYLIGHT components use the same TZNAME, it returns that. If they use different TZNAMEs, it formats them like "EST/EDT". The returned string should be freed by the caller.

Definition at line 366 of file icaltimezone.c.

Referenced by icaltimezone_get_vtimezone_properties().

{
    icalcomponent *comp;
    icalcomponent_kind type;
    icalproperty *prop;
    struct icaltimetype dtstart;
    struct icaldatetimeperiodtype rdate;
    const char *current_tzname;
    const char *standard_tzname = NULL, *daylight_tzname = NULL;
    struct icaltimetype standard_max_date, daylight_max_date;
    struct icaltimetype current_max_date;

    standard_max_date = icaltime_null_time();
    daylight_max_date = icaltime_null_time();

    /* Step through the STANDARD & DAYLIGHT subcomponents. */
    comp = icalcomponent_get_first_component (component, ICAL_ANY_COMPONENT);
    while (comp) {
      type = icalcomponent_isa (comp);
      if (type == ICAL_XSTANDARD_COMPONENT
          || type == ICAL_XDAYLIGHT_COMPONENT) {
          current_max_date = icaltime_null_time ();
          current_tzname = NULL;

          /* Step through the properties. We want to find the TZNAME, and
             the largest DTSTART or RDATE. */
          prop = icalcomponent_get_first_property (comp, ICAL_ANY_PROPERTY);
          while (prop) {
            switch (icalproperty_isa (prop)) {
            case ICAL_TZNAME_PROPERTY:
                current_tzname = icalproperty_get_tzname (prop);
                break;

            case ICAL_DTSTART_PROPERTY:
                dtstart = icalproperty_get_dtstart (prop);
                if (icaltime_compare (dtstart, current_max_date) > 0)
                  current_max_date = dtstart;

                break;

            case ICAL_RDATE_PROPERTY:
                rdate = icalproperty_get_rdate (prop);
                if (icaltime_compare (rdate.time, current_max_date) > 0)
                  current_max_date = rdate.time;

                break;

            default:
                break;
            }

            prop = icalcomponent_get_next_property (comp,
                                          ICAL_ANY_PROPERTY);
          }

          if (current_tzname) {
            if (type == ICAL_XSTANDARD_COMPONENT) {
                if (!standard_tzname
                  || icaltime_compare (current_max_date,
                                   standard_max_date) > 0) {
                  standard_max_date = current_max_date;
                  standard_tzname = current_tzname;
                }
            } else {
                if (!daylight_tzname
                  || icaltime_compare (current_max_date,
                                   daylight_max_date) > 0) {
                  daylight_max_date = current_max_date;
                  daylight_tzname = current_tzname;
                }
            }
          }
      }

        comp = icalcomponent_get_next_component (component,
                                     ICAL_ANY_COMPONENT);
    }

    /* Outlook (2000) places "Standard Time" and "Daylight Time" in the TZNAME
       strings, which is totally useless. So we return NULL in that case. */
    if (standard_tzname && !strcmp (standard_tzname, "Standard Time"))
      return NULL;

    /* If both standard and daylight TZNAMEs were found, if they are the same
       we return just one, else we format them like "EST/EDT". */
    if (standard_tzname && daylight_tzname) {
      unsigned int standard_len, daylight_len;
      char *tznames;

      if (!strcmp (standard_tzname, daylight_tzname))
          return strdup (standard_tzname);

      standard_len = strlen (standard_tzname);
      daylight_len = strlen (daylight_tzname);
      tznames = malloc (standard_len + daylight_len + 2);
      strcpy (tznames, standard_tzname);
      tznames[standard_len] = '/';
      strcpy (tznames + standard_len + 1, daylight_tzname);
      return tznames;
    } else {
      const char *tznames;

      /* If either of the TZNAMEs was found just return that, else NULL. */
      tznames = standard_tzname ? standard_tzname : daylight_tzname;
      return tznames ? strdup (tznames) : NULL;
    }
}


Generated by  Doxygen 1.6.0   Back to index