diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/misc.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/apps/misc.c b/apps/misc.c index e0496633e4..5b560dee16 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -894,16 +894,20 @@ char* skip_whitespace(char* const str) | |||
894 | */ | 894 | */ |
895 | void format_time(char* buf, int buf_size, long t) | 895 | void format_time(char* buf, int buf_size, long t) |
896 | { | 896 | { |
897 | if ( t < 3600000 ) | 897 | int const time = ABS(t / 1000); |
898 | int const hours = time / 3600; | ||
899 | int const minutes = time / 60 - hours * 60; | ||
900 | int const seconds = time % 60; | ||
901 | const char * const sign = &"-"[t < 0 ? 0 : 1]; | ||
902 | |||
903 | if ( hours == 0 ) | ||
898 | { | 904 | { |
899 | snprintf(buf, buf_size, "%d:%02d", | 905 | snprintf(buf, buf_size, "%s%d:%02d", sign, minutes, seconds); |
900 | (int) (t / 60000), (int) (t % 60000 / 1000)); | ||
901 | } | 906 | } |
902 | else | 907 | else |
903 | { | 908 | { |
904 | snprintf(buf, buf_size, "%d:%02d:%02d", | 909 | snprintf(buf, buf_size, "%s%d:%02d:%02d", sign, hours, minutes, |
905 | (int) (t / 3600000), (int) (t % 3600000 / 60000), | 910 | seconds); |
906 | (int) (t % 60000 / 1000)); | ||
907 | } | 911 | } |
908 | } | 912 | } |
909 | 913 | ||