]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
usability: use ISO-8601 timestamp
authorSami Kerola <kerolasa@iki.fi>
Mon, 29 Aug 2016 18:45:36 +0000 (19:45 +0100)
committerSami Kerola <kerolasa@iki.fi>
Mon, 29 Aug 2016 18:47:58 +0000 (19:47 +0100)
The ISO timestamp has timezone information, and is easily parsable.

curses.c
report.c
utils.c
utils.h

index 001d3a711fdc811d5ff5446b345cce88a55065fe..74e6076c03701fc7bce51ed2ce5454fbc260a31a 100644 (file)
--- a/curses.c
+++ b/curses.c
@@ -656,7 +656,8 @@ extern void mtr_curses_redraw(struct mtr_ctl *ctl)
   }
   */
   time(&t);
-  mvprintw(1, maxx-25, ctime(&t));
+  mvprintw(1, maxx-25, iso_time(&t));
+  printw("\n");
 
   printw("Keys:  ");
   attron(A_BOLD); printw("H"); attroff(A_BOLD); printw("elp   ");
index 46f6ae52da31c1d0e43426c6a32a247e59997f76..c6f98ac7e9ff56be351ccde863bb4b7ca9f89924 100644 (file)
--- a/report.c
+++ b/report.c
@@ -32,6 +32,7 @@
 #include "net.h"
 #include "dns.h"
 #include "asn.h"
+#include "utils.h"
 
 #define MAXLOADBAL 5
 #define MAX_FORMAT_STR 81
 extern void report_open(void)
 {
   const time_t now = time(NULL);
-  char *t = ctime (&now);
-  const size_t len = strlen(t);
+  const char *t = iso_time (&now);
 
-  if (t[len - 1] == '\n')
-    t[len - 1] = '\0';
   printf ("Start: %s\n", t);
 }
 
diff --git a/utils.c b/utils.c
index 0a98e6c598becfa89752a15f4e33fc0d62604018..55fec05fae2cb8333504747644d95f90aa54570d 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -25,6 +25,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <time.h>
 #include <unistd.h>
 
 #ifdef HAVE_ERROR_H
@@ -147,3 +148,15 @@ extern void close_stdout(void)
   if (close_stream(stderr) != 0)
     _exit(EXIT_FAILURE);
 }
+
+/* ctime() replacement that will reteturn ISO-8601 timestamp string such as:
+ * 2016-08-29T19:25:02+01:00 */
+extern const char *iso_time(const time_t *t)
+{
+  static char s[32];
+  struct tm *tm;
+
+  tm = localtime(t);
+  strftime(s, sizeof(s), "%Y-%m-%dT%H:%M:%S%z", tm);
+  return s;
+}
diff --git a/utils.h b/utils.h
index 437bca0b7db64663e4950ea956d06132d78394e6..cb06899cd9b8a9751bcd34d9ebb5df66c3d6e607 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -37,3 +37,5 @@ extern void *xmalloc(const size_t size);
 extern char *xstrdup(const char *str);
 
 extern void close_stdout(void);
+
+extern const char *iso_time(const time_t *t);