[sysprof: 37/63] libsysprof-capture: Use strftime() to format dates rather than GLib



commit e8a6474236f945d1d7675f0e25d68cfc5137eb84
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Jul 2 12:15:04 2020 +0100

    libsysprof-capture: Use strftime() to format dates rather than GLib
    
    This means we lose support for local timezones other than UTC, but is
    otherwise equivalent.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>
    
    Helps: #40

 src/libsysprof-capture/sysprof-capture-writer.c | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)
---
diff --git a/src/libsysprof-capture/sysprof-capture-writer.c b/src/libsysprof-capture/sysprof-capture-writer.c
index 88c5697..ca3dd56 100644
--- a/src/libsysprof-capture/sysprof-capture-writer.c
+++ b/src/libsysprof-capture/sysprof-capture-writer.c
@@ -478,8 +478,8 @@ SysprofCaptureWriter *
 sysprof_capture_writer_new_from_fd (int    fd,
                                     size_t buffer_size)
 {
-  g_autofree gchar *nowstr = NULL;
-  g_autoptr(GDateTime) now = NULL;
+  time_t now;
+  char now_str[sizeof ("2020-06-30T14:34:00Z")];
   SysprofCaptureWriter *self;
   SysprofCaptureFileHeader *header;
   size_t header_len = sizeof(*header);
@@ -511,18 +511,14 @@ sysprof_capture_writer_new_from_fd (int    fd,
   self->len = buffer_size;
   self->next_counter_id = 1;
 
-  now = g_date_time_new_now_local ();
-
-#if GLIB_CHECK_VERSION(2, 62, 0)
-  nowstr = g_date_time_format_iso8601 (now);
-#else
-  {
-    GTimeVal tv;
-
-    g_date_time_to_timeval (now, &tv);
-    nowstr = g_time_val_to_iso8601 (&tv);
-  }
-#endif
+  /* Format the time as ISO 8601, in UTC */
+  time (&now);
+  if (strftime (now_str, sizeof (now_str), "%FT%TZ", gmtime (&now)) == 0)
+    {
+      free (self->buf);
+      free (self);
+      return NULL;
+    }
 
   header = sysprof_capture_writer_allocate (self, &header_len);
 


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