diff options
| author | 2025-04-28 14:11:28 -0400 | |
|---|---|---|
| committer | 2025-04-28 14:11:28 -0400 | |
| commit | c8c0af300dde117a839f2d5d6b777694d7f118e9 (patch) | |
| tree | 3297f1ba256da0b837fbaa9c581d7f420ce98a4a /src/util | |
| parent | 61492af23ecc5dd9ab4956a84a7c0451deb8b84b (diff) | |
| download | camu-c8c0af300dde117a839f2d5d6b777694d7f118e9.tar.gz camu-c8c0af300dde117a839f2d5d6b777694d7f118e9.tar.bz2 camu-c8c0af300dde117a839f2d5d6b777694d7f118e9.zip | |
Minor restructure and dependency updates
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/print_time.h | 21 |
1 files changed, 21 insertions, 0 deletions
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 <al/lib.h> + +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; +} |