From 072e06753ec4dfe616a48a62510ac2c51556b52d Mon Sep 17 00:00:00 2001 From: Ernestas Kulik Date: Sat, 25 Jun 2016 12:19:14 +0300 Subject: file: fix date string day difference calculation nautilus_file_get_date_as_string() uses today's date and the GDateTime constructed from the return value of nautilus_file_get_date(), which also includes the time of day, thus making the calculation of the day difference incorrect. To illustrate, files, modified two days ago can appear to have been modified yesterday. This commit fixes that by calculating the day difference of the dates with the time value of 00:00:00. https://bugzilla.gnome.org/show_bug.cgi?id=756402 --- src/nautilus-file.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/nautilus-file.c b/src/nautilus-file.c index e3cbdfe20..a238d6998 100644 --- a/src/nautilus-file.c +++ b/src/nautilus-file.c @@ -4717,7 +4717,7 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateFormat date_format) { time_t file_time_raw; - GDateTime *file_date, *now; + GDateTime *file_date_time, *now; GDateTime *today_midnight; gint days_ago; gboolean use_24; @@ -4728,13 +4728,20 @@ nautilus_file_get_date_as_string (NautilusFile *file, if (!nautilus_file_get_date (file, date_type, &file_time_raw)) return NULL; - file_date = g_date_time_new_from_unix_local (file_time_raw); + file_date_time = g_date_time_new_from_unix_local (file_time_raw); if (date_format != NAUTILUS_DATE_FORMAT_FULL) { + GDateTime *file_date; + 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); + 0, 0, 0); + + file_date = g_date_time_new_local (g_date_time_get_year (file_date_time), + g_date_time_get_month (file_date_time), + g_date_time_get_day_of_month (file_date_time), + 0, 0, 0); days_ago = g_date_time_difference (today_midnight, file_date) / G_TIME_SPAN_DAY; @@ -4832,6 +4839,7 @@ nautilus_file_get_date_as_string (NautilusFile *file, } } + g_date_time_unref (file_date); g_date_time_unref (now); g_date_time_unref (today_midnight); } else { @@ -4839,8 +4847,8 @@ nautilus_file_get_date_as_string (NautilusFile *file, format = _("%c"); } - result = g_date_time_format (file_date, format); - g_date_time_unref (file_date); + result = g_date_time_format (file_date_time, format); + g_date_time_unref (file_date_time); /* Replace ":" with ratio. Replacement is done afterward because g_date_time_format * may fail with utf8 chars in some locales */ -- cgit v1.2.1