From 191299605f82dcfe5382b48ed93bdc7f0183f5b4 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 17 Oct 2024 12:18:22 +0200 Subject: [PATCH] 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 --- proxmox-time/src/time_span.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxmox-time/src/time_span.rs b/proxmox-time/src/time_span.rs index c645ac38..8c96f94f 100644 --- a/proxmox-time/src/time_span.rs +++ b/proxmox-time/src/time_span.rs @@ -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);