@@ -4,11 +4,13 @@ void ffDurationAppendNum(uint64_t totalSeconds, FFstrbuf* result)
4
4
{
5
5
const FFOptionsDisplay * options = & instance .config .display ;
6
6
7
- const char * space = instance . config . display . durationSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER ? " " : "" ;
7
+ bool spaceBeforeUnit = options -> durationSpaceBeforeUnit != FF_SPACE_BEFORE_UNIT_NEVER ;
8
8
9
- if (totalSeconds < 60 )
9
+ if (totalSeconds < 60 )
10
10
{
11
- ffStrbufAppendF (result , options -> durationAbbreviation ? "%u%ssec" : "%u%ssecond" , (unsigned ) totalSeconds , space );
11
+ ffStrbufAppendUInt (result , totalSeconds );
12
+ if (spaceBeforeUnit ) ffStrbufAppendC (result , ' ' );
13
+ ffStrbufAppendS (result , options -> durationAbbreviation ? "sec" : "second" );
12
14
if (totalSeconds != 1 )
13
15
ffStrbufAppendC (result , 's' );
14
16
return ;
@@ -25,63 +27,56 @@ void ffDurationAppendNum(uint64_t totalSeconds, FFstrbuf* result)
25
27
totalSeconds /= 24 ;
26
28
uint32_t days = (uint32_t ) totalSeconds ;
27
29
28
- if (days > 0 )
30
+ if (days > 0 )
29
31
{
30
- if (options -> durationAbbreviation )
32
+ ffStrbufAppendUInt (result , days );
33
+ if (spaceBeforeUnit ) ffStrbufAppendC (result , ' ' );
34
+ if (options -> durationAbbreviation )
31
35
{
32
- ffStrbufAppendF (result , "%u%sd" , days , space );
36
+ ffStrbufAppendC (result , 'd' );
33
37
34
- if (hours > 0 || minutes > 0 )
38
+ if (hours > 0 || minutes > 0 )
35
39
ffStrbufAppendC (result , ' ' );
36
40
}
37
41
else
38
42
{
39
- ffStrbufAppendF (result , "%u%sday" , days , space );
43
+ ffStrbufAppendS (result , days == 1 ? "day" : "days" );
40
44
41
- if (days > 1 )
42
- ffStrbufAppendC (result , 's' );
43
-
44
- if (days >= 100 )
45
+ if (days >= 100 )
45
46
ffStrbufAppendS (result , "(!)" );
46
47
47
- if (hours > 0 || minutes > 0 )
48
+ if (hours > 0 || minutes > 0 )
48
49
ffStrbufAppendS (result , ", " );
49
50
}
50
51
}
51
52
52
- if (hours > 0 )
53
+ if (hours > 0 )
53
54
{
54
- if (options -> durationAbbreviation )
55
+ ffStrbufAppendUInt (result , hours );
56
+ if (spaceBeforeUnit ) ffStrbufAppendC (result , ' ' );
57
+ if (options -> durationAbbreviation )
55
58
{
56
- ffStrbufAppendF (result , "%u%sh" , hours , space );
59
+ ffStrbufAppendC (result , 'h' );
57
60
58
61
if (minutes > 0 )
59
62
ffStrbufAppendC (result , ' ' );
60
63
}
61
64
else
62
65
{
63
- ffStrbufAppendF (result , "%u%shour" , hours , space );
64
-
65
- if (hours > 1 )
66
- ffStrbufAppendC (result , 's' );
66
+ ffStrbufAppendS (result , hours == 1 ? "hour" : "hours" );
67
67
68
- if (minutes > 0 )
68
+ if (minutes > 0 )
69
69
ffStrbufAppendS (result , ", " );
70
70
}
71
71
}
72
72
73
- if (minutes > 0 )
73
+ if (minutes > 0 )
74
74
{
75
- if ( options -> durationAbbreviation )
76
- {
77
- ffStrbufAppendF ( result , "%u%sm" , minutes , space );
78
- }
75
+ ffStrbufAppendUInt ( result , minutes );
76
+ if ( spaceBeforeUnit ) ffStrbufAppendC ( result , ' ' );
77
+ if ( options -> durationAbbreviation )
78
+ ffStrbufAppendC ( result , 'm' );
79
79
else
80
- {
81
- ffStrbufAppendF (result , "%u%smin" , minutes , space );
82
-
83
- if (minutes > 1 )
84
- ffStrbufAppendC (result , 's' );
85
- }
80
+ ffStrbufAppendS (result , minutes == 1 ? "min" : "mins" );
86
81
}
87
82
}
0 commit comments