From 96a50bc803949eaee393cd1499f57830ccbe88d3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Sat, 1 Apr 2017 12:06:22 -0700 Subject: [PATCH] time-plugin: Use GDateTime https://github.com/GNOME/gedit/commit/121f02a3ea066565eeae5dd42868f822ecce4924 --- plugins/time/xed-time-plugin.c | 58 ++++++---------------------------- 1 file changed, 10 insertions(+), 48 deletions(-) diff --git a/plugins/time/xed-time-plugin.c b/plugins/time/xed-time-plugin.c index 3fd3840..7d2983e 100644 --- a/plugins/time/xed-time-plugin.c +++ b/plugins/time/xed-time-plugin.c @@ -29,10 +29,6 @@ #endif #include -#include - -#include "xed-time-plugin.h" -#include #include #include @@ -43,6 +39,8 @@ #include #include #include +#include +#include "xed-time-plugin.h" #define XED_TIME_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \ XED_TYPE_TIME_PLUGIN, \ @@ -71,7 +69,6 @@ static const gchar *formats[] = "%a %d %b %Y %H:%M:%S", "%d/%m/%Y", "%d/%m/%y", - "%D", "%A %d %B %Y", "%A %B %d %Y", "%Y-%m-%d", @@ -88,9 +85,7 @@ static const gchar *formats[] = "%I.%M %p", "%d/%m/%Y %H:%M:%S", "%d/%m/%y %H:%M:%S", -#if __GLIBC__ >= 2 "%a, %d %b %Y %H:%M:%S %z", -#endif NULL }; @@ -319,58 +314,25 @@ get_custom_format (XedTimePlugin *plugin) } static gchar * -get_time (const gchar* format) +get_time (const gchar *format) { - gchar *out = NULL; - gchar *out_utf8 = NULL; - time_t clock; - struct tm *now; - size_t out_length = 0; - gchar *locale_format; + gchar *out; + GDateTime *now; xed_debug (DEBUG_PLUGINS); g_return_val_if_fail (format != NULL, NULL); - if (strlen (format) == 0) + if (*format == '\0') { return g_strdup (" "); } - locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL); - if (locale_format == NULL) - { - return g_strdup (" "); - } + now = g_date_time_new_now_local (); + out = g_date_time_format (now, format); + g_date_time_unref (now); - clock = time (NULL); - now = localtime (&clock); - - do - { - out_length += 255; - out = g_realloc (out, out_length); - } - while (strftime (out, out_length, locale_format, now) == 0); - - g_free (locale_format); - - if (g_utf8_validate (out, -1, NULL)) - { - out_utf8 = out; - } - else - { - out_utf8 = g_locale_to_utf8 (out, -1, NULL, NULL, NULL); - g_free (out); - - if (out_utf8 == NULL) - { - out_utf8 = g_strdup (" "); - } - } - - return out_utf8; + return out; } static void