namespace Xorog.UniversalExtensions; public static class TimeExtensions { /// /// Get a timespan from now to the given time. Negative on values in the past. /// /// /// public static TimeSpan GetTimespanUntil(this DateTime until) => (until.ToUniversalTime() - DateTime.UtcNow); /// /// /// /// /// public static TimeSpan GetTimespanUntil(this DateTimeOffset until) => (until.ToUniversalTime() - DateTime.UtcNow); /// /// Get the total seconds until a given DateTime. Negative on values in the past. /// /// /// public static long GetTotalSecondsUntil(this DateTime until) => ((long)Math.Ceiling((until.ToUniversalTime() - DateTime.UtcNow).TotalSeconds)); /// /// /// /// /// public static long GetTotalSecondsUntil(this DateTimeOffset until) => ((long)Math.Ceiling((until.ToUniversalTime() - DateTime.UtcNow).TotalSeconds)); /// /// Get a timespan from now to the given time. Negative on values in the future. /// /// /// public static TimeSpan GetTimespanSince(this DateTime until) => (DateTime.UtcNow - until.ToUniversalTime()); /// /// /// /// /// public static TimeSpan GetTimespanSince(this DateTimeOffset until) => (DateTime.UtcNow - until.ToUniversalTime()); /// /// Get the total seconds since a given DateTime. Negative on values in the future. /// /// /// public static long GetTotalSecondsSince(this DateTime until) => ((long)Math.Ceiling((DateTime.UtcNow - until.ToUniversalTime()).TotalSeconds)); /// /// /// /// /// public static long GetTotalSecondsSince(this DateTimeOffset until) => ((long)Math.Ceiling((DateTime.UtcNow - until.ToUniversalTime()).TotalSeconds)); /// /// Get a short human readable string for the given amount of seconds /// /// /// /// public static string GetShortHumanReadable(this int seconds, TimeFormat timeFormat = TimeFormat.Days) => TimeSpan.FromSeconds(seconds).GetShortTimeFormat(timeFormat); /// /// /// /// /// /// public static string GetShortHumanReadable(this long seconds, TimeFormat timeFormat = TimeFormat.Days) => TimeSpan.FromSeconds(seconds).GetShortTimeFormat(timeFormat); /// /// Get a short human readable string for the given amount of time /// /// /// /// public static string GetShortHumanReadable(this TimeSpan timespan, TimeFormat timeFormat = TimeFormat.Days) => timespan.GetShortTimeFormat(timeFormat); /// /// Get a human readable string for the given amount of time. /// /// /// /// public static string GetHumanReadable(this int seconds, TimeFormat timeFormat = TimeFormat.Days, HumanReadableTimeFormatConfig? config = null) => TimeSpan.FromSeconds(seconds).GetTimeFormat(timeFormat, config); /// public static string GetHumanReadable(this long seconds, TimeFormat timeFormat = TimeFormat.Days, HumanReadableTimeFormatConfig? config = null) => TimeSpan.FromSeconds(seconds).GetTimeFormat(timeFormat, config); /// public static string GetHumanReadable(this TimeSpan timeSpan, TimeFormat timeFormat = TimeFormat.Days, HumanReadableTimeFormatConfig? config = null) => timeSpan.GetTimeFormat(timeFormat, config); }