From c8c0af300dde117a839f2d5d6b777694d7f118e9 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 28 Apr 2025 14:11:28 -0400 Subject: Minor restructure and dependency updates Signed-off-by: Andrew Opalach --- src/util/print_time.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/util/print_time.h (limited to 'src/util') diff --git a/src/util/print_time.h b/src/util/print_time.h new file mode 100644 index 0000000..d9dd4cc --- /dev/null +++ b/src/util/print_time.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +static inline s32 camu_print_time(char *buf, size_t size, u64 nanoseconds, bool always_show_hour, u32 hour_padding) +{ + u32 hours = nanoseconds / 3600000000u; + u32 minutes = nanoseconds / 60000000u; + bool show_hour = always_show_hour || minutes >= 60u; + u32 seconds = nanoseconds / 1000000u; + seconds -= minutes * 60u; + minutes -= hours * 60u; + s32 offset = 0; + if (show_hour) { + static const char *padding_table[] = { "%.2u:", "%.3u:", "%.4u:" }; + hour_padding = CLAMP(hour_padding, 2u, 4u) - 2u; + offset += al_snprintf(buf, size, padding_table[hour_padding], hours); + } + offset += al_snprintf(buf + offset, size - offset, "%.2u:%.2u", minutes, seconds); + return offset; +} -- cgit v1.2.3-101-g0448