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



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

    nautilus-file: implement smarter dates

 libnautilus-private/nautilus-file.c |   92 +++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/libnautilus-private/nautilus-file.c b/libnautilus-private/nautilus-file.c
index b4a9fca..3be5696 100644
--- a/libnautilus-private/nautilus-file.c
+++ b/libnautilus-private/nautilus-file.c
@@ -4733,6 +4733,98 @@ nautilus_file_get_date_as_string (NautilusFile *file, NautilusDateType date_type
        return result;
 }
 
+static char *
+nautilus_file_get_date_as_string (NautilusFile     *file,
+                                  NautilusDateType *date_type,
+                                  gboolean          compact)
+{
+       time_t file_time_raw;
+       GDateTime *date_time, *today;
+
+       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);
+       now = g_date_time_new_now_local ();
+
+        var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
+
+        let format;
+
+        let desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
+        let clockFormat = desktopSettings.get_string(CLOCK_FORMAT_KEY);
+        let hasAmPm = date.toLocaleFormat('%p') != '';
+
+        if (clockFormat == '24h' || !hasAmPm) {
+            // Show only the time if date is on today
+            if(daysAgo < 1){
+                /* Translators: Time in 24h format */
+                format = N_("%H\u2236%M");
+            }
+            // Show the word "Yesterday" and time if date is on yesterday
+            else if(daysAgo <2){
+                /* 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");
+            }
+            // Show a week day and time if date is in the last week
+            else if (daysAgo < 7) {
+                /* Translators: this is the week day name followed by a time
+                 string in 24h format. i.e. "Monday, 14:30" */
+                // xgettext:no-c-format
+                format = N_("%A, %H\u2236%M");
+
+            } else if (date.getYear() == now.getYear()) {
+                /* Translators: this is the month name and day number
+                 followed by a time string in 24h format.
+                 i.e. "May 25, 14:30" */
+                // xgettext:no-c-format
+                format = N_("%B %d, %H\u2236%M");
+            } else {
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 24h format.
+                 i.e. "May 25 2012, 14:30" */
+                // xgettext:no-c-format
+                format = N_("%B %d %Y, %H\u2236%M");
+            }
+        } else {
+            // Show only the time if date is on today
+            if(daysAgo < 1){
+                /* Translators: Time in 24h format */
+                format = N_("%l\u2236%M %p");
+            }
+            // Show the word "Yesterday" and time if date is on yesterday
+            else if(daysAgo <2){
+                /* 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 followed by a time
+                 string in 12h format. i.e. "Monday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = N_("%A, %l\u2236%M %p");
+
+            } else if (date.getYear() == now.getYear()) {
+                /* Translators: this is the month name and day number
+                 followed by a time string in 12h format.
+                 i.e. "May 25, 2:30 pm" */
+                // xgettext:no-c-format
+                format = N_("%B %d, %l\u2236%M %p");
+            } else {
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 12h format.
+                 i.e. "May 25 2012, 2:30 pm"*/
+                // xgettext:no-c-format
+                format = N_("%B %d %Y, %l\u2236%M %p");
+            }
+        }
+        return date.toLocaleFormat(Shell.util_translate_time_string(format));
+}
 static void
 show_directory_item_count_changed_callback (gpointer callback_data)
 {


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