[gnome-calendar] edit-dialog: fix date span backward



commit 1228f05a902eb948664b8a59c5641af9ced63cf5
Author: Andrei Ceapa <andrei781995 gmail com>
Date:   Mon Feb 20 14:16:19 2017 +0200

    edit-dialog: fix date span backward
    
    The problem is that the end date might change to one before the
    start date when modifying the start time.
    
    Treat some cases taking into consideration the start date and start
    time related to the fact that an event is spanning all day or not.
    Separate the handling of the start date and start time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=772100

 src/gcal-edit-dialog.c |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 34dd1e7..46d6d3f 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -300,10 +300,12 @@ sync_datetimes (GcalEditDialog *self,
 {
   GDateTime *start, *end, *new_date;
   GtkWidget *date_widget, *time_widget;
-  gboolean is_start;
+  gboolean is_start_time, is_start_date;
   gint hour_to_add;
 
-  is_start = (widget == self->start_time_selector || widget == self->start_date_selector);
+  is_start_time = (widget == self->start_time_selector);
+  is_start_date = (widget == self->start_date_selector);
+
   start = gcal_edit_dialog_get_date_start (self);
   end = gcal_edit_dialog_get_date_end (self);
 
@@ -317,9 +319,36 @@ sync_datetimes (GcalEditDialog *self,
    */
   hour_to_add = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->all_day_check)) ? 0 : 1;
 
-  if (is_start)
+  if (is_start_date)
+    {
+      if (hour_to_add)
+        {
+          if (g_date_time_difference(end, start) < 0)
+            {
+              new_date = g_date_time_add_hours (start, hour_to_add + 24);
+
+              date_widget = self->end_date_selector;
+              time_widget = self->end_time_selector;
+            }
+          else
+            {
+              new_date = g_date_time_add_hours (start, hour_to_add);
+
+              date_widget = self->end_date_selector;
+              time_widget = self->end_time_selector;
+            }
+        }
+      else
+        {
+          new_date = g_date_time_add_hours (start, hour_to_add);
+
+          date_widget = self->end_date_selector;
+          time_widget = self->end_time_selector;
+        }
+    }
+  else if (is_start_time)
     {
-      new_date = g_date_time_add_hours (start, hour_to_add);
+      new_date = g_date_time_add_hours (start, hour_to_add + 24);
 
       date_widget = self->end_date_selector;
       time_widget = self->end_time_selector;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]