static gboolean free_busy_instance (ECalComponent *comp, time_t instance_start, time_t instance_end, gpointer data) { icalcomponent *vfb = data; icalproperty *prop; icalparameter *param; struct icalperiodtype ipt; icaltimezone *utc_zone; utc_zone = icaltimezone_get_utc_timezone (); ipt.start = icaltime_from_timet_with_zone (instance_start, FALSE, utc_zone); ipt.end = icaltime_from_timet_with_zone (instance_end, FALSE, utc_zone); ipt.duration = icaldurationtype_null_duration (); /* add busy information to the vfb component */ prop = icalproperty_new (ICAL_FREEBUSY_PROPERTY); icalproperty_set_freebusy (prop, ipt); param = icalparameter_new_fbtype (ICAL_FBTYPE_BUSY); icalproperty_add_parameter (prop, param); icalcomponent_add_property (vfb, prop); return TRUE; }
static icalcomponent *icalmessage_new_reply_base(icalcomponent *c, const char *user, const char *msg) { icalproperty *attendee; char tmp[45]; icalcomponent *reply = icalcomponent_vanew( ICAL_VCALENDAR_COMPONENT, icalproperty_new_method(ICAL_METHOD_REPLY), icalcomponent_vanew( ICAL_VEVENT_COMPONENT, icalproperty_new_dtstamp(icaltime_from_timet_with_zone(time(0), 0, NULL)), 0), 0); icalcomponent *inner = icalmessage_get_inner(reply); icalerror_check_arg_rz(c, "c"); icalmessage_copy_properties(reply, c, ICAL_UID_PROPERTY); icalmessage_copy_properties(reply, c, ICAL_ORGANIZER_PROPERTY); icalmessage_copy_properties(reply, c, ICAL_RECURRENCEID_PROPERTY); icalmessage_copy_properties(reply, c, ICAL_SUMMARY_PROPERTY); icalmessage_copy_properties(reply, c, ICAL_SEQUENCE_PROPERTY); icalcomponent_set_dtstamp(reply, icaltime_from_timet_with_zone(time(0), 0, NULL)); if (msg != 0) { icalcomponent_add_property(inner, icalproperty_new_comment(msg)); } /* Copy this user's attendee property */ attendee = icalmessage_find_attendee(c, user); if (attendee == 0) { icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR); icalcomponent_free(reply); return 0; } icalcomponent_add_property(inner, icalproperty_new_clone(attendee)); /* Add PRODID and VERSION */ icalcomponent_add_property(reply, icalproperty_new_version("2.0")); snprintf(tmp, sizeof(tmp), "-//SoftwareStudio//NONSGML %s %s //EN", ICAL_PACKAGE, ICAL_VERSION); icalcomponent_add_property(reply, icalproperty_new_prodid(tmp)); return reply; }
icalcomponent *icalspanlist_as_vfreebusy(icalspanlist* sl, const char* organizer, const char* attendee) { icalcomponent *comp; icalproperty *p; struct icaltimetype atime = icaltime_from_timet( time(0),0); pvl_elem itr; icaltimezone *utc_zone; icalparameter *param; if (!attendee) { icalerror_set_errno(ICAL_USAGE_ERROR); return 0; } utc_zone = icaltimezone_get_utc_timezone (); comp = icalcomponent_new_vfreebusy(); icalcomponent_add_property(comp, icalproperty_new_dtstart(sl->start)); icalcomponent_add_property(comp, icalproperty_new_dtend(sl->end)); icalcomponent_add_property(comp, icalproperty_new_dtstamp(atime)); if (organizer) { icalcomponent_add_property(comp, icalproperty_new_organizer(organizer)); } icalcomponent_add_property(comp, icalproperty_new_attendee(attendee)); /* now add the freebusy sections.. */ for( itr = pvl_head(sl->spans); itr != 0; itr = pvl_next(itr)) { struct icalperiodtype period; struct icaltime_span *s = (struct icaltime_span*)pvl_data(itr); if (s->is_busy == 1) { period.start = icaltime_from_timet_with_zone (s->start, 0, utc_zone); period.end = icaltime_from_timet_with_zone (s->end, 0, utc_zone); period.duration = icaldurationtype_null_duration(); p = icalproperty_new_freebusy(period); param = icalparameter_new_fbtype(ICAL_FBTYPE_BUSY); icalproperty_add_parameter(p, param); icalcomponent_add_property(comp, p); } } return comp; }
/** * time_add_month_with_zone: * @time: A time_t value. * @months: Number of months to add. * @zone: Timezone to use. * * Adds or subtracts a number of months to/from the given time_t value, using * the given timezone. * * If the day would be off the end of the month (e.g. adding 1 month to * 30th January, would lead to an invalid day, 30th February), it moves it * down to the last day in the month, e.g. 28th Feb (or 29th in a leap year.) * * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Return value: a time_t value containing @time plus the months added. */ time_t time_add_month_with_zone (time_t time, int months, icaltimezone *zone) { struct icaltimetype tt; int day, days_in_month; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); /* Add on the number of months. */ tt.month += months; /* Save the day, and set it to 1, so we don't overflow into the next month. */ day = tt.day; tt.day = 1; /* Normalize it, fixing any month overflow. */ tt = icaltime_normalize (tt); /* If we go past the end of a month, set it to the last day. */ days_in_month = time_days_in_month (tt.year, tt.month - 1); if (day > days_in_month) day = days_in_month; tt.day = day; /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); }
/** * e2k_timestamp_to_icaltime: * @timestamp: an Exchange timestamp string * * Converts @timestamp to an #icaltimetype * * Return value: the #icaltimetype **/ struct icaltimetype e2k_timestamp_to_icaltime (const gchar *timestamp) { return icaltime_from_timet_with_zone ( e2k_parse_timestamp (timestamp), FALSE, icaltimezone_get_utc_timezone ()); }
/** * time_week_begin_with_zone: * @time: A time_t value. * @week_start_day: Day to use as the starting of the week. * @zone: Timezone to use. * * Returns the start of the week containing the given time_t, using the given * timezone. week_start_day should use the same values as mktime(), * i.e. 0 (Sun) to 6 (Sat). * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Return value: the beginning of the week. */ time_t time_week_begin_with_zone (time_t time, int week_start_day, icaltimezone *zone) { struct icaltimetype tt; int weekday, offset; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); /* Get the weekday. */ weekday = time_day_of_week (tt.day, tt.month - 1, tt.year); /* Calculate the current offset from the week start day. */ offset = (weekday + 7 - week_start_day) % 7; /* Set it to the start of the month. */ tt.day -= offset; tt.hour = 0; tt.minute = 0; tt.second = 0; /* Normalize it, to fix any overflow. */ tt = icaltime_normalize (tt); /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); }
/** * @brief * Get the occurrence as defined by the given recurrence rule, * index, and start time. This function assumes that the * time dtsart passed in is the one to start the occurrence from. * * @par NOTE: This function should be made reentrant such that * it can be looped over without having to loop over every occurrence * over and over again. * * @param[in] rrule - The recurrence rule as defined by the user * @param[in] dtstart - The start time from which to start * @param[in] tz - The timezone associated to the recurrence rule * @param[in] idx - The index of the occurrence to start counting from * * @return time_t * @retval The date of the next occurrence or -1 if the date exceeds libical's * Unix time in 2038 * */ time_t get_occurrence(char *rrule, time_t dtstart, char *tz, int idx) { #ifdef LIBICAL struct icalrecurrencetype rt; struct icaltimetype start; icaltimezone *localzone; struct icaltimetype next; struct icalrecur_iterator_impl *itr; int i; time_t next_occr = dtstart; if (rrule == NULL) return dtstart; if (tz == NULL) return -1; icalerror_clear_errno(); icalerror_set_error_state(ICAL_PARSE_ERROR, ICAL_ERROR_NONFATAL); #ifdef LIBICAL_API2 icalerror_set_errors_are_fatal(0); #else icalerror_errors_are_fatal = 0; #endif localzone = icaltimezone_get_builtin_timezone(tz); if (localzone == NULL) return -1; rt = icalrecurrencetype_from_string(rrule); start = icaltime_from_timet_with_zone(dtstart, 0, NULL); icaltimezone_convert_time(&start, icaltimezone_get_utc_timezone(), localzone); next = start; itr = (struct icalrecur_iterator_impl*) icalrecur_iterator_new(rt, start); /* Skip as many occurrences as specified by idx */ for (i = 0; i < idx && !icaltime_is_null_time(next); i++) next = icalrecur_iterator_next(itr); if (!icaltime_is_null_time(next)) { icaltimezone_convert_time(&next, localzone, icaltimezone_get_utc_timezone()); next_occr = icaltime_as_timet(next); } else next_occr = -1; /* If reached end of possible date-time return -1 */ icalrecur_iterator_free(itr); return next_occr; #else return dtstart; #endif }
static gboolean check_first_instance_cb (ECalComponent *comp, time_t instance_start, time_t instance_end, gpointer user_data) { CheckFirstInstanceData *ifs = user_data; icalcomponent *icalcomp; struct icaltimetype rid; g_return_val_if_fail (ifs != NULL, FALSE); icalcomp = e_cal_component_get_icalcomponent (comp); if (icalcomponent_get_first_property (icalcomp, ICAL_RECURRENCEID_PROPERTY) != NULL) { rid = icalcomponent_get_recurrenceid (icalcomp); } else { struct icaltimetype dtstart; dtstart = icalcomponent_get_dtstart (icalcomp); if (dtstart.zone) { rid = icaltime_from_timet_with_zone (instance_start, dtstart.is_date, dtstart.zone); } else { rid = icaltime_from_timet (instance_start, dtstart.is_date); } } ifs->matches = icaltime_compare (ifs->rid, rid) == 0; return FALSE; }
struct icaltimetype icaltime_from_timet(const time_t tm, const int is_date) { #if NO_WARN_DEPRECATED == 0 icalerror_warn( "icaltime_from_timet() is DEPRECATED, use icaltime_from_timet_with_zone() instead"); #endif return icaltime_from_timet_with_zone(tm, is_date, 0); }
/** * time_to_gdate_with_zone: * @date: Destination #GDate value. * @time: A time value. * @zone: Desired timezone for destination @date, or NULL if the UTC timezone * is desired. * * Converts a time_t value to a #GDate structure using the specified timezone. * This is analogous to g_date_set_time() but takes the timezone into account. **/ void time_to_gdate_with_zone (GDate *date, time_t time, icaltimezone *zone) { struct icaltimetype tt; g_return_if_fail (date != NULL); g_return_if_fail (time != -1); tt = icaltime_from_timet_with_zone (time, FALSE, zone ? zone : icaltimezone_get_utc_timezone ()); g_date_set_dmy (date, tt.day, tt.month, tt.year); }
/** * time_add_day_with_zone: * @time: A time_t value. * @days: Number of days to add. * @zone: Timezone to use. * * Adds or subtracts a number of days to/from the given time_t value, using * the given timezone. * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Return value: a time_t value containing @time plus the days added. */ time_t time_add_day_with_zone (time_t time, int days, icaltimezone *zone) { struct icaltimetype tt; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); /* Add/subtract the number of days. */ icaltime_adjust (&tt, days, 0, 0, 0); /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); }
static icalcomponent * create_object (void) { icalcomponent *icalcomp; struct icaltimetype now; now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "To-be-sent event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet_with_zone (icaltime_as_timet (now) + 60 * 60 * 60, 0, NULL)); return icalcomp; }
static void adjust_dtstart_day_to_rrule(icalcomponent *comp, struct icalrecurrencetype rule) { time_t now, year_start; struct icaltimetype start, comp_start, iter_start, itime; icalrecur_iterator *iter; now = time(NULL); itime = icaltime_from_timet_with_zone(now, 0, NULL); itime.month = itime.day = 1; itime.hour = itime.minute = itime.second = 0; year_start = icaltime_as_timet(itime); comp_start = icalcomponent_get_dtstart(comp); start = icaltime_from_timet_with_zone(year_start, 0, NULL); iter = icalrecur_iterator_new(rule, start); iter_start = icalrecur_iterator_next(iter); icalrecur_iterator_free(iter); if (iter_start.day != comp_start.day) { comp_start.day = iter_start.day; icalcomponent_set_dtstart(comp, comp_start); } }
//TODO: should not call libical functions directly -- better to make // a new libkcal abstraction method. QDateTime WebdavHandler::utcAsZone( const QDateTime& utc, const QString& timeZoneId ) { int daylight; QDateTime epoch; epoch.setTime_t( 0 ); time_t v = epoch.secsTo( utc ); struct icaltimetype tt = icaltime_from_timet_with_zone( v, 0 /*is_date*/, icaltimezone_get_builtin_timezone( "UTC" ) ); int offset = icaltimezone_get_utc_offset( icaltimezone_get_builtin_timezone( timeZoneId.latin1() ), &tt, &daylight ); kdDebug() << "Calculated offset of: " << offset << " of timezone: " << timeZoneId << endl; return utc.addSecs( offset ); }
/* Converts a time_t to a string, relative to the specified timezone */ gchar * timet_to_str_with_zone (time_t t, icaltimezone *zone, gboolean date_only) { struct icaltimetype itt; struct tm tm; if (t == -1) return g_strdup (_("invalid time")); itt = icaltime_from_timet_with_zone (t, FALSE, zone); tm = icaltimetype_to_tm (&itt); return e_datetime_format_format_tm ("calendar", "table", date_only ? DTFormatKindDate : DTFormatKindDateTime, &tm); }
/** * time_day_begin_with_zone: * @time: A time_t value. * @zone: Timezone to use. * * Returns the start of the day containing the given time_t, using the given * timezone. * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Return value: the beginning of the day. */ time_t time_day_begin_with_zone (time_t time, icaltimezone *zone) { struct icaltimetype tt; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); /* Set it to the start of the day. */ tt.hour = 0; tt.minute = 0; tt.second = 0; /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); }
static struct tm cal_shell_view_get_current_time (ECalendarItem *calitem, ECalShellView *cal_shell_view) { ECalShellContent *cal_shell_content; struct icaltimetype tt; icaltimezone *timezone; ECalModel *model; cal_shell_content = cal_shell_view->priv->cal_shell_content; model = e_cal_base_shell_content_get_model (E_CAL_BASE_SHELL_CONTENT (cal_shell_content)); timezone = e_cal_model_get_timezone (model); tt = icaltime_from_timet_with_zone (time (NULL), FALSE, timezone); return icaltimetype_to_tm (&tt); }
static struct tm annum_shell_view_get_current_time (ECalendarItem * calitem, AnnumShellView * prox_shell_view) { AnnumShellContent *prox_shell_content; struct icaltimetype tt; icaltimezone *timezone; ECalModel *model; prox_shell_content = prox_shell_view->priv->prox_shell_content; model = annum_shell_content_get_model (prox_shell_content); timezone = e_cal_model_get_timezone (model); tt = icaltime_from_timet_with_zone (time (NULL), FALSE, timezone); return icaltimetype_to_tm (&tt); }
/* Converts a time_t to a string, relative to the specified timezone */ gchar * timet_to_str_with_zone (time_t t, icaltimezone *zone) { struct icaltimetype itt; struct tm tm; gchar buf[256]; if (t == -1) return g_strdup (_("invalid time")); itt = icaltime_from_timet_with_zone (t, FALSE, zone); tm = icaltimetype_to_tm (&itt); e_time_format_date_and_time (&tm, config_data_get_24_hour_format (), FALSE, FALSE, buf, sizeof (buf)); return g_strdup (buf); }
/** * time_day_end_with_zone: * @time: A time_t value. * @zone: Timezone to use. * * Returns the end of the day containing the given time_t, using the given * timezone. (The end of the day is the start of the next day.) * NOTE: this function is only here to make the transition to the timezone * functions easier. New code should use icaltimetype values and * icaltime_adjust() to add or subtract days, hours, minutes & seconds. * * Return value: the end of the day. */ time_t time_day_end_with_zone (time_t time, icaltimezone *zone) { struct icaltimetype tt; /* Convert to an icaltimetype. */ tt = icaltime_from_timet_with_zone (time, FALSE, zone); /* Set it to the start of the next day. */ tt.day++; tt.hour = 0; tt.minute = 0; tt.second = 0; /* Normalize it, to fix any overflow. */ tt = icaltime_normalize (tt); /* Convert back to a time_t. */ return icaltime_as_timet_with_zone (tt, zone); }
static void find_transidx(time_t *transitions, ttinfo *types, int *trans_idx, long int num_trans, int *stdidx, int *dstidx) { time_t now, year_start; int i, found = 0; struct icaltimetype itime; now = time(NULL); itime = icaltime_from_timet_with_zone(now, 0, NULL); itime.month = itime.day = 1; itime.hour = itime.minute = itime.second = 0; year_start = icaltime_as_timet(itime); /* Set this by default */ *stdidx = (num_trans - 1); for (i = (num_trans - 1); i >= 0; --i) { if (year_start < transitions[i]) { int idx; found = 1; idx = trans_idx[i]; (types[idx].isdst) ? (*dstidx = i) : (*stdidx = i); } } /* If the transition found is the last among the list, prepare to use the last two transtions. * Using this will most likely throw the DTSTART of the resulting component off by 1 or 2 days * but it would set right by the adjustment made. * NOTE: We need to use the last two transitions only because there is no data for the future * transitions. */ if (found && (*dstidx == -1)) { *dstidx = ((*stdidx) - 1); } return; }
/* Returns the current time, for the ECalendarItem. */ static struct tm get_current_time (ECalendarItem *calitem, gpointer data) { icaltimezone *zone; struct tm tmp_tm = { 0 }; struct icaltimetype tt; /* Get the current timezone. */ zone = calendar_config_get_icaltimezone (); tt = icaltime_from_timet_with_zone (time (NULL), FALSE, zone); /* Now copy it to the struct tm and return it. */ tmp_tm.tm_year = tt.year - 1900; tmp_tm.tm_mon = tt.month - 1; tmp_tm.tm_mday = tt.day; tmp_tm.tm_hour = tt.hour; tmp_tm.tm_min = tt.minute; tmp_tm.tm_sec = tt.second; tmp_tm.tm_isdst = -1; return tmp_tm; }
static gchar * create_object (ECalClient *cal_client) { icalcomponent *icalcomp; struct icaltimetype now; gchar *uid = NULL; GError *error = NULL; g_return_val_if_fail (cal_client != NULL, NULL); now = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ()); icalcomp = icalcomponent_new (ICAL_VEVENT_COMPONENT); icalcomponent_set_summary (icalcomp, "To-be-removed event summary"); icalcomponent_set_dtstart (icalcomp, now); icalcomponent_set_dtend (icalcomp, icaltime_from_timet_with_zone (icaltime_as_timet (now) + 60 * 60 * 60, 0, NULL)); if (!e_cal_client_create_object_sync (cal_client, icalcomp, &uid, NULL, &error)) g_error ("create object sync: %s", error->message); icalcomponent_free (icalcomp); return uid; }
static ECalComponent * create_test_component (time_t start, time_t end) { ECalComponent *comp = e_cal_component_new (); ECalComponentText summary; struct icaltimetype current; e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT); /* ECalComponentDateTime dtstart, dtend; struct icaltimetype time_start, time_end; * time_start = icaltime_from_timet_with_zone (start, 0, NULL); dtstart.value = icaltime_from_timet_with_zone (start, 0, NULL); dtstart.zone = icaltimezone_get_utc_timezone (); * dtend.value = icaltime_from_timet_with_zone (end, 0, NULL); dtend.value = icaltimezone_get_utc_timezone (); e_cal_component_set_dtstart (comp, &dtstart); e_cal_component_set_dtend (comp, &dtend); */ summary.value = g_strdup_printf ("%" G_GINT64_FORMAT "- %" G_GINT64_FORMAT, (gint64) start, (gint64) end); summary.altrep = NULL; e_cal_component_set_summary (comp, &summary); g_free ((gchar *) summary.value); current = icaltime_from_timet_with_zone (time (NULL), 0, NULL); e_cal_component_set_created (comp, ¤t); e_cal_component_set_last_modified (comp, ¤t); return comp; }
/* Creates a "goto date" dialog and runs it */ void goto_dialog (GnomeCalendar *gcal) { time_t start_time; struct icaltimetype tt; int b; char *gladefile; if (dlg) { return; } dlg = g_new0 (GoToDialog, 1); /* Load the content widgets */ gladefile = g_build_filename (EVOLUTION_GLADEDIR, "goto-dialog.glade", NULL); dlg->xml = glade_xml_new (gladefile, NULL, NULL); g_free (gladefile); if (!dlg->xml) { g_message ("goto_dialog(): Could not load the Glade XML file!"); g_free (dlg); return; } if (!get_widgets (dlg)) { g_message ("goto_dialog(): Could not find all widgets in the XML file!"); g_free (dlg); return; } dlg->gcal = gcal; gnome_calendar_get_selected_time_range (dlg->gcal, &start_time, NULL); tt = icaltime_from_timet_with_zone (start_time, FALSE, gnome_calendar_get_timezone (gcal)); dlg->year_val = tt.year; dlg->month_val = tt.month - 1; dlg->day_val = tt.day; gtk_option_menu_set_history (GTK_OPTION_MENU (dlg->month), dlg->month_val); gtk_spin_button_set_value (GTK_SPIN_BUTTON (dlg->year), dlg->year_val); create_ecal (dlg); goto_dialog_init_widgets (dlg); gtk_window_set_transient_for (GTK_WINDOW (dlg->dialog), GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (gcal)))); /* set initial selection to current day */ dlg->ecal->calitem->selection_set = TRUE; dlg->ecal->calitem->selection_start_month_offset = 0; dlg->ecal->calitem->selection_start_day = tt.day; dlg->ecal->calitem->selection_end_month_offset = 0; dlg->ecal->calitem->selection_end_day = tt.day; /* Set week_start_day. Convert it to 0 (Mon) to 6 (Sun), which is what we use. */ dlg->ecal->calitem->week_start_day = (calendar_config_get_week_start_day () + 6) % 7; gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (dlg->ecal->calitem)); b = gtk_dialog_run (GTK_DIALOG (dlg->dialog)); gtk_widget_destroy (dlg->dialog); if (b == 0) goto_today (dlg); g_object_unref (dlg->xml); g_free (dlg); dlg = NULL; }
int main() { icalarray *timezones; icaltimezone *zone, *utc_zone; char *zone_location; size_t i; int ret = 0; unsigned int total_failed = 0; unsigned int total_okay = 0; unsigned int percent_failed = 0; int verbose = 0; int day; time_t start_time; struct tm start_tm; time_t curr_time; struct tm curr_tm; struct icaltimetype curr_tt; int failed = 0; int curr_failed; int zonedef_printed = 0; #if !defined(HAVE_SETENV) static char new_tz[256]; #endif set_zone_directory("../../zoneinfo"); icaltimezone_set_tzid_prefix("/softwarestudio.org/"); timezones = icaltimezone_get_builtin_timezones(); utc_zone = icaltimezone_get_utc_timezone(); /* for all known time zones... */ for (i = 0; i < timezones->num_elements; i++) { zone = (icaltimezone *)icalarray_element_at(timezones, i); zone_location = (char *)icaltimezone_get_location(zone); if (!zone_location) continue; /* * select this location for glibc: needs support for TZ=<location> * which is not POSIX */ #if defined(HAVE_SETENV) setenv("TZ", zone_location, 1); #else new_tz[0] = '\0'; strncat(new_tz, "TZ=", 255); strncat(new_tz, zone_location, 255 - strlen(new_tz)); putenv(new_tz); #endif tzset(); /* * determine current local time and date: always use midday in * the current zone and first day of first month in the year */ start_time = time(NULL); localtime_r(&start_time, &start_tm); start_tm.tm_hour = 12; start_tm.tm_min = 0; start_tm.tm_sec = 0; start_tm.tm_mday = 1; start_tm.tm_mon = 0; start_time = mktime(&start_tm); /* check time conversion for the next 365 days */ for (day = 0, curr_time = start_time; day < 365; day++, curr_time += 24 * 60 * 60) { /* determine date/time with glibc */ localtime_r(&curr_time, &curr_tm); /* determine date/time with libical */ curr_tt = icaltime_from_timet_with_zone(curr_time, 0, utc_zone); curr_tt.zone = utc_zone; /* workaround: icaltime_from_timet_with_zone() should do this, but doesn't! */ curr_tt = icaltime_convert_to_zone(curr_tt, zone); /* compare... */ curr_failed = curr_tm.tm_year + 1900 != curr_tt.year || curr_tm.tm_mon + 1 != curr_tt.month || curr_tm.tm_mday != curr_tt.day || curr_tm.tm_hour != curr_tt.hour || curr_tm.tm_min != curr_tt.minute || curr_tm.tm_sec != curr_tt.second; /* only print first failed day and first day which is okay again */ if (verbose || curr_failed != failed) { struct tm utc_tm; if (!gmtime_r(&curr_time, &utc_tm)) memset(&utc_tm, 0, sizeof(utc_tm)); printf( "%s: day %03d: %s: %04d-%02d-%02d %02d:%02d:%02d UTC = " "libc %04d-%02d-%02d %02d:%02d:%02d dst %d", zone_location, day, verbose ? (curr_failed ? "failed" : "okay") : (curr_failed ? "first failed" : "okay again"), utc_tm.tm_year + 1900, utc_tm.tm_mon + 1, utc_tm.tm_mday, utc_tm.tm_hour, utc_tm.tm_min, utc_tm.tm_sec, curr_tm.tm_year + 1900, curr_tm.tm_mon + 1, curr_tm.tm_mday, curr_tm.tm_hour, curr_tm.tm_min, curr_tm.tm_sec, curr_tm.tm_isdst); if (curr_failed) { printf(" != libical %04d-%02d-%02d %02d:%02d:%02d dst %d", curr_tt.year, curr_tt.month, curr_tt.day, curr_tt.hour, curr_tt.minute, curr_tt.second, curr_tt.is_daylight); ret = 1; } printf("\n"); failed = curr_failed; if (!zonedef_printed) { icalcomponent *comp = icaltimezone_get_component(zone); if (comp) { printf("%s\n", icalcomponent_as_ical_string(comp)); } zonedef_printed = 1; } } if (curr_failed) { total_failed++; } else { total_okay++; } } } if (total_failed || total_okay) { percent_failed = total_failed * 100 / (total_failed + total_okay); printf(" *** Summary: %lu zones tested, %u days failed, %u okay => %u%% failed ***\n", (unsigned long)timezones->num_elements, total_failed, total_okay, percent_failed); if (!icaltzutil_get_exact_vtimezones_support()) { if (!percent_failed) { ret = 0; printf(" *** Expect some small error rate with inter-operable vtimezones *** \n"); } } } icaltimezone_free_builtin_timezones(); return ret; }
/** @brief Convenience constructor. * * Returns the current day as an icaltimetype, with is_date set. */ struct icaltimetype icaltime_today(void) { return icaltime_from_timet_with_zone(time(NULL), 1, NULL); }
static ECellDateEditValue * get_dtend (ECalModelCalendar *model, ECalModelComponent *comp_data) { struct icaltimetype tt_end; if (!comp_data->dtend) { icalproperty *prop; icaltimezone *zone = NULL, *model_zone = NULL; gboolean got_zone = FALSE; prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTEND_PROPERTY); if (!prop) return NULL; tt_end = icalproperty_get_dtend (prop); if (icaltime_get_tzid (tt_end) && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_end), &zone, NULL, NULL)) got_zone = TRUE; model_zone = e_cal_model_get_timezone (E_CAL_MODEL (model)); if (got_zone) { tt_end = icaltime_from_timet_with_zone (comp_data->instance_end, tt_end.is_date, zone); if (model_zone) icaltimezone_convert_time (&tt_end, zone, model_zone); } else { tt_end = icaltime_from_timet_with_zone ( comp_data->instance_end, tt_end.is_date, model_zone); } if (!icaltime_is_valid_time (tt_end) || icaltime_is_null_time (tt_end)) return NULL; if (tt_end.is_date && icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY)) { struct icaltimetype tt_start; icaltimezone *start_zone = NULL; gboolean got_start_zone = FALSE; tt_start = icalproperty_get_dtstart (prop); if (icaltime_get_tzid (tt_start) && e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_start), &start_zone, NULL, NULL)) got_start_zone = TRUE; if (got_start_zone) { tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, start_zone); if (model_zone) icaltimezone_convert_time (&tt_start, start_zone, model_zone); } else { tt_start = icaltime_from_timet_with_zone ( comp_data->instance_start, tt_start.is_date, model_zone); } icaltime_adjust (&tt_start, 1, 0, 0, 0); /* Decrease by a day only if the DTSTART will still be before, or the same as, DTEND */ if (icaltime_compare (tt_start, tt_end) <= 0) icaltime_adjust (&tt_end, -1, 0, 0, 0); } comp_data->dtend = g_new0 (ECellDateEditValue, 1); comp_data->dtend->tt = tt_end; if (got_zone) comp_data->dtend->zone = zone; else comp_data->dtend->zone = NULL; } return e_cal_model_copy_cell_date_value (comp_data->dtend); }
/** Store timestamp of last sync. * * @param cb 3E calendar backend. * @param stamp Timestamp in local time. */ void e_cal_backend_3e_set_sync_timestamp(ECalBackend3e *cb, time_t stamp) { g_static_rw_lock_writer_lock(&cb->priv->cache_lock); e_cal_backend_cache_put_server_utc_time(cb->priv->cache, icaltime_as_ical_string(icaltime_from_timet_with_zone(stamp, 0, NULL))); g_static_rw_lock_writer_unlock(&cb->priv->cache_lock); }
/** @brief Convenience constructor. * * Returns the current time in the given timezone, as an icaltimetype. */ struct icaltimetype icaltime_current_time_with_zone(const icaltimezone *zone) { return icaltime_from_timet_with_zone(time(NULL), 0, zone); }