-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDurationFormat.cs
More file actions
25 lines (21 loc) · 855 Bytes
/
Copy pathDurationFormat.cs
File metadata and controls
25 lines (21 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using System.Globalization;
namespace RustPlusBot.Features.Commands.Formatting;
/// <summary>Formats durations compactly for in-game replies.</summary>
internal static class DurationFormat
{
/// <summary>Renders a duration as "Xd Yh" / "Yh Zm" / "Zm".</summary>
/// <param name="span">The duration to render.</param>
/// <returns>A compact duration string.</returns>
public static string Compact(TimeSpan span)
{
if (span.TotalDays >= 1)
{
return string.Create(CultureInfo.InvariantCulture, $"{(int)span.TotalDays}d {span.Hours}h");
}
if (span.TotalHours >= 1)
{
return string.Create(CultureInfo.InvariantCulture, $"{(int)span.TotalHours}h {span.Minutes}m");
}
return string.Create(CultureInfo.InvariantCulture, $"{(int)span.TotalMinutes}m");
}
}