Innovenergy_trunk/csharp/Lib/Time/Unix/UnixTimeSpan.Overrides.cs

50 lines
1.1 KiB
C#

using System.Text;
namespace InnovEnergy.Lib.Time.Unix;
public readonly partial struct UnixTimeSpan
{
public override String ToString()
{
var sb = new StringBuilder();
var dt = ToTimeSpan();
var weeks = dt.Days / 7;
var days = dt.Days % 7;
if (weeks > 0)
{
sb.Append(weeks);
sb.Append("w ");
}
if (days > 0)
{
sb.Append(days);
sb.Append("d ");
}
if (dt.Hours > 0)
{
sb.Append(dt.Hours);
sb.Append("h ");
}
if (dt.Minutes > 0)
{
sb.Append(dt.Minutes);
sb.Append("m ");
}
if (dt.Seconds > 0)
{
sb.Append(dt.Seconds);
sb.Append("s");
}
return sb.ToString().Trim();
}
public override Boolean Equals(Object? obj) => obj is UnixTime other && Ticks == other.Ticks;
public override Int32 GetHashCode() => (Int32) (Ticks & 0x7F_FF_FF_FF);
public static UnixTimeSpan Forever { get; } = FromTicks(UInt32.MaxValue) / 1.Weeks() * 1.Weeks();
}