[gnome-todo] scheduled-panel: all labels show in scheduled view



commit 9521d42865365a2eef84af3c790d219db4f12f5f
Author: Aeden McClain <dev platypro net>
Date:   Sun Mar 12 22:37:56 2017 -0700

    scheduled-panel: all labels show in scheduled view
    
    The panel was being sorted, but seemed to place tasks in random groups
    
    The problem is that both dates and times were set for each task. This
    breaks the labeling, as single day gaps between tasks could be
    interpreted as less than a day due to the fact that only whole days are
    counted in the current mechanism. This groups certain tasks together,
    which places some under the wrong header.
    
    The fix is to seperate the working date difference system from the
    mechanism which adds labels to the far right side of the task. Since
    this works for labelling the task as "Tomorrow" or "Today", it is
    suitable for also managing which headers should be set for each task.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774034

 plugins/scheduled-panel/gtd-panel-scheduled.c |   64 +++++++++++++++++--------
 1 files changed, 44 insertions(+), 20 deletions(-)
---
diff --git a/plugins/scheduled-panel/gtd-panel-scheduled.c b/plugins/scheduled-panel/gtd-panel-scheduled.c
index 71094f3..a866528 100644
--- a/plugins/scheduled-panel/gtd-panel-scheduled.c
+++ b/plugins/scheduled-panel/gtd-panel-scheduled.c
@@ -51,32 +51,57 @@ enum {
   N_PROPS
 };
 
-static gchar*
-get_string_for_date (GDateTime *dt,
-                     gint      *span)
+static void
+get_date_offset (GDateTime *dt,
+                 gint* days_diff,
+                 gint* next_year_diff)
 {
+  GDateTime *now;
   GDateTime *today;
   GDateTime *next_year;
-  GDateTime *now;
-  gchar *str;
-  gint days_diff;
-  gint next_year_diff;
-
-  /* This case should never happen */
-  if (!dt)
-    return g_strdup (_("No date set"));
 
   now = g_date_time_new_now_utc ();
+
   today = g_date_time_new_utc (g_date_time_get_year (now),
                                g_date_time_get_month (now),
                                g_date_time_get_day_of_month (now),
                                0, 0, 0);
+
   next_year = g_date_time_new_utc (g_date_time_get_year (now) + 1,
                                    G_DATE_JANUARY,
                                    1,
                                    0, 0, 0);
-  next_year_diff = g_date_time_difference (next_year, today) / G_TIME_SPAN_DAY;
-  days_diff = g_date_time_difference (dt, today) / G_TIME_SPAN_DAY;
+
+  if (days_diff)
+    {
+      *days_diff = g_date_time_difference (dt, today) / G_TIME_SPAN_DAY;
+    }
+
+  if (next_year_diff)
+    {
+      *next_year_diff = g_date_time_difference (next_year, today) / G_TIME_SPAN_DAY;
+    }
+
+  g_clear_pointer (&next_year, g_date_time_unref);
+  g_clear_pointer (&today, g_date_time_unref);
+  g_clear_pointer (&now, g_date_time_unref);
+
+  return;
+}
+
+static gchar*
+get_string_for_date (GDateTime *dt,
+                     gint      *span)
+{
+  gchar *str;
+  gint days_diff;
+  gint next_year_diff;
+
+  /* This case should never happen */
+  if (!dt)
+    return g_strdup (_("No date set"));
+
+  get_date_offset(dt, &days_diff, &next_year_diff);
 
   if (days_diff < 0)
     {
@@ -106,10 +131,6 @@ get_string_for_date (GDateTime *dt,
   if (span)
     *span = days_diff;
 
-  g_clear_pointer (&next_year, g_date_time_unref);
-  g_clear_pointer (&today, g_date_time_unref);
-  g_clear_pointer (&now, g_date_time_unref);
-
   return str;
 }
 
@@ -170,12 +191,15 @@ gtd_panel_scheduled_header_func (GtkListBoxRow     *row,
   else
     {
       GDateTime *before_dt;
-      gint diff;
+      gint before_diff;
+      gint new_diff;
 
       before_dt = gtd_task_get_due_date (before_task);
-      diff = g_date_time_difference (dt, before_dt) / G_TIME_SPAN_DAY;
 
-      if (diff != 0)
+      get_date_offset(before_dt, &before_diff, NULL);
+      get_date_offset(dt, &new_diff, NULL);
+
+      if (new_diff - before_diff != 0)
         {
           text = get_string_for_date (dt, &span);
 


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