diff options
| author | dam <dam@gudinoff> | 2022-10-16 02:34:38 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2022-10-16 02:34:38 +0000 |
| commit | 39765b0018dc6530a9169379021931e0f7c5bcce (patch) | |
| tree | 1522c20cf350e454a7339f3c5b66dc1e46df82e3 | |
| parent | 14fac683284fe4725e1f68d069cbade0848fb4f3 (diff) | |
| download | task-time-tracker-39765b0018dc6530a9169379021931e0f7c5bcce.tar.zst task-time-tracker-39765b0018dc6530a9169379021931e0f7c5bcce.zip | |
Fixed format_time to change precision only when reaches halfway between current and next precision step.
| -rw-r--r-- | main.c | 12 |
1 files changed, 6 insertions, 6 deletions
@@ -129,16 +129,16 @@ char *format_time(char* string, intmax_t time, int length) { int left_padding = (length - 5) / 2; int right_padding = length - 5 - left_padding; - if (time > (intmax_t)9999 * SECONDS_IN_YEAR) { + if (time >= (intmax_t)(9999.5 * SECONDS_IN_YEAR)) { sprintf(string, "%*s ∞ %*s", left_padding, "", right_padding, ""); } - else if (time > (intmax_t)9999 * SECONDS_IN_DAY) { + else if (time >= (intmax_t)(9999.5 * SECONDS_IN_DAY)) { double value = (double)time / (double)SECONDS_IN_YEAR; int decimals = - time > 99 * SECONDS_IN_YEAR ? 0 : - time > 9 * SECONDS_IN_YEAR ? 1 : + time >= 99.95 * SECONDS_IN_YEAR ? 0 : + time >= 9.995 * SECONDS_IN_YEAR ? 1 : 2; sprintf(string, "%*s%4.*fy%*s", @@ -150,8 +150,8 @@ char *format_time(char* string, intmax_t time, int length) { else if (time >= (intmax_t)100 * SECONDS_IN_HOUR) { double value = (double)time / (double)SECONDS_IN_DAY; int decimals = - time > 99 * SECONDS_IN_DAY ? 0 : - time > 9 * SECONDS_IN_DAY ? 1 : + time >= 99.95 * SECONDS_IN_DAY ? 0 : + time >= 9.995 * SECONDS_IN_DAY ? 1 : 2; sprintf(string, "%*s%4.*fd%*s", |
