[gnome-control-center/wip/loc-apps: 1/4] Move get_smart_date() to common utils



commit 9b7c1749a984343904babeedd67b05a9ea173cf5
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Feb 12 23:06:59 2016 +0000

    Move get_smart_date() to common utils
    
    And rename it to cc_util_get_smart_date().
    
    In a following patch, we'll need to use it from privacy panel.

 panels/common/cc-util.c                  |   39 ++++++++++++++++++++++++++++++
 panels/common/cc-util.h                  |    3 +-
 panels/user-accounts/um-history-dialog.c |    4 ++-
 panels/user-accounts/um-user-panel.c     |    3 +-
 panels/user-accounts/um-utils.c          |   39 ------------------------------
 panels/user-accounts/um-utils.h          |    2 -
 6 files changed, 46 insertions(+), 44 deletions(-)
---
diff --git a/panels/common/cc-util.c b/panels/common/cc-util.c
index e51a9d2..8511e8c 100644
--- a/panels/common/cc-util.c
+++ b/panels/common/cc-util.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include <string.h>
+#include <glib/gi18n.h>
 
 
 #include "cc-util.h"
@@ -103,3 +104,41 @@ cc_util_normalize_casefold_and_unaccent (const char *str)
 
   return tmp;
 }
+
+gchar *
+cc_util_get_smart_date (GDateTime *date)
+{
+        gchar *label;
+        GDateTime *today, *local;
+        GTimeSpan span;
+
+        /* Set today date */
+        local = g_date_time_new_now_local ();
+        today = g_date_time_new_local (g_date_time_get_year (local),
+                                       g_date_time_get_month (local),
+                                       g_date_time_get_day_of_month (local),
+                                       0, 0, 0);
+
+        span = g_date_time_difference (today, date);
+        if (span <= 0) {
+                label = g_strdup (_("Today"));
+        }
+        else if (span <= G_TIME_SPAN_DAY) {
+                label = g_strdup (_("Yesterday"));
+        }
+        else {
+                if (g_date_time_get_year (date) == g_date_time_get_year (today)) {
+                        /* Translators: This is a date format string in the style of "Feb 24". */
+                        label = g_date_time_format (date, _("%b %e"));
+                }
+                else {
+                        /* Translators: This is a date format string in the style of "Feb 24, 2013". */
+                        label = g_date_time_format (date, _("%b %e, %Y"));
+                }
+        }
+
+        g_date_time_unref (local);
+        g_date_time_unref (today);
+
+        return label;
+}
diff --git a/panels/common/cc-util.h b/panels/common/cc-util.h
index 42b09ff..ac01cf4 100644
--- a/panels/common/cc-util.h
+++ b/panels/common/cc-util.h
@@ -23,6 +23,7 @@
 
 #include <glib.h>
 
-char *cc_util_normalize_casefold_and_unaccent (const char *str);
+char * cc_util_normalize_casefold_and_unaccent (const char *str);
+gchar *cc_util_get_smart_date                  (GDateTime *date);
 
 #endif
diff --git a/panels/user-accounts/um-history-dialog.c b/panels/user-accounts/um-history-dialog.c
index dae13ec..5bc3cff 100644
--- a/panels/user-accounts/um-history-dialog.c
+++ b/panels/user-accounts/um-history-dialog.c
@@ -30,6 +30,8 @@
 #include <gtk/gtk.h>
 #include <act/act.h>
 
+#include "cc-util.h"
+
 #include "um-history-dialog.h"
 #include "um-utils.h"
 
@@ -169,7 +171,7 @@ add_record (GtkWidget *box, GDateTime *datetime, gchar *record_string, gint line
         gchar *date, *time, *str;
         GtkWidget *label, *row;
 
-        date = get_smart_date (datetime);
+        date = cc_util_get_smart_date (datetime);
         /* Translators: This is a time format string in the style of "22:58".
            It indicates a login time which follows a date. */
         time = g_date_time_format (datetime, C_("login date-time", "%k:%M"));
diff --git a/panels/user-accounts/um-user-panel.c b/panels/user-accounts/um-user-panel.c
index f534745..3d42458 100644
--- a/panels/user-accounts/um-user-panel.c
+++ b/panels/user-accounts/um-user-panel.c
@@ -60,6 +60,7 @@
 #include "um-history-dialog.h"
 
 #include "cc-common-language.h"
+#include "cc-util.h"
 
 #include "um-realm-manager.h"
 
@@ -838,7 +839,7 @@ get_login_time_text (ActUser *user)
         }
         else if (time > 0) {
                 date_time = g_date_time_new_from_unix_local (time);
-                date_str = get_smart_date (date_time);
+                date_str = cc_util_get_smart_date (date_time);
                 /* Translators: This is a time format string in the style of "22:58".
                    It indicates a login time which follows a date. */
                 time_str = g_date_time_format (date_time, C_("login date-time", "%k:%M"));
diff --git a/panels/user-accounts/um-utils.c b/panels/user-accounts/um-utils.c
index 34cd0ea..cd22fdf 100644
--- a/panels/user-accounts/um-utils.c
+++ b/panels/user-accounts/um-utils.c
@@ -796,45 +796,6 @@ generate_username_choices (const gchar  *name,
         g_string_free (item4, TRUE);
 }
 
-gchar *
-get_smart_date (GDateTime *date)
-{
-        gchar *label;
-        GDateTime *today, *local;
-        GTimeSpan span;
-
-        /* Set today date */
-        local = g_date_time_new_now_local ();
-        today = g_date_time_new_local (g_date_time_get_year (local),
-                                       g_date_time_get_month (local),
-                                       g_date_time_get_day_of_month (local),
-                                       0, 0, 0);
-
-        span = g_date_time_difference (today, date);
-        if (span <= 0) {
-                label = g_strdup (_("Today"));
-        }
-        else if (span <= G_TIME_SPAN_DAY) {
-                label = g_strdup (_("Yesterday"));
-        }
-        else {
-                if (g_date_time_get_year (date) == g_date_time_get_year (today)) {
-                        /* Translators: This is a date format string in the style of "Feb 24". */
-                        label = g_date_time_format (date, _("%b %e"));
-                }
-                else {
-                        /* Translators: This is a date format string in the style of "Feb 24, 2013". */
-                        label = g_date_time_format (date, _("%b %e, %Y"));
-                }
-        }
-
-        g_date_time_unref (local);
-        g_date_time_unref (today);
-
-        return label;
-}
-
-
 static gboolean
 check_user_file (const char *filename,
                  gssize      max_file_size)
diff --git a/panels/user-accounts/um-utils.h b/panels/user-accounts/um-utils.h
index e6a95e8..bb328da 100644
--- a/panels/user-accounts/um-utils.h
+++ b/panels/user-accounts/um-utils.h
@@ -73,8 +73,6 @@ gboolean is_valid_username                (const gchar     *name,
 void     generate_username_choices        (const gchar     *name,
                                            GtkListStore    *store);
 
-gchar *  get_smart_date                   (GDateTime *date);
-
 cairo_surface_t *render_user_icon         (ActUser         *user,
                                            UmIconStyle      style,
                                            gint             icon_size,


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