[file-roller/wip/jtojnar/engrampa-backports: 12/21] glib-utils: Remove get_time_string()




commit 0e2cc75aff13d289e78385fbbb203f7f2917c592
Author: rbuj <robert buj gmail com>
Date:   Sun Sep 1 20:41:47 2019 +0200

    glib-utils: Remove get_time_string()
    
    get_time_string() is a local function that wraps strftime().
    In contrast to strftime(), g_date_time_format() always produces
    an UTF-8 string, regardless of the current locale.
    
    Cherry picked from 
https://github.com/mate-desktop/engrampa/commit/29b945fd67d1e7eb93cfe66d089977d064c7f7bc
    Modified to use automatic memory management

 src/dlg-prop.c   | 13 +++++++++----
 src/fr-window.c  | 13 +++++++++----
 src/glib-utils.c | 24 ------------------------
 src/glib-utils.h |  4 ----
 4 files changed, 18 insertions(+), 36 deletions(-)
---
diff --git a/src/dlg-prop.c b/src/dlg-prop.c
index 5898c567..b9b4b869 100644
--- a/src/dlg-prop.c
+++ b/src/dlg-prop.c
@@ -113,10 +113,15 @@ dlg_prop (FrWindow *window)
 
        /**/
 
-       label = _gtk_builder_get_widget (data->builder, "p_date_label");
-       s = _g_time_to_string (_g_file_get_file_mtime (fr_window_get_archive_file (window)));
-       gtk_label_set_text (GTK_LABEL (label), s);
-       g_free (s);
+       {
+               g_autoptr (GDateTime) date_time;
+
+               label = _gtk_builder_get_widget (data->builder, "p_date_label");
+               date_time = g_date_time_new_from_unix_local (_g_file_get_file_mtime 
(fr_window_get_archive_file (window)));
+               s = g_date_time_format (date_time, _("%d %B %Y, %H:%M"));
+               gtk_label_set_text (GTK_LABEL (label), s);
+               g_free (s);
+       }
 
        /**/
 
diff --git a/src/fr-window.c b/src/fr-window.c
index a7ad2487..51bcec23 100644
--- a/src/fr-window.c
+++ b/src/fr-window.c
@@ -1570,10 +1570,13 @@ fr_window_populate_file_list (FrWindow  *window,
 
                        s_size = g_format_size (fdata->dir_size);
 
-                       if (fdata->list_dir)
+                       if (fdata->list_dir) {
                                s_time = g_strdup ("");
-                       else
-                               s_time = _g_time_to_string (fdata->modified);
+                       } else {
+                               g_autoptr (GDateTime) date_time;
+                               date_time = g_date_time_new_from_unix_local (fdata->modified);
+                               s_time = g_date_time_format (date_time, _("%d %B %Y, %H:%M"));
+                       }
 
                        gtk_list_store_set (window->priv->list_store, &iter,
                                            COLUMN_FILE_DATA, fdata,
@@ -1590,6 +1593,7 @@ fr_window_populate_file_list (FrWindow  *window,
                        g_free (s_time);
                }
                else {
+                       g_autoptr (GDateTime) date_time;
                        char *utf8_path;
                        char *s_size;
                        char *s_time;
@@ -1598,7 +1602,8 @@ fr_window_populate_file_list (FrWindow  *window,
                        utf8_path = g_filename_display_name (fdata->path);
 
                        s_size = g_format_size (fdata->size);
-                       s_time = _g_time_to_string (fdata->modified);
+                       date_time = g_date_time_new_from_unix_local (fdata->modified);
+                       s_time = g_date_time_format (date_time, _("%d %B %Y, %H:%M"));
                        desc = g_content_type_get_description (fdata->content_type);
 
                        gtk_list_store_set (window->priv->list_store, &iter,
diff --git a/src/glib-utils.c b/src/glib-utils.c
index 2ebc38ad..11db6e5a 100644
--- a/src/glib-utils.c
+++ b/src/glib-utils.c
@@ -701,30 +701,6 @@ _g_regexp_split_from_patterns (const char         *pattern_string,
 }
 
 
-/* time */
-
-
-char *
-_g_time_to_string (time_t time)
-{
-       struct tm *tm;
-       char       s_time[256];
-       char      *locale_format = NULL;
-       char      *time_utf8;
-
-       tm = localtime (&time);
-       /* This is the time format used in the "Date Modified" column and
-        * in the Properties dialog.  See the man page of strftime for an
-        * explanation of the values. */
-       locale_format = g_locale_from_utf8 (_("%d %B %Y, %H:%M"), -1, NULL, NULL, NULL);
-       strftime (s_time, sizeof (s_time) - 1, locale_format, tm);
-       g_free (locale_format);
-       time_utf8 = g_locale_to_utf8 (s_time, -1, NULL, NULL, NULL);
-
-       return time_utf8;
-}
-
-
 /* uri/path/filename */
 
 
diff --git a/src/glib-utils.h b/src/glib-utils.h
index 2c7eaa39..e4723959 100644
--- a/src/glib-utils.h
+++ b/src/glib-utils.h
@@ -116,10 +116,6 @@ char **             _g_regexp_get_patternv         (const char          *pattern
 GRegex **           _g_regexp_split_from_patterns  (const char          *pattern_string,
                                                    GRegexCompileFlags   compile_options);
 
-/* time */
-
-char *              _g_time_to_string              (time_t               time);
-
 /* uri/path/filename */
 
 const char *        _g_uri_get_home                (void);


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