Host C Specs


Directory: src/c/
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 14 / 0 / 14
Functions: 100.0% 2 / 0 / 2
Branches: 100.0% 6 / 0 / 6

core/clock/duration.c
Line Branch Exec Source
1 /**
2 * @file duration.c
3 * @brief A minute count turned into a short human duration.
4 *
5 * @ingroup lib_core
6 */
7 #include "clock/duration.h"
8
9 #include <stdio.h>
10
11 4 void duration_hm(char *out, size_t n, int minutes)
12 {
13
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (minutes < 0)
14 {
15 1 minutes = 0;
16 }
17 4 snprintf(out, n, "%d:%02d", minutes / 60, minutes % 60);
18 4 }
19
20 4 void duration_hm_compact(char *out, size_t n, int minutes)
21 {
22
2/2
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 3 times.
4 if (minutes < 0)
23 {
24 1 minutes = 0;
25 }
26
27 4 int hours = minutes / 60;
28 4 int mins = minutes % 60;
29
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if (hours > 0)
30 {
31 2 snprintf(out, n, "%dh %dm", hours, mins);
32 }
33 else
34 {
35 2 snprintf(out, n, "%dm", mins);
36 }
37 4 }
38