diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c index 31cd0a00a2bcded930c418a066a7f3ba9fdbc687..01a34f05f2a971d8c1621ccbe7cc185fb8d2da51 100644 --- a/src/gcal-edit-dialog.c +++ b/src/gcal-edit-dialog.c @@ -452,6 +452,7 @@ action_button_clicked (GtkWidget *widget, GcalRecurrenceFrequency freq; GcalRecurrence *old_recur; GDateTime *start_date, *end_date; + gboolean was_all_day; gboolean all_day; gchar *note_text; @@ -468,6 +469,7 @@ action_button_clicked (GtkWidget *widget, /* Update all day */ all_day = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check)); + was_all_day = gcal_event_get_all_day (dialog->event); gcal_event_set_all_day (dialog->event, all_day); @@ -483,7 +485,7 @@ action_button_clicked (GtkWidget *widget, /* * Update start & end dates. The dates are already translated to the current - * timezone. + * timezone (unless the event used to be all day, but no longer is). */ start_date = gcal_edit_dialog_get_date_start (dialog); end_date = gcal_edit_dialog_get_date_end (dialog); @@ -500,6 +502,23 @@ action_button_clicked (GtkWidget *widget, g_clear_pointer (&end_date, g_date_time_unref); end_date = fake_end_date; } + else if (!all_day && was_all_day) + { + /* When an all day event is changed to be not an all day event, we + * need to correct for the fact that the event's timezone was until + * now set to UTC. That means we need to change the timezone to + * localtime now, or else it will be saved incorrectly. + */ + GDateTime *localtime_date; + + localtime_date = g_date_time_to_local (start_date); + g_clear_pointer (&start_date, g_date_time_unref); + start_date = localtime_date; + + localtime_date = g_date_time_to_local (end_date); + g_clear_pointer (&end_date, g_date_time_unref); + end_date = localtime_date; + } gcal_event_set_date_start (dialog->event, start_date); gcal_event_set_date_end (dialog->event, end_date); diff --git a/src/gcal-event.c b/src/gcal-event.c index 789f67c4aab266cb3ea7eb5395391092c20f3fc5..a7aaa00a6a471010c6727adc927e41b334c5de79 100644 --- a/src/gcal-event.c +++ b/src/gcal-event.c @@ -221,9 +221,8 @@ get_timezone_from_ical (ECalComponentDateTime *comp) } static ECalComponentDateTime* -build_component_from_datetime (GcalEvent *self, - icaltimezone *current_tz, - GDateTime *dt) +build_component_from_datetime (GcalEvent *self, + GDateTime *dt) { ECalComponentDateTime *comp_dt; @@ -231,15 +230,19 @@ build_component_from_datetime (GcalEvent *self, return NULL; comp_dt = g_new0 (ECalComponentDateTime, 1); - comp_dt->value = NULL; - comp_dt->tzid = NULL; - comp_dt->value = datetime_to_icaltime (dt); - comp_dt->value->zone = self->all_day ? icaltimezone_get_utc_timezone () : current_tz; comp_dt->value->is_date = self->all_day; - /* All day events have UTC timezone */ - comp_dt->tzid = g_strdup (self->all_day ? "UTC" : icaltimezone_get_tzid (current_tz)); + if (self->all_day) + { + comp_dt->value->zone = icaltimezone_get_utc_timezone (); + comp_dt->tzid = g_strdup ("UTC"); + } + else + { + comp_dt->value->zone = e_cal_util_get_system_timezone (); + comp_dt->tzid = g_strdup (icaltimezone_get_tzid ((icaltimezone *) comp_dt->value->zone)); + } return comp_dt; } @@ -985,29 +988,21 @@ gcal_event_set_date_end (GcalEvent *self, { g_return_if_fail (GCAL_IS_EVENT (self)); - if (self->dt_end != dt && - (!self->dt_end || !dt || - (self->dt_end && dt && !g_date_time_equal (self->dt_end, dt)))) + if (self->dt_end != dt) { - ECalComponentDateTime *component_dt, current; + ECalComponentDateTime *component_dt; g_clear_pointer (&self->dt_end, g_date_time_unref); self->dt_end = g_date_time_ref (dt); - /* Retrieve the current timezone */ - e_cal_component_get_dtstart (self->component, ¤t); - /* Setup the ECalComponent's datetime value */ - component_dt = build_component_from_datetime (self, - icaltimezone_get_builtin_timezone_from_tzid (current.tzid), - dt); + component_dt = build_component_from_datetime (self, dt); e_cal_component_set_dtend (self->component, component_dt); e_cal_component_commit_sequence (self->component); g_object_notify (G_OBJECT (self), "date-end"); - e_cal_component_free_datetime (¤t); e_cal_component_free_datetime (component_dt); g_free (component_dt); } @@ -1042,29 +1037,21 @@ gcal_event_set_date_start (GcalEvent *self, { g_return_if_fail (GCAL_IS_EVENT (self)); - if (self->dt_start != dt && - (!self->dt_start || !dt || - (self->dt_start && dt && !g_date_time_equal (self->dt_start, dt)))) + if (self->dt_start != dt) { - ECalComponentDateTime *component_dt, current; + ECalComponentDateTime *component_dt; g_clear_pointer (&self->dt_start, g_date_time_unref); self->dt_start = g_date_time_ref (dt); - /* Retrieve the current timezone */ - e_cal_component_get_dtstart (self->component, ¤t); - /* Setup the ECalComponent's datetime value */ - component_dt = build_component_from_datetime (self, - icaltimezone_get_builtin_timezone_from_tzid (current.tzid), - dt); + component_dt = build_component_from_datetime (self, dt); e_cal_component_set_dtstart (self->component, component_dt); e_cal_component_commit_sequence (self->component); g_object_notify (G_OBJECT (self), "date-start"); - e_cal_component_free_datetime (¤t); e_cal_component_free_datetime (component_dt); g_free (component_dt); }