You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Extensions/TimeSpanExtensions.cs

30 lines
816 B

2 years ago
// Copyright (c) MudBlazor
using System;
// ReSharper disable once CheckNamespace
internal static class TimeSpanExtensions
{
public static string ToIsoString(this TimeSpan self, bool seconds = false, bool ms = false)
{
if (!seconds)
return $"{self.Hours:D2}:{self.Minutes:D2}";
if (!ms)
return $"{self.Hours:D2}:{self.Minutes:D2}-{self.Seconds:D2}";
return $"{self.Hours:D2}:{self.Minutes:D2}-{self.Seconds:D2},{self.Milliseconds}";
}
public static string ToIsoString(this TimeSpan? self, bool seconds = false, bool ms = false)
{
return self?.ToIsoString(seconds, ms);
}
public static int ToAmPmHour(this TimeSpan time)
{
var h = time.Hours % 12;
if (h == 0)
h = 12;
return h;
}
}