aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-10-16 02:34:38 +0000
committerdam <dam@gudinoff>2022-10-16 02:34:38 +0000
commit39765b0018dc6530a9169379021931e0f7c5bcce (patch)
tree1522c20cf350e454a7339f3c5b66dc1e46df82e3 /main.c
parent14fac683284fe4725e1f68d069cbade0848fb4f3 (diff)
downloadtask-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.
Diffstat (limited to 'main.c')
-rw-r--r--main.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/main.c b/main.c
index ab8bef8..4331792 100644
--- a/main.c
+++ b/main.c
@@ -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",