edit-dialog: correctly transform the edited datetime
This commit is contained in:
+41
-39
@@ -478,8 +478,7 @@ gcal_edit_dialog_action_button_clicked (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GDateTime *start_date, *adjusted_start;
|
GDateTime *start_date, *end_date;
|
||||||
GDateTime *end_date, *adjusted_end;
|
|
||||||
gboolean all_day;
|
gboolean all_day;
|
||||||
gchar *note_text;
|
gchar *note_text;
|
||||||
|
|
||||||
@@ -510,20 +509,15 @@ gcal_edit_dialog_action_button_clicked (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Update start & end dates. We always translate the dates to the event's
|
* Update start & end dates. The dates are already translated to the current
|
||||||
* timezone before applying them.
|
* timezone.
|
||||||
*/
|
*/
|
||||||
start_date = gcal_edit_dialog_get_date_start (dialog);
|
start_date = gcal_edit_dialog_get_date_start (dialog);
|
||||||
adjusted_start = g_date_time_to_timezone (start_date, gcal_event_get_timezone (dialog->event));
|
|
||||||
|
|
||||||
end_date = gcal_edit_dialog_get_date_end (dialog);
|
end_date = gcal_edit_dialog_get_date_end (dialog);
|
||||||
adjusted_end = g_date_time_to_timezone (end_date, gcal_event_get_timezone (dialog->event));
|
|
||||||
|
|
||||||
gcal_event_set_date_start (dialog->event, adjusted_start);
|
gcal_event_set_date_start (dialog->event, start_date);
|
||||||
gcal_event_set_date_end (dialog->event, adjusted_end);
|
gcal_event_set_date_end (dialog->event, end_date);
|
||||||
|
|
||||||
g_clear_pointer (&adjusted_start, g_date_time_unref);
|
|
||||||
g_clear_pointer (&adjusted_end, g_date_time_unref);
|
|
||||||
g_clear_pointer (&start_date, g_date_time_unref);
|
g_clear_pointer (&start_date, g_date_time_unref);
|
||||||
g_clear_pointer (&end_date, g_date_time_unref);
|
g_clear_pointer (&end_date, g_date_time_unref);
|
||||||
|
|
||||||
@@ -687,8 +681,10 @@ gcal_edit_dialog_set_manager (GcalEditDialog *dialog,
|
|||||||
g_object_notify (G_OBJECT (dialog), "manager");
|
g_object_notify (G_OBJECT (dialog), "manager");
|
||||||
}
|
}
|
||||||
|
|
||||||
GDateTime*
|
static GDateTime*
|
||||||
gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
return_datetime_for_widgets (GcalEditDialog *dialog,
|
||||||
|
GcalDateSelector *date_selector,
|
||||||
|
GcalTimeSelector *time_selector)
|
||||||
{
|
{
|
||||||
GTimeZone *tz;
|
GTimeZone *tz;
|
||||||
GDateTime *date;
|
GDateTime *date;
|
||||||
@@ -698,10 +694,10 @@ gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
|||||||
|
|
||||||
/* Use UTC timezone for All Day events, otherwise use the event's timezone */
|
/* Use UTC timezone for All Day events, otherwise use the event's timezone */
|
||||||
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));
|
||||||
tz = all_day ? g_time_zone_new_utc () : g_time_zone_ref (gcal_event_get_timezone (dialog->event));
|
tz = all_day ? g_time_zone_new_utc () : g_time_zone_new_local ();
|
||||||
|
|
||||||
date = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->start_date_selector));
|
date = gcal_date_selector_get_date (date_selector);
|
||||||
time = gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->start_time_selector));
|
time = gcal_time_selector_get_time (time_selector);
|
||||||
|
|
||||||
retval = g_date_time_new (tz,
|
retval = g_date_time_new (tz,
|
||||||
g_date_time_get_year (date),
|
g_date_time_get_year (date),
|
||||||
@@ -711,36 +707,42 @@ gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
|||||||
g_date_time_get_minute (time),
|
g_date_time_get_minute (time),
|
||||||
0);
|
0);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the event is not all day, the timezone may be different from UTC or
|
||||||
|
* local. In any case, since we're editing the event in the current timezone,
|
||||||
|
* we should always correct the timezone to the event's timezone.
|
||||||
|
*/
|
||||||
|
if (!all_day)
|
||||||
|
{
|
||||||
|
GDateTime *aux = retval;
|
||||||
|
|
||||||
|
retval = g_date_time_to_timezone (aux, gcal_event_get_timezone (dialog->event));
|
||||||
|
|
||||||
|
g_clear_pointer (&aux, g_date_time_unref);
|
||||||
|
}
|
||||||
|
|
||||||
g_clear_pointer (&tz, g_time_zone_unref);
|
g_clear_pointer (&tz, g_time_zone_unref);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GDateTime*
|
||||||
|
gcal_edit_dialog_get_date_start (GcalEditDialog *dialog)
|
||||||
|
{
|
||||||
|
|
||||||
|
g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL);
|
||||||
|
|
||||||
|
return return_datetime_for_widgets (dialog,
|
||||||
|
GCAL_DATE_SELECTOR (dialog->start_date_selector),
|
||||||
|
GCAL_TIME_SELECTOR (dialog->start_time_selector));
|
||||||
|
}
|
||||||
|
|
||||||
GDateTime*
|
GDateTime*
|
||||||
gcal_edit_dialog_get_date_end (GcalEditDialog *dialog)
|
gcal_edit_dialog_get_date_end (GcalEditDialog *dialog)
|
||||||
{
|
{
|
||||||
GTimeZone *tz;
|
g_return_val_if_fail (GCAL_IS_EDIT_DIALOG (dialog), NULL);
|
||||||
GDateTime *date;
|
|
||||||
GDateTime *time;
|
|
||||||
GDateTime *retval;
|
|
||||||
gboolean all_day;
|
|
||||||
|
|
||||||
/* Use UTC timezone for All Day events, otherwise use the event's timezone */
|
return return_datetime_for_widgets (dialog,
|
||||||
all_day = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->all_day_check));
|
GCAL_DATE_SELECTOR (dialog->end_date_selector),
|
||||||
tz = all_day ? g_time_zone_new_utc () : g_time_zone_ref (gcal_event_get_timezone (dialog->event));
|
GCAL_TIME_SELECTOR (dialog->end_time_selector));
|
||||||
|
|
||||||
date = gcal_date_selector_get_date (GCAL_DATE_SELECTOR (dialog->end_date_selector));
|
|
||||||
time = gcal_time_selector_get_time (GCAL_TIME_SELECTOR (dialog->end_time_selector));
|
|
||||||
|
|
||||||
retval = g_date_time_new (tz,
|
|
||||||
g_date_time_get_year (date),
|
|
||||||
g_date_time_get_month (date),
|
|
||||||
g_date_time_get_day_of_month (date),
|
|
||||||
g_date_time_get_hour (time),
|
|
||||||
g_date_time_get_minute (time),
|
|
||||||
0);
|
|
||||||
|
|
||||||
g_clear_pointer (&tz, g_time_zone_unref);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user