[nautilus/wip/csoriano/improve_list_view: 9/10] nautilus-file: implement smarter dates



commit e5e378a22d14570bbb74a9ec09c8659fdd9a30d6
Author: Carlos Soriano <csoriano gnome org>
Date:   Thu Feb 12 17:39:08 2015 +0100

    nautilus-file: implement smarter dates
    
    Design request, more readable and gnome-shell and polari does the same
    as us.

 libnautilus-private/nautilus-file.c |  121 +++++++++++++++++------------------
 1 files changed, 59 insertions(+), 62 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index b4a9fca..0c49596 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -4657,26 +4657,6 @@ nautilus_file_get_trash_original_file_parent_as_string (NautilusFile *file)
        return NULL;
 }
 
-/*
- * Note to localizers: You can look at man strftime
- * for details on the format, but you should only use
- * the specifiers from the C standard, not extensions.
- * These include "%" followed by one of
- * "aAbBcdHIjmMpSUwWxXyYZ". There are two extensions
- * in the Nautilus version of strftime that can be
- * used (and match GNU extensions). Putting a "-"
- * between the "%" and any numeric directive will turn
- * off zero padding, and putting a "_" there will use
- * space padding instead of zero padding.
- */
-#define TODAY_TIME_FORMAT_24 N_("%R")
-#define TODAY_TIME_FORMAT N_("%-I:%M %P")
-#define THIS_MONTH_TIME_FORMAT N_("%b %-e")
-#define THIS_YEAR_TIME_FORMAT N_("%b %-e")
-#define ANYTIME_TIME_FORMAT N_("%b %-d %Y")
-#define FULL_FORMAT N_("%a, %b %e %Y %I:%M:%S %p")
-#define FULL_FORMAT_24 N_("%a, %b %e %Y %T")
-
 /**
  * nautilus_file_get_date_as_string:
  * 
@@ -4688,49 +4668,72 @@ nautilus_file_get_trash_original_file_parent_as_string (NautilusFile *file)
  * 
  **/
 static char *
-nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type, gboolean compact)
+nautilus_file_get_date_as_string (NautilusFile     *file,
+                                  NautilusDateType  date_type)
 {
        time_t file_time_raw;
-       const char *format;
-       char *result = NULL;
-       GDateTime *date_time, *today;
-       int y, m, d;
-       int y_now, m_now, d_now;
-       GDesktopClockFormat value;
+       GDateTime *file_date, *now;
+       gint daysAgo;
        gboolean use_24;
+       gchar *format;
+       gchar *result;
 
-       if (!nautilus_file_get_date (file, date_type, &file_time_raw)) {
+       if (!nautilus_file_get_date (file, date_type, &file_time_raw))
                return NULL;
-       }
 
-       date_time = g_date_time_new_from_unix_local (file_time_raw);
+       file_date = g_date_time_new_from_unix_local (file_time_raw);
+       now = g_date_time_new_now_local ();
 
-       g_date_time_get_ymd (date_time, &y, &m, &d);
+        daysAgo = g_date_time_difference (now, file_date) / (24 * 60 * 60 * 1000 * 1000L);
 
-       today = g_date_time_new_now_local ();
-       g_date_time_get_ymd (today, &y_now, &m_now, &d_now);
-       g_date_time_unref (today);
+       use_24 = g_settings_get_enum (gnome_interface_preferences, "clock-format") ==
+                 G_DESKTOP_CLOCK_FORMAT_24H;
 
-       value = g_settings_get_enum (gnome_interface_preferences, "clock-format");
-       use_24 = value == G_DESKTOP_CLOCK_FORMAT_24H;
-
-       if (!compact) {
-               format = use_24 ? FULL_FORMAT_24 : FULL_FORMAT;
-       } else if (y == y_now && m == m_now && d == d_now) {
-               format = use_24 ? TODAY_TIME_FORMAT_24 : TODAY_TIME_FORMAT;
-       } else if (y == y_now && m == m_now) {
-               format = THIS_MONTH_TIME_FORMAT;
-       } else if (y == y_now) {
-               format = THIS_YEAR_TIME_FORMAT;
+       // Show only the time if date is on today
+       if (daysAgo < 1) {
+               if (use_24) {
+                       /* Translators: Time in 24h format */
+                       format = N_("%H\u2236%M");
+               } else {
+                       /* Translators: Time in 12h format */
+                       format = N_("%l\u2236%M %p");
+               }
+       }
+       // Show the word "Yesterday" and time if date is on yesterday
+       else if (daysAgo < 2) {
+               if (use_24) {
+                       /* Translators: this is the word "Yesterday" followed by a
+                        time string in 24h format. i.e. "Yesterday, 14:30" */
+                       // xgettext:no-c-format
+                       format = N_("Yesterday, %H\u2236%M");
+               } else {
+                       /* Translators: this is the word "Yesterday" followed by a
+                        time string in 12h format. i.e. "Yesterday, 2:30 pm" */
+                       // xgettext:no-c-format
+                       format = N_("Yesterday, %l\u2236%M %p");
+               }
+       }
+       // Show a week day and time if date is in the last week
+       else if (daysAgo < 7) {
+               /* Translators: this is the week day name. i.e. "Monday" */
+               // xgettext:no-c-format
+               format = N_("%A");
+       } else if (g_date_time_get_year (file_date) == g_date_time_get_year (now)) {
+               /* Translators: this is the month name followed by the day.
+                i.e. "May 25" */
+               // xgettext:no-c-format
+               format = N_("%B %d");
        } else {
-               format = ANYTIME_TIME_FORMAT;
+               /* Translators: this is the month name, day number & year
+                i.e. "May 25 2012" */
+               // xgettext:no-c-format
+               format = N_("%B %d %Y");
        }
 
-       result = g_date_time_format (date_time, _(format));
-
-       g_date_time_unref (date_time);
+       result = g_date_time_format (file_date, format);
+       g_date_time_unref (file_date);
 
-       return result;
+        return  result;
 }
 
 static void
@@ -6187,33 +6190,27 @@ nautilus_file_get_string_attribute_q (NautilusFile *file, GQuark attribute_q)
        }
        if (attribute_q == attribute_date_modified_q) {
                return nautilus_file_get_date_as_string (file, 
-                                                        NAUTILUS_DATE_TYPE_MODIFIED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_TYPE_MODIFIED);
        }
        if (attribute_q == attribute_date_modified_full_q) {
                return nautilus_file_get_date_as_string (file, 
-                                                        NAUTILUS_DATE_TYPE_MODIFIED,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_TYPE_MODIFIED);
        }
        if (attribute_q == attribute_date_accessed_q) {
                return nautilus_file_get_date_as_string (file,
-                                                        NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_TYPE_ACCESSED);
        }
        if (attribute_q == attribute_date_accessed_full_q) {
                return nautilus_file_get_date_as_string (file,
-                                                        NAUTILUS_DATE_TYPE_ACCESSED,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_TYPE_ACCESSED);
        }
        if (attribute_q == attribute_trashed_on_q) {
                return nautilus_file_get_date_as_string (file,
-                                                        NAUTILUS_DATE_TYPE_TRASHED,
-                                                        TRUE);
+                                                        NAUTILUS_DATE_TYPE_TRASHED);
        }
        if (attribute_q == attribute_trashed_on_full_q) {
                return nautilus_file_get_date_as_string (file,
-                                                        NAUTILUS_DATE_TYPE_TRASHED,
-                                                        FALSE);
+                                                        NAUTILUS_DATE_TYPE_TRASHED);
        }
        if (attribute_q == attribute_permissions_q) {
                return nautilus_file_get_permissions_as_string (file);


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