Merge branch 'wip/mcatanzaro/timezone' into 'master'

Events created in month or year view are created with incorrect time and missing timezone

Closes #168

See merge request GNOME/gnome-calendar!7
This commit is contained in:
Georges Basile Stavracas Neto
2017-12-06 10:45:42 +00:00
2 changed files with 38 additions and 32 deletions
+20 -1
View File
@@ -452,6 +452,7 @@ action_button_clicked (GtkWidget *widget,
GcalRecurrenceFrequency freq; GcalRecurrenceFrequency freq;
GcalRecurrence *old_recur; GcalRecurrence *old_recur;
GDateTime *start_date, *end_date; GDateTime *start_date, *end_date;
gboolean was_all_day;
gboolean all_day; gboolean all_day;
gchar *note_text; gchar *note_text;
@@ -468,6 +469,7 @@ action_button_clicked (GtkWidget *widget,
/* Update all day */ /* Update all day */
all_day = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check)); 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); 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 * 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); start_date = gcal_edit_dialog_get_date_start (dialog);
end_date = gcal_edit_dialog_get_date_end (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); g_clear_pointer (&end_date, g_date_time_unref);
end_date = fake_end_date; 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_start (dialog->event, start_date);
gcal_event_set_date_end (dialog->event, end_date); gcal_event_set_date_end (dialog->event, end_date);
+18 -31
View File
@@ -221,9 +221,8 @@ get_timezone_from_ical (ECalComponentDateTime *comp)
} }
static ECalComponentDateTime* static ECalComponentDateTime*
build_component_from_datetime (GcalEvent *self, build_component_from_datetime (GcalEvent *self,
icaltimezone *current_tz, GDateTime *dt)
GDateTime *dt)
{ {
ECalComponentDateTime *comp_dt; ECalComponentDateTime *comp_dt;
@@ -231,15 +230,19 @@ build_component_from_datetime (GcalEvent *self,
return NULL; return NULL;
comp_dt = g_new0 (ECalComponentDateTime, 1); comp_dt = g_new0 (ECalComponentDateTime, 1);
comp_dt->value = NULL;
comp_dt->tzid = NULL;
comp_dt->value = datetime_to_icaltime (dt); 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; comp_dt->value->is_date = self->all_day;
/* All day events have UTC timezone */ if (self->all_day)
comp_dt->tzid = g_strdup (self->all_day ? "UTC" : icaltimezone_get_tzid (current_tz)); {
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; return comp_dt;
} }
@@ -985,29 +988,21 @@ gcal_event_set_date_end (GcalEvent *self,
{ {
g_return_if_fail (GCAL_IS_EVENT (self)); g_return_if_fail (GCAL_IS_EVENT (self));
if (self->dt_end != dt && if (self->dt_end != dt)
(!self->dt_end || !dt ||
(self->dt_end && dt && !g_date_time_equal (self->dt_end, dt))))
{ {
ECalComponentDateTime *component_dt, current; ECalComponentDateTime *component_dt;
g_clear_pointer (&self->dt_end, g_date_time_unref); g_clear_pointer (&self->dt_end, g_date_time_unref);
self->dt_end = g_date_time_ref (dt); self->dt_end = g_date_time_ref (dt);
/* Retrieve the current timezone */
e_cal_component_get_dtstart (self->component, &current);
/* Setup the ECalComponent's datetime value */ /* Setup the ECalComponent's datetime value */
component_dt = build_component_from_datetime (self, component_dt = build_component_from_datetime (self, dt);
icaltimezone_get_builtin_timezone_from_tzid (current.tzid),
dt);
e_cal_component_set_dtend (self->component, component_dt); e_cal_component_set_dtend (self->component, component_dt);
e_cal_component_commit_sequence (self->component); e_cal_component_commit_sequence (self->component);
g_object_notify (G_OBJECT (self), "date-end"); g_object_notify (G_OBJECT (self), "date-end");
e_cal_component_free_datetime (&current);
e_cal_component_free_datetime (component_dt); e_cal_component_free_datetime (component_dt);
g_free (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)); g_return_if_fail (GCAL_IS_EVENT (self));
if (self->dt_start != dt && if (self->dt_start != dt)
(!self->dt_start || !dt ||
(self->dt_start && dt && !g_date_time_equal (self->dt_start, dt))))
{ {
ECalComponentDateTime *component_dt, current; ECalComponentDateTime *component_dt;
g_clear_pointer (&self->dt_start, g_date_time_unref); g_clear_pointer (&self->dt_start, g_date_time_unref);
self->dt_start = g_date_time_ref (dt); self->dt_start = g_date_time_ref (dt);
/* Retrieve the current timezone */
e_cal_component_get_dtstart (self->component, &current);
/* Setup the ECalComponent's datetime value */ /* Setup the ECalComponent's datetime value */
component_dt = build_component_from_datetime (self, component_dt = build_component_from_datetime (self, dt);
icaltimezone_get_builtin_timezone_from_tzid (current.tzid),
dt);
e_cal_component_set_dtstart (self->component, component_dt); e_cal_component_set_dtstart (self->component, component_dt);
e_cal_component_commit_sequence (self->component); e_cal_component_commit_sequence (self->component);
g_object_notify (G_OBJECT (self), "date-start"); g_object_notify (G_OBJECT (self), "date-start");
e_cal_component_free_datetime (&current);
e_cal_component_free_datetime (component_dt); e_cal_component_free_datetime (component_dt);
g_free (component_dt); g_free (component_dt);
} }