summaryrefslogtreecommitdiff
path: root/lib/timer.h
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2017-06-06 16:47:30 +0200
committerOndrej Zajicek (work) <santiago@crfreenet.org>2017-12-07 13:49:27 +0100
commitf047271cb963c62663687d63b2f7cf8dd5edfbb7 (patch)
treecec19ec5f00167aabc3a5233cef5bc6c5e384526 /lib/timer.h
parent025525266f6861437ca54aca2a86eb505a486baf (diff)
Timers: Parse and format functions for microsecond times
Date/time output (e.g. in logs, show commands) can use %f to specify subsecond time. By default, millisecond precision is used in output.
Diffstat (limited to 'lib/timer.h')
-rw-r--r--lib/timer.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/timer.h b/lib/timer.h
index b70ac48d..61a2aa94 100644
--- a/lib/timer.h
+++ b/lib/timer.h
@@ -105,4 +105,23 @@ void timers_fire(struct timeloop *loop);
void timer_init(void);
+struct timeformat {
+ char *fmt1, *fmt2;
+ btime limit;
+};
+
+#define TM_ISO_SHORT_S (struct timeformat){"%T", "%F", (s64) (20*3600) S_}
+#define TM_ISO_SHORT_MS (struct timeformat){"%T.%3f", "%F", (s64) (20*3600) S_}
+#define TM_ISO_SHORT_US (struct timeformat){"%T.%6f", "%F", (s64) (20*3600) S_}
+
+#define TM_ISO_LONG_S (struct timeformat){"%F %T", NULL, 0}
+#define TM_ISO_LONG_MS (struct timeformat){"%F %T.%3f", NULL, 0}
+#define TM_ISO_LONG_US (struct timeformat){"%F %T.%6f", NULL, 0}
+
+#define TM_DATETIME_BUFFER_SIZE 32 /* Buffer size required by tm_format_time() */
+
+btime tm_parse_time(char *x);
+void tm_format_time(char *x, struct timeformat *fmt, btime t);
+void tm_format_real_time(char *x, const char *fmt, btime t);
+
#endif