[chronojump] Implemented UtilGtk.DateColumnCompare



commit 776c23ceec3d5a73761882ca559ba5dada248e85
Author: Xavier de Blas <xaviblas gmail com>
Date:   Sun Oct 16 13:51:46 2022 +0200

    Implemented UtilGtk.DateColumnCompare

 src/utilGtk.cs | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/utilGtk.cs b/src/utilGtk.cs
index 5fbb59744..9d8d52eb6 100644
--- a/src/utilGtk.cs
+++ b/src/utilGtk.cs
@@ -335,13 +335,26 @@ public class UtilGtk
        }
 
        /*
-        * DateColumnCompare depends on the column. Better define this method where is needed.
-        * Search for dateColumnCompare
+        * DateColumnCompare depends on the column. Note here we are using column 0
+        * Other parts of the program use another column, search for dateColumnCompare
         *
-       public static int DateColumnCompare (TreeModel model, TreeIter iter1, TreeIter iter2)     {
-       }
-       */
+        */
+       public static int DateColumnCompare (TreeModel model, TreeIter iter1, TreeIter iter2)
+       {
+               var dt1String = (model.GetValue(iter1, 0).ToString());
+               var dt2String = (model.GetValue(iter2, 0).ToString());
+
+               DateTime dt1;
+               DateTime dt2;
 
+               var converted1 = DateTime.TryParse(dt1String, out dt1);
+               var converted2 = DateTime.TryParse(dt2String, out dt2);
+
+               if(converted1 && converted2)
+                       return DateTime.Compare(dt1, dt2);
+               else
+                       return 0;
+       }
        
        public static int GetSelectedRowUniqueID (Gtk.TreeView tv, Gtk.TreeStore store, int uniqueIDcol) {
                TreeModel model;


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