[nautilus/gnome-3-18] file: fix wrong date calculation



commit bcaf4efc546dbb2e2a1c3371bb35ddb3792ea845
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Nov 26 13:12:25 2015 +0100

    file: fix wrong date calculation
    
    We were checking how many days ago the file was modified by
    checking directly the current time with the file modification
    time, which is wrong if the file was modified a few hours ago
    but the day already passed.
    What happened is that it was showing the time as in if it was
    modified in the same day, instead of saying "Yesterday".
    
    To fix it, check the time difference with the midnight time.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757272

 libnautilus-private/nautilus-file.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index eff26dc..8fde7c5 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -4694,6 +4694,7 @@ nautilus_file_get_date_as_string (NautilusFile       *file,
 {
        time_t file_time_raw;
        GDateTime *file_date, *now;
+        GDateTime *today_midnight;
        gint days_ago;
        gboolean use_24;
        const gchar *format;
@@ -4706,8 +4707,13 @@ nautilus_file_get_date_as_string (NautilusFile       *file,
        file_date = g_date_time_new_from_unix_local (file_time_raw);
        if (date_format != NAUTILUS_DATE_FORMAT_FULL) {
                now = g_date_time_new_now_local ();
+                today_midnight = g_date_time_new_local (g_date_time_get_year (now),
+                                                        g_date_time_get_month (now),
+                                                        g_date_time_get_day_of_month (now),
+                                                        0, 1, 0);
 
-               days_ago = g_date_time_difference (now, file_date) / (24 * 60 * 60 * 1000 * 1000L);
+               days_ago = g_date_time_difference (today_midnight, file_date) /
+                           (24 * 60 * 60 * 1000 * 1000L);
 
                use_24 = g_settings_get_enum (gnome_interface_preferences, "clock-format") ==
                         G_DESKTOP_CLOCK_FORMAT_24H;
@@ -4804,6 +4810,7 @@ nautilus_file_get_date_as_string (NautilusFile       *file,
                }
 
                g_date_time_unref (now);
+               g_date_time_unref (today_midnight);
        } else {
                // xgettext:no-c-format
                format = N_("%c");


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