diff options
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; +} |