[nautilus/wip/oholy/search-engine-fixes: 5/5] nautilus-search-engine: Use GDateTime everywhere




commit ecd3a57d721b7b8314ec64711f27a89e68b31f07
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Feb 15 10:59:34 2022 +0100

    nautilus-search-engine: Use GDateTime everywhere
    
    The search providers convert dates from unix time to `GDateTime` and vice
    versa. Let's use `GDateTime` everywhere.
    
    Relates: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2152

 src/nautilus-search-engine-model.c  | 10 +++++-----
 src/nautilus-search-engine-recent.c | 10 +++++-----
 src/nautilus-search-engine-simple.c | 10 +++++-----
 src/nautilus-ui-utilities.c         |  9 ++-------
 src/nautilus-ui-utilities.h         |  2 +-
 5 files changed, 18 insertions(+), 23 deletions(-)
---
diff --git a/src/nautilus-search-engine-model.c b/src/nautilus-search-engine-model.c
index 1dbf5a25e..3bc2ab3d6 100644
--- a/src/nautilus-search-engine-model.c
+++ b/src/nautilus-search-engine-model.c
@@ -179,7 +179,7 @@ model_directory_ready_cb (NautilusDirectory *directory,
         if (found && date_range != NULL)
         {
             NautilusQuerySearchType type;
-            guint64 current_file_unix_time = 0;
+            GDateTime *target_date = NULL;
 
             type = nautilus_query_get_search_type (model->query);
             initial_date = g_ptr_array_index (date_range, 0);
@@ -187,18 +187,18 @@ model_directory_ready_cb (NautilusDirectory *directory,
 
             if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
             {
-                current_file_unix_time = g_date_time_to_unix (atime);
+                target_date = atime;
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
             {
-                current_file_unix_time = g_date_time_to_unix (mtime);
+                target_date = mtime;
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
             {
-                current_file_unix_time = g_date_time_to_unix (ctime);
+                target_date = ctime;
             }
 
-            found = nautilus_file_date_in_between (current_file_unix_time,
+            found = nautilus_date_time_in_between (target_date,
                                                    initial_date,
                                                    end_date);
             g_ptr_array_unref (date_range);
diff --git a/src/nautilus-search-engine-recent.c b/src/nautilus-search-engine-recent.c
index 7195c8a87..b1ff3178d 100644
--- a/src/nautilus-search-engine-recent.c
+++ b/src/nautilus-search-engine-recent.c
@@ -294,7 +294,7 @@ recent_thread_func (gpointer user_data)
             if (date_range != NULL)
             {
                 NautilusQuerySearchType type;
-                guint64 target_time = 0;
+                GDateTime *target_date = NULL;
                 GDateTime *initial_date;
                 GDateTime *end_date;
 
@@ -304,18 +304,18 @@ recent_thread_func (gpointer user_data)
 
                 if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
                 {
-                    target_time = g_date_time_to_unix (atime);
+                    target_date = atime;
                 }
                 else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
                 {
-                    target_time = g_date_time_to_unix (mtime);
+                    target_date = mtime;
                 }
                 else if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
                 {
-                    target_time = g_date_time_to_unix (ctime);
+                    target_date = ctime;
                 }
 
-                if (!nautilus_file_date_in_between (target_time,
+                if (!nautilus_date_time_in_between (target_date,
                                                     initial_date, end_date))
                 {
                     continue;
diff --git a/src/nautilus-search-engine-simple.c b/src/nautilus-search-engine-simple.c
index 306fe3bd1..b5f622f0f 100644
--- a/src/nautilus-search-engine-simple.c
+++ b/src/nautilus-search-engine-simple.c
@@ -361,25 +361,25 @@ visit_directory (GFile            *dir,
 
         if (found && date_range != NULL)
         {
-            guint64 current_file_time = 0;
+            GDateTime *target_date = NULL;
 
             initial_date = g_ptr_array_index (date_range, 0);
             end_date = g_ptr_array_index (date_range, 1);
 
             if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_ACCESS)
             {
-                current_file_time = g_date_time_to_unix (atime);
+                target_date = atime;
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_LAST_MODIFIED)
             {
-                current_file_time = g_date_time_to_unix (mtime);
+                target_date = mtime;
             }
             else if (type == NAUTILUS_QUERY_SEARCH_TYPE_CREATED)
             {
-                current_file_time = g_date_time_to_unix (ctime);
+                target_date = ctime;
             }
 
-            found = nautilus_file_date_in_between (current_file_time,
+            found = nautilus_date_time_in_between (target_date,
                                                    initial_date,
                                                    end_date);
         }
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 6153d3f1f..1d2b40beb 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -189,21 +189,18 @@ nautilus_ui_frame_video (GdkPixbuf **pixbuf)
 }
 
 gboolean
-nautilus_file_date_in_between (guint64    unix_file_time,
+nautilus_date_time_in_between (GDateTime *date,
                                GDateTime *initial_date,
                                GDateTime *end_date)
 {
-    GDateTime *date;
     gboolean in_between;
 
     /* Silently ignore errors */
-    if (unix_file_time == 0)
+    if (date == 0)
     {
         return FALSE;
     }
 
-    date = g_date_time_new_from_unix_local (unix_file_time);
-
     /* For the end date, we want to make end_date inclusive,
      * for that the difference between the start of the day and the in_between
      * has to be more than -1 day
@@ -211,8 +208,6 @@ nautilus_file_date_in_between (guint64    unix_file_time,
     in_between = g_date_time_difference (date, initial_date) > 0 &&
                  g_date_time_difference (end_date, date) / G_TIME_SPAN_DAY > -1;
 
-    g_date_time_unref (date);
-
     return in_between;
 }
 
diff --git a/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index d59d453e1..61fae69e1 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -37,7 +37,7 @@ void        nautilus_g_menu_replace_string_in_item  (GMenu             *menu,
 
 void        nautilus_ui_frame_video                 (GdkPixbuf        **pixbuf);
 
-gboolean    nautilus_file_date_in_between           (guint64            file_unix_time,
+gboolean    nautilus_date_time_in_between           (GDateTime         *date,
                                                      GDateTime         *initial_date,
                                                      GDateTime         *end_date);
 gchar     * get_text_for_date_range                 (GPtrArray         *date_range,


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