time: display minute/month such that it can be parsed again

Previously we displayed, e.g., "4m 1h 1min", i.e. using "m" for months
and "min" for minutes but "m"  was not accepted as month when parsing
a timespan string, so a 4 month timespan would be printed "4m" but if
parsed again it would result in a timespan of 4 minutes.

So switch month to an uppercase "M" and minute to the lower case "m",
which makes renderings of common timespans nicer, as in most of our
use cases they are in the range of minutes to hours, sometimes days
but seldom longer than weeks. So using single letters for all but
"min" stuck out quite a bit, e.g.: "1h 5min 2s" looks odd compared to
"1h 5m 1s"

While the duplicate letter is not 100% ideal it's still better than
the status quo, where rendering and parsing would interpret things
differently.
Also, the order still makes it quite clear, e.g.:
"7m 2w 3d 1h 5min 44s" now becomes "7M 2w 3d 1h 5m 44s"

As a side effect this also brings the display format closer to what is
used inside PVE backup job taks logs.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2024-10-17 12:18:22 +02:00
parent 9ae91303fd
commit 191299605f

View File

@ -155,7 +155,7 @@ impl std::fmt::Display for TimeSpan {
do_write(self.years, "y")?;
}
if self.months > 0 {
do_write(self.months, "m")?;
do_write(self.months, "M")?;
}
if self.weeks > 0 {
do_write(self.weeks, "w")?;
@ -167,7 +167,7 @@ impl std::fmt::Display for TimeSpan {
do_write(self.hours, "h")?;
}
if self.minutes > 0 {
do_write(self.minutes, "min")?;
do_write(self.minutes, "m")?;
}
}
let seconds = self.seconds as f64 + (self.msec as f64 / 1000.0);