introduce implicit converters for UnixTime & UnixTimeSpan
This commit is contained in:
parent
c3b1484e99
commit
17c2a959e6
|
@ -3,4 +3,7 @@ namespace InnovEnergy.Lib.Time.Unix;
|
|||
public readonly partial struct UnixTime
|
||||
{
|
||||
public DateTime ToUtcDateTime() => DateTime.UnixEpoch + TimeSpan.FromSeconds(Ticks);
|
||||
|
||||
public static implicit operator DateTime(UnixTime unixTimeSpan) => unixTimeSpan.ToUtcDateTime();
|
||||
public static implicit operator UnixTime(DateTime dateTime) => FromUtcDateTime(dateTime);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
namespace InnovEnergy.Lib.Time.Unix;
|
||||
|
||||
public readonly partial struct UnixTimeSpan
|
||||
{
|
||||
public TimeSpan ToTimeSpan() => TimeSpan.FromSeconds(Ticks);
|
||||
|
||||
public static implicit operator TimeSpan(UnixTimeSpan unixTimeSpan) => unixTimeSpan.ToTimeSpan();
|
||||
public static implicit operator UnixTimeSpan(TimeSpan timeSpan) => FromTimeSpan(timeSpan);
|
||||
}
|
|
@ -4,8 +4,5 @@ public readonly partial struct UnixTimeSpan
|
|||
{
|
||||
public UInt32 Ticks { get; }
|
||||
|
||||
public TimeSpan ToTimeSpan()
|
||||
{
|
||||
return TimeSpan.FromSeconds(Ticks);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
namespace InnovEnergy.Lib.Time.Unix;
|
||||
|
||||
public static class UnixTimeDeltaExtensions
|
||||
public static class UnixTimeSpanExtensions
|
||||
{
|
||||
public static UnixTimeSpan Seconds(this Int32 s) => UnixTimeSpan.FromSeconds(s);
|
||||
public static UnixTimeSpan Minutes(this Int32 m) => UnixTimeSpan.FromMinutes(m);
|
||||
|
|
Loading…
Reference in New Issue