From f047271cb963c62663687d63b2f7cf8dd5edfbb7 Mon Sep 17 00:00:00 2001 From: "Ondrej Zajicek (work)" Date: Tue, 6 Jun 2017 16:47:30 +0200 Subject: 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. --- lib/timer.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/timer.h') 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 -- cgit v1.2.3