Fix various issues in how %#T is handled:
- If precision is 0, don't print period followed by no digits. - If precision is 0 stop printing units as soon as possible (eg. if we have three years and five days and precision is 0 print only 3y5d). - If precision is not 0, print all units (eg. 3y0d0h0m0s.00). MFC after: 2 weeks
This commit is contained in:
parent
2868a01f09
commit
3d92417062
@ -80,6 +80,12 @@ __printf_render_time(struct __printf_io *io, const struct printf_info *pi, const
|
||||
nsec = 0;
|
||||
prec = 0;
|
||||
}
|
||||
if (pi->is_long || pi->is_long_double) {
|
||||
if (pi->prec >= 0)
|
||||
prec = pi->prec;
|
||||
if (prec == 0)
|
||||
nsec = 0;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
if (pi->alt) {
|
||||
@ -88,26 +94,24 @@ __printf_render_time(struct __printf_io *io, const struct printf_info *pi, const
|
||||
p += sprintf(p, "%jdy", t / YEAR);
|
||||
t %= YEAR;
|
||||
}
|
||||
if (t >= DAY && t != 0) {
|
||||
if (tx >= DAY && (t != 0 || prec != 0)) {
|
||||
p += sprintf(p, "%jdd", t / DAY);
|
||||
t %= DAY;
|
||||
}
|
||||
if (t >= HOUR && t != 0) {
|
||||
if (tx >= HOUR && (t != 0 || prec != 0)) {
|
||||
p += sprintf(p, "%jdh", t / HOUR);
|
||||
t %= HOUR;
|
||||
}
|
||||
if (t >= MINUTE && t != 0) {
|
||||
if (tx >= MINUTE && (t != 0 || prec != 0)) {
|
||||
p += sprintf(p, "%jdm", t / MINUTE);
|
||||
t %= MINUTE;
|
||||
}
|
||||
if (t != 0 || tx == 0)
|
||||
if (t != 0 || tx == 0 || prec != 0)
|
||||
p += sprintf(p, "%jds", t);
|
||||
} else {
|
||||
p += sprintf(p, "%jd", (intmax_t)t);
|
||||
}
|
||||
if (pi->is_long || pi->is_long_double) {
|
||||
if (pi->prec >= 0)
|
||||
prec = pi->prec;
|
||||
if (prec != 0) {
|
||||
for (i = prec; i < 9; i++)
|
||||
nsec /= 10;
|
||||
p += sprintf(p, ".%.*d", prec, nsec);
|
||||
|
Loading…
Reference in New Issue
Block a user