summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-08-03 22:17:09 +0200
committerraveit65 <[email protected]>2020-09-01 22:03:58 +0200
commitbba42125fb0d1dd10246e20e0b1156b5c40620f7 (patch)
tree19d194cfa2764b822d5dca384a98fb6f255950d8 /plugins
parentde6bc223dfdd1610064317c44e892523b05a0cb7 (diff)
downloadpluma-bba42125fb0d1dd10246e20e0b1156b5c40620f7.tar.bz2
pluma-bba42125fb0d1dd10246e20e0b1156b5c40620f7.tar.xz
pluma-time-plugin: Use g_date_time_format
Diffstat (limited to 'plugins')
-rw-r--r--plugins/time/pluma-time-plugin.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/plugins/time/pluma-time-plugin.c b/plugins/time/pluma-time-plugin.c
index 59cb53bc..b0f3e2b5 100644
--- a/plugins/time/pluma-time-plugin.c
+++ b/plugins/time/pluma-time-plugin.c
@@ -31,7 +31,6 @@
#endif
#include <string.h>
-#include <time.h>
#include "pluma-time-plugin.h"
#include <pluma/pluma-help.h>
@@ -87,9 +86,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
};
@@ -406,50 +403,21 @@ set_custom_format (GSettings *settings,
static gchar *
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;
-
- pluma_debug (DEBUG_PLUGINS);
-
- g_return_val_if_fail (format != NULL, NULL);
-
- if (strlen (format) == 0)
- return g_strdup (" ");
-
- locale_format = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
- if (locale_format == NULL)
- return g_strdup (" ");
-
- clock = time (NULL);
- now = localtime (&clock);
+ gchar *out;
+ GDateTime *now;
- do
- {
- out_length += 255;
- out = g_realloc (out, out_length);
- }
- while (strftime (out, out_length, locale_format, now) == 0);
+ pluma_debug (DEBUG_PLUGINS);
- g_free (locale_format);
+ g_return_val_if_fail (format != NULL, NULL);
- 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 (*format == '\0')
+ return g_strdup (" ");
- if (out_utf8 == NULL)
- out_utf8 = g_strdup (" ");
- }
+ now = g_date_time_new_now_local ();
+ out = g_date_time_format (now, format);
+ g_date_time_unref (now);
- return out_utf8;
+ return out;
}
static void