20 lines
752 B
C#
20 lines
752 B
C#
namespace DeepDrftPublic.Client.Helpers;
|
|
|
|
/// <summary>
|
|
/// Formats a runtime expressed in seconds as a compact <c>hh:mm</c> string for the home hero stat row.
|
|
/// Hours are not zero-padded and may exceed two digits (mixes are few, so a large total simply renders
|
|
/// "123:45"); minutes are always two digits. Negative or non-finite inputs clamp to "0:00".
|
|
/// </summary>
|
|
public static class RuntimeFormat
|
|
{
|
|
public static string ToHoursMinutes(double totalSeconds)
|
|
{
|
|
if (double.IsNaN(totalSeconds) || double.IsInfinity(totalSeconds) || totalSeconds <= 0)
|
|
return "0:00";
|
|
|
|
var total = TimeSpan.FromSeconds(totalSeconds);
|
|
var hours = (int)total.TotalHours;
|
|
return $"{hours}:{total.Minutes:D2}";
|
|
}
|
|
}
|