summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Soriano <csoriano@gnome.org>2015-11-26 13:12:25 +0100
committerCarlos Soriano <csoriano@gnome.org>2015-12-02 11:19:37 +0100
commit91d5990612fdeebb080fb2c55f1740bfc2c64ef2 (patch)
tree2fdf1cd246f3c9f95665df9735af967dbf69f39c
parented100686f6ffcc48e867a73febe66b5de0ec11a0 (diff)
downloadnautilus-91d5990612fdeebb080fb2c55f1740bfc2c64ef2.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");