summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2015-11-26 13:12:25 +0100
committerCarlos Soriano <csoriano@gnome.org>2015-11-26 17:39:24 +0100
commitbcaf4efc546dbb2e2a1c3371bb35ddb3792ea845 (patch)
treea9b31eb71a863c2922455eda01a918abf92edca4
parent8f70e4c705183ed31eb21941eecd3c5cfe8e1448 (diff)
downloadnautilus-bcaf4efc546dbb2e2a1c3371bb35ddb3792ea845.tar.gz
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
-rw-r--r--libnautilus-private/nautilus-file.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index eff26dcc0..8fde7c510 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");