Innovenergy_trunk/csharp/lib/Time/Unix/UnixTime.Constructors.cs

20 lines
642 B
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
namespace InnovEnergy.Time.Unix;
public readonly partial struct UnixTime
{
private UnixTime(UInt32 ticks) => Ticks = ticks;
public static UnixTime FromTicks(UInt32 ticks) => new UnixTime(ticks);
public static UnixTime FromTicks(Int32 ticks) => new UnixTime((UInt32) ticks);
public static UnixTime FromUtcDateTime(DateTime dateTime)
{
var timeSinceEpoch = dateTime - DateTime.UnixEpoch;
var ticks = (UInt32) timeSinceEpoch.TotalSeconds;
return new UnixTime(ticks);
}
public static UnixTime Epoch => new UnixTime(0);
public static UnixTime Now => FromUtcDateTime(DateTime.UtcNow);
}