Files
Flypaper/src/Flypaper.Web/Components/Shared/Formatting.cs
T
TomandClaude Opus 5.5 3671019e60
Build and deploy / build (push) Successful in 1m46s
Build and deploy / deploy (push) Successful in 22s
Add IP origin enrichment with DB-IP and world map
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 15:44:33 +01:00

20 lines
877 B
C#

namespace Flypaper.Web.Components.Shared;
public static class Formatting
{
public static string Duration(TimeSpan duration) => duration switch
{
{ TotalDays: >= 1 } => $"{(int)duration.TotalDays} d {duration.Hours} h",
{ TotalHours: >= 1 } => $"{duration.Hours} h {duration.Minutes} min",
{ TotalMinutes: >= 1 } => $"{duration.Minutes} min {duration.Seconds} s",
_ => $"{duration.TotalSeconds:0.0} s"
};
public static string Flag(string? countryCode) =>
countryCode is { Length: 2 } && char.IsAsciiLetter(countryCode[0]) && char.IsAsciiLetter(countryCode[1])
? string.Concat(countryCode.ToUpperInvariant().Select(c => char.ConvertFromUtf32(0x1F1E6 + c - 'A')))
: "";
public static string? Provider(long? asn, string? provider) => asn is null ? provider : $"AS{asn} {provider}".TrimEnd();
}