aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/cal-util/cal-recur.c
diff options
context:
space:
mode:
authorDamon Chaplin <damon@ximian.com>2001-10-23 08:23:42 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-10-23 08:23:42 +0800
commit04bda8ad1e0cb676d711dbf0f22ff9f4fb615891 (patch)
tree7f1ff1303c52e9b48a0006c500b204902b9d77c5 /calendar/cal-util/cal-recur.c
parent68de308a89a844dcc579e1d9f24d7813d645c956 (diff)
downloadgsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.gz
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.tar.zst
gsoc2013-evolution-04bda8ad1e0cb676d711dbf0f22ff9f4fb615891.zip
added setDefaultTimezone() method.
2001-10-22 Damon Chaplin <damon@ximian.com> * idl/evolution-calendar.idl: added setDefaultTimezone() method. * pcs/cal-backend.c (cal_backend_get_default_timezone): (cal_backend_set_default_timezone): new functions to call class methods. * pcs/cal-backend-file.c: lots of changes to handle the default timezone and use it. * pcs/query.c: use the default timezone. * gui/dialogs/task-details-page.c (date_changed_cb): initialized completed_tt. * gui/dialogs/event-page.c: changed it to handle DATE values. The 'All Day Event' checkbox is only set now when the DTSTART and DTEND are DATE values. * gui/dialogs/comp-editor-util.c (comp_editor_free_dates): free the CalComponentDateTime structs as well. * gui/e-tasks.c: set the default timezone on the server. * gui/tag-calendar.c: * gui/gnome-cal.c: * gui/e-week-view.c: * gui/e-day-view.c: updates to handle DATE values. * gui/e-calendar-table.c (date_compare_cb): updated to use the new ECellDateEditValue values, so it now works. (percent_compare_cb): updated to use GPOINTER_TO_INT values. (e_calendar_table_init): use an ECellPercent for the percent field and an ECellDateEditText for the date fields. * gui/comp-util.c (cal_comp_util_compare_event_timezones): return TRUE if the DTSTART or DTEND is a DATE value. We don't want to show the timezone icons for DATE values. * gui/comp-editor-factory.c (resolve_pending_requests): set the default timezone on the server. * gui/calendar-model.c: major changes to support sorting properly. For date and percent fields we now use subclasses of ECellText, so we don't use a char* as the model value. For the percent field we now use a GINT_TO_POINTER. For the date fields we now use a ECellDateEditValue* as the value. * gui/calendar-config.c (calendar_config_configure_e_cell_date_edit): set the timezone and use_24_hour flags of the new ECellDateEditText. * conduits/todo/todo-conduit.c (pre_sync): * conduits/calendar/calendar-conduit.c (pre_sync): set the default timezone on the server. * cal-util/timeutil.c (time_days_in_month): removed debug message. * cal-util/test-recur.c: try to handle timezones in the iCalendar file properly, and updated to pass default timezone. * cal-util/cal-util.c (cal_util_generate_alarms_for_comp): (cal_util_generate_alarms_for_list): added default timezone argument. * cal-util/cal-recur.c: changed many of the functions to take a default timezone, to use to resolve DATE and floating DATE-TIME values. * cal-client/cal-client.c (cal_client_set_default_timezone): new function to set the default timezone. (cal_client_ensure_timezone_on_server): new function to ensure that a given timezone is on the server. * gui/e-cell-date-edit-text.c: new subclass of ECellText to display and edit a date value. * cal-util/cal-recur.c (cal_obj_byday_expand_monthly): changed week_num to -week_num when calculating the weeks to go back from the end of the month for things like BYDAY=-2WE. Fixes bug #11525. (cal_recur_generate_instances_of_rule): only go up to MAX_YEAR (2037). We can't really handle anything past that anyway. (cal_recur_ensure_rule_end_date): initialize cb_date.end_date to 0, so if the RULE doesn't generate COUNT instances we save 0 as the time_t. svn path=/trunk/; revision=13920
Diffstat (limited to 'calendar/cal-util/cal-recur.c')
-rw-r--r--calendar/cal-util/cal-recur.c123
1 files changed, 91 insertions, 32 deletions
diff --git a/calendar/cal-util/cal-recur.c b/calendar/cal-util/cal-recur.c
index 83a0bccae9..28b1be9aec 100644
--- a/calendar/cal-util/cal-recur.c
+++ b/calendar/cal-util/cal-recur.c
@@ -104,8 +104,13 @@
* spec.
*/
+/* This is the maximum year we will go up to (inclusive). Since we use time_t
+ values we can't go past 2037 anyway, and some of our VTIMEZONEs may stop
+ at 2037 as well. */
+#define MAX_YEAR 2037
+
/* Define this for some debugging output. */
-#if 0
+#if 1
#define CAL_OBJ_DEBUG 1
#endif
@@ -264,11 +269,13 @@ static void cal_recur_generate_instances_of_rule (CalComponent *comp,
CalRecurInstanceFn cb,
gpointer cb_data,
CalRecurResolveTimezoneFn tz_cb,
- gpointer tz_cb_data);
+ gpointer tz_cb_data,
+ icaltimezone *default_timezone);
static CalRecurrence * cal_recur_from_icalproperty (icalproperty *prop,
gboolean exception,
- icaltimezone *zone);
+ icaltimezone *zone,
+ gboolean convert_end_date);
static gint cal_recur_ical_weekday_to_weekday (enum icalrecurrencetype_weekday day);
static void cal_recur_free (CalRecurrence *r);
@@ -294,6 +301,7 @@ static gboolean generate_instances_for_chunk (CalComponent *comp,
CalObjTime *chunk_end,
gint duration_days,
gint duration_seconds,
+ gboolean convert_end_date,
CalRecurInstanceFn cb,
gpointer cb_data);
@@ -487,7 +495,8 @@ static gboolean cal_recur_ensure_rule_end_date_cb (CalComponent *comp,
time_t instance_start,
time_t instance_end,
gpointer data);
-static time_t cal_recur_get_rule_end_date (icalproperty *prop);
+static time_t cal_recur_get_rule_end_date (icalproperty *prop,
+ icaltimezone *default_timezone);
static void cal_recur_set_rule_end_date (icalproperty *prop,
time_t end_date);
@@ -613,7 +622,8 @@ cal_recur_generate_instances (CalComponent *comp,
CalRecurInstanceFn cb,
gpointer cb_data,
CalRecurResolveTimezoneFn tz_cb,
- gpointer tz_cb_data)
+ gpointer tz_cb_data,
+ icaltimezone *default_timezone)
{
#if 0
g_print ("In cal_recur_generate_instances comp: %p\n", comp);
@@ -621,7 +631,8 @@ cal_recur_generate_instances (CalComponent *comp,
g_print (" end : %li - %s", end, ctime (&end));
#endif
cal_recur_generate_instances_of_rule (comp, NULL, start, end,
- cb, cb_data, tz_cb, tz_cb_data);
+ cb, cb_data, tz_cb, tz_cb_data,
+ default_timezone);
}
@@ -647,7 +658,8 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
CalRecurInstanceFn cb,
gpointer cb_data,
CalRecurResolveTimezoneFn tz_cb,
- gpointer tz_cb_data)
+ gpointer tz_cb_data,
+ icaltimezone *default_timezone)
{
CalComponentDateTime dtstart, dtend;
time_t dtstart_time, dtend_time;
@@ -656,11 +668,12 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
CalObjTime interval_start, interval_end, event_start, event_end;
CalObjTime chunk_start, chunk_end;
gint days, seconds, year;
- gboolean single_rule;
+ gboolean single_rule, convert_end_date = FALSE;
icaltimezone *start_zone = NULL, *end_zone = NULL;
g_return_if_fail (comp != NULL);
g_return_if_fail (cb != NULL);
+ g_return_if_fail (tz_cb != NULL);
g_return_if_fail (start >= -1);
g_return_if_fail (end >= -1);
@@ -675,15 +688,18 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
goto out;
}
- /* FIXME: All floating times, including those from recurrence rules,
- should be converted to the current timezone, otherwise the time_t
- values may be outside the given range. This may also mean that
- we need to add a timezone argument to the IDL method. */
-
- if (dtstart.tzid && tz_cb)
+ /* For DATE-TIME values with a TZID, we use the supplied callback to
+ resolve the TZID. For DATE values and DATE-TIME values without a
+ TZID (i.e. floating times) we use the default timezone. */
+ if (dtstart.tzid && !dtstart.value->is_date) {
start_zone = (*tz_cb) (dtstart.tzid, tz_cb_data);
- if (dtend.tzid && tz_cb)
- end_zone = (*tz_cb) (dtend.tzid, tz_cb_data);
+ } else {
+ start_zone = default_timezone;
+
+ /* Flag that we need to convert the saved ENDDATE property
+ to the default timezone. */
+ convert_end_date = TRUE;
+ }
dtstart_time = icaltime_as_timet_with_zone (*dtstart.value,
start_zone);
@@ -691,8 +707,22 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
start = dtstart_time;
/* FIXME: DURATION could be used instead, couldn't it? - Damon */
- if (!dtend.value) {
+
+ /* If there is no DTEND, then use the same as the DTSTART. For
+ DATE-TIME values that means we will just have a single point in
+ time. For DATE values it means we end up with the entire day. */
+ if (!dtend.value)
*dtend.value = *dtstart.value;
+
+ if (dtend.tzid && !dtend.value->is_date) {
+ end_zone = (*tz_cb) (dtend.tzid, tz_cb_data);
+ } else {
+ end_zone = default_timezone;
+ }
+
+ /* If DTEND is a DATE value, we add 1 day to it so that it includes
+ the entire day. */
+ if (dtend.value->is_date) {
dtend.value->hour = 0;
dtend.value->minute = 0;
dtend.value->second = 0;
@@ -768,7 +798,7 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
Though this does mean that we sometimes do a lot more work than
is necessary, e.g. if COUNT is set to something quite low. */
for (year = interval_start.year;
- end == -1 || year <= interval_end.year;
+ (end == -1 || year <= interval_end.year) && year <= MAX_YEAR;
year++) {
chunk_start = interval_start;
chunk_start.year = year;
@@ -801,6 +831,7 @@ cal_recur_generate_instances_of_rule (CalComponent *comp,
start,
&chunk_start, &chunk_end,
days, seconds,
+ convert_end_date,
cb, cb_data))
break;
}
@@ -833,9 +864,13 @@ array_to_list (short *array, int max_elements)
/**
* cal_recur_from_icalproperty:
- * @ir: An RRULE or EXRULE #icalproperty.
+ * @prop: An RRULE or EXRULE #icalproperty.
+ * @exception: TRUE if this is an EXRULE rather than an RRULE.
* @zone: The DTSTART timezone, used for converting the UNTIL property if it
* is given as a DATE value.
+ * @convert_end_date: TRUE if the saved end date needs to be converted to the
+ * given @zone timezone. This is needed if the DTSTART is a DATE or floating
+ * time.
*
* Converts an #icalproperty to a #CalRecurrence. This should be
* freed using the cal_recur_free() function.
@@ -844,7 +879,7 @@ array_to_list (short *array, int max_elements)
**/
static CalRecurrence *
cal_recur_from_icalproperty (icalproperty *prop, gboolean exception,
- icaltimezone *zone)
+ icaltimezone *zone, gboolean convert_end_date)
{
struct icalrecurrencetype ir;
CalRecurrence *r;
@@ -863,8 +898,10 @@ cal_recur_from_icalproperty (icalproperty *prop, gboolean exception,
r->interval = ir.interval;
if (ir.count != 0) {
- /* If COUNT is set, we use the pre-calculated enddate. */
- r->enddate = cal_recur_get_rule_end_date (prop);
+ /* If COUNT is set, we use the pre-calculated enddate.
+ Note that this can be 0 if the RULE doesn't actually
+ generate COUNT instances. */
+ r->enddate = cal_recur_get_rule_end_date (prop, convert_end_date ? zone : NULL);
} else {
if (icaltime_is_null_time (ir.until)) {
/* If neither COUNT or UNTIL is set, the event
@@ -1033,6 +1070,7 @@ generate_instances_for_chunk (CalComponent *comp,
CalObjTime *chunk_end,
gint duration_days,
gint duration_seconds,
+ gboolean convert_end_date,
CalRecurInstanceFn cb,
gpointer cb_data)
{
@@ -1079,7 +1117,8 @@ generate_instances_for_chunk (CalComponent *comp,
CalRecurrence *r;
prop = elem->data;
- r = cal_recur_from_icalproperty (prop, FALSE, zone);
+ r = cal_recur_from_icalproperty (prop, FALSE, zone,
+ convert_end_date);
tmp_occs = cal_obj_expand_recurrence (event_start, zone, r,
chunk_start,
@@ -1146,7 +1185,8 @@ generate_instances_for_chunk (CalComponent *comp,
CalRecurrence *r;
prop = elem->data;
- r = cal_recur_from_icalproperty (prop, FALSE, zone);
+ r = cal_recur_from_icalproperty (prop, FALSE, zone,
+ convert_end_date);
tmp_occs = cal_obj_expand_recurrence (event_start, zone, r,
chunk_start,
@@ -2986,8 +3026,15 @@ cal_obj_byday_expand_monthly (RecurData *recur_data,
occ->day = time_days_in_month (occ->year,
occ->month);
last_weekday = cal_obj_time_weekday (occ);
+
+ /* This calculates the number of days to step
+ backwards from the last day of the month
+ to the weekday we want. */
offset = (last_weekday + 7 - weekday) % 7;
- offset += (week_num - 1) * 7;
+
+ /* This adds on the weeks. */
+ offset += (-week_num - 1) * 7;
+
cal_obj_time_add_days (occ, -offset);
if (occ->year == year && occ->month == month)
g_array_append_vals (new_occs, occ, 1);
@@ -3780,16 +3827,22 @@ cal_recur_ensure_rule_end_date (CalComponent *comp,
/* If refresh is FALSE, we check if the enddate is already set, and
if it is we just return. */
if (!refresh) {
- if (cal_recur_get_rule_end_date (prop) != -1)
+ if (cal_recur_get_rule_end_date (prop, NULL) != -1)
return FALSE;
}
- /* Calculate the end date. */
+ /* Calculate the end date. Note that we initialize end_date to 0, so
+ if the RULE doesn't generate COUNT instances we save a time_t of 0.
+ Also note that we use the UTC timezone as the default timezone.
+ In get_end_date() if the DTSTART is a DATE or floating time, we will
+ convert the ENDDATE to the current timezone. */
cb_data.count = rule.count;
cb_data.instances = 0;
+ cb_data.end_date = 0;
cal_recur_generate_instances_of_rule (comp, prop, -1, -1,
cal_recur_ensure_rule_end_date_cb,
- &cb_data, tz_cb, tz_cb_data);
+ &cb_data, tz_cb, tz_cb_data,
+ icaltimezone_get_utc_timezone ());
/* Store the end date in the "X-EVOLUTION-ENDDATE" parameter of the
rule. */
@@ -3820,14 +3873,19 @@ cal_recur_ensure_rule_end_date_cb (CalComponent *comp,
}
+/* If default_timezone is set, the saved ENDDATE parameter is assumed to be
+ in that timezone. This is used when the DTSTART is a DATE or floating
+ value, since the RRULE end date will change depending on the timezone that
+ it is evaluated in. */
static time_t
-cal_recur_get_rule_end_date (icalproperty *prop)
+cal_recur_get_rule_end_date (icalproperty *prop,
+ icaltimezone *default_timezone)
{
icalparameter *param;
const char *xname, *xvalue;
icalvalue *value;
struct icaltimetype icaltime;
- icaltimezone *utc_zone;
+ icaltimezone *zone;
param = icalproperty_get_first_parameter (prop, ICAL_X_PARAMETER);
while (param) {
@@ -3840,9 +3898,10 @@ cal_recur_get_rule_end_date (icalproperty *prop)
icaltime = icalvalue_get_datetime (value);
icalvalue_free (value);
- utc_zone = icaltimezone_get_utc_timezone ();
+ zone = default_timezone ? default_timezone :
+ icaltimezone_get_utc_timezone ();
return icaltime_as_timet_with_zone (icaltime,
- utc_zone);
+ zone);
}
}