[backend/core] Refactor NumberExtensions
This commit is contained in:
parent
6adfa87966
commit
9319dc22c9
1 changed files with 8 additions and 27 deletions
|
@ -20,39 +20,20 @@ public static class NumberExtensions
|
||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToBase36(this int input)
|
public static string ToBase36(this int input) => ToBase36((long)input);
|
||||||
{
|
|
||||||
if (input == 0) return "0";
|
|
||||||
var result = new StringBuilder();
|
|
||||||
|
|
||||||
while (input >= 0)
|
|
||||||
{
|
|
||||||
result.Insert(0, Base36Charset[input % 36]);
|
|
||||||
input /= 36;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string ToDurationDisplayString(this long input)
|
public static string ToDurationDisplayString(this long input)
|
||||||
{
|
{
|
||||||
|
var ts = TimeSpan.FromMilliseconds(input);
|
||||||
|
|
||||||
return input switch
|
return input switch
|
||||||
{
|
{
|
||||||
< 1000 => $"{input} ms",
|
< 1000 => $"{input} ms",
|
||||||
< 1000 * 60 => $"{Math.Round(input / 1000d / 60d, 2)} s",
|
< 1000 * 60 => $"{Math.Round(input / 1000d, 2)} s",
|
||||||
< 1000 * 60 * 60 => $"{Math.Round(input / 60000d / 60d, 2)} m",
|
< 1000 * 60 * 60 => $"{ts.Minutes}m {ts.Seconds}s",
|
||||||
_ => $"{Math.Round(input / 60000d / 60d / 60d, 2)} h"
|
_ => $"{Math.Truncate(ts.TotalHours)}h {ts.Minutes}m"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ToDurationDisplayString(this int input)
|
public static string ToDurationDisplayString(this int input) => ToDurationDisplayString((long)input);
|
||||||
{
|
|
||||||
return input switch
|
|
||||||
{
|
|
||||||
< 1000 => $"{input} ms",
|
|
||||||
< 1000 * 60 => $"{Math.Round(input / 1000d / 60d, 2)} s",
|
|
||||||
< 1000 * 60 * 60 => $"{Math.Round(input / 60000d / 60d, 2)} m",
|
|
||||||
_ => $"{Math.Round(input / 60000d / 60d / 60d, 2)} h"
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue