namespace Blog; /// /// Short human renderings of numbers that would otherwise be printed raw. /// public static class Format { /// /// A duration as the largest two units that carry information — "3d 4h", "1h 4m", "3m 20s", /// "42s" — matching what the bot itself prints in chat. Null renders as "?", since a duration /// we don't know is not the same as one of zero. /// public static string Duration(TimeSpan? span) { if (span is not { } value) return "?"; if (value < TimeSpan.Zero) value = TimeSpan.Zero; return value switch { { TotalDays: >= 1 } => $"{(int)value.TotalDays}d {value.Hours}h", { TotalHours: >= 1 } => $"{(int)value.TotalHours}h {value.Minutes}m", { TotalMinutes: >= 1 } => $"{(int)value.TotalMinutes}m {value.Seconds}s", _ => $"{(int)value.TotalSeconds}s" }; } }