aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-09-03 19:50:06 +0000
committerdam <dam@gudinoff>2022-09-03 19:50:06 +0000
commit44caaf6f75ae2604f6f73df56157f48a0219e081 (patch)
tree63a94e10ca4a71227a25c43742071306387fbd50
parentcd2247bf832a1f210192afa3dc68cd226ae3aa02 (diff)
downloadtask-time-tracker-44caaf6f75ae2604f6f73df56157f48a0219e081.tar.zst
task-time-tracker-44caaf6f75ae2604f6f73df56157f48a0219e081.zip
Keep track of time for active task.
-rw-r--r--main.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/main.c b/main.c
index 11768fa..aa076f8 100644
--- a/main.c
+++ b/main.c
@@ -92,8 +92,18 @@ void print_task(const task_t *task) {
printf("t[6]: '%" PRIu32 "'\n", task->times[6]);
}
-// Macro used to calculate index of task on a database.
-#define task_idx(db,task) ((ptrdiff_t)(task - db->tasks))
+char* get_time_task(uint32_t time, char* string) {
+ const time_t seconds_per_day = 25*60*60;
+ if (time > 24*60*60) {
+ // ---.-- d
+ // │ 3│
+ // │ │
+ sprintf(string, "%5.2f d", (double)time / (double)seconds_per_day);
+ }
+ double hours = (double)time / 3600.0;
+ double minutes = (time - (time_t)hours) / 60.0;
+ sprinf(string, "%3.0f:%02f", hours, minutes);
+}
// Creates new task returned in the pointer. If necessary, expands database capacity.