[gnome-todo] log: Replace GTimeVal by GDateTime



commit 5fc6c5111cf3d64ed1a0e91e0e16eb4509d787d9
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Sat Sep 21 10:42:53 2019 -0300

    log: Replace GTimeVal by GDateTime
    
    GTimeVal is not prepared for the year 2032 overflow,
    whereas GDateTime's microseconds is.
    
    Use GDateTime instead.
    
    https://gitlab.gnome.org/GNOME/gnome-todo/issues/282

 src/logging/gtd-log.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)
---
diff --git a/src/logging/gtd-log.c b/src/logging/gtd-log.c
index 96c0cf2..8a154e6 100644
--- a/src/logging/gtd-log.c
+++ b/src/logging/gtd-log.c
@@ -56,25 +56,23 @@ gtd_log_handler (const gchar    *domain,
                   const gchar    *message,
                   gpointer        user_data)
 {
-  GTimeVal tv;
-  struct tm tt;
-  time_t t;
+  g_autoptr (GDateTime) now = NULL;
+  g_autofree gchar *buffer = NULL;
+  g_autofree gchar *ftime = NULL;
   const gchar *level;
-  gchar ftime[32];
-  gchar *buffer;
+  gint microsecond;
 
   /* Skip ignored log domains */
   if (domain && g_strv_contains (ignored_domains, domain))
     return;
 
   level = log_level_str (log_level);
-  g_get_current_time (&tv);
-  t = (time_t) tv.tv_sec;
-  tt = *localtime (&t);
-  strftime (ftime, sizeof (ftime), "%H:%M:%S", &tt);
-  buffer = g_strdup_printf ("%s.%04ld  %24s: %s: %s\n",
+  now = g_date_time_new_now_local ();
+  ftime = g_date_time_format (now, "%H:%M:%S");
+  microsecond = g_date_time_get_microsecond (now);
+  buffer = g_strdup_printf ("%s.%04d  %28s: %s: %s\n",
                             ftime,
-                            tv.tv_usec / 1000,
+                            microsecond,
                             domain,
                             level,
                             message);
@@ -86,8 +84,6 @@ gtd_log_handler (const gchar    *domain,
   g_io_channel_flush (standard_channel, NULL);
 
   G_UNLOCK (channel_lock);
-
-  g_free (buffer);
 }
 
 void


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