2020-04-16 23:18:54 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2019-09-19 00:45:11 +00:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Time.Clock
|
|
|
|
|
{
|
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
|
|
|
struct TimeSpanType
|
|
|
|
|
{
|
|
|
|
|
private const long NanoSecondsPerSecond = 1000000000;
|
|
|
|
|
|
2019-10-08 03:48:49 +00:00
|
|
|
|
public static readonly TimeSpanType Zero = new TimeSpanType(0);
|
|
|
|
|
|
2020-04-16 23:18:54 +00:00
|
|
|
|
private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
|
public long NanoSeconds;
|
|
|
|
|
|
|
|
|
|
public TimeSpanType(long nanoSeconds)
|
|
|
|
|
{
|
|
|
|
|
NanoSeconds = nanoSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long ToSeconds()
|
|
|
|
|
{
|
|
|
|
|
return NanoSeconds / NanoSecondsPerSecond;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 23:18:54 +00:00
|
|
|
|
public TimeSpanType AddSeconds(long seconds)
|
|
|
|
|
{
|
|
|
|
|
return new TimeSpanType(NanoSeconds + (seconds * NanoSecondsPerSecond));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsDaylightSavingTime()
|
|
|
|
|
{
|
|
|
|
|
return UnixEpoch.AddSeconds(ToSeconds()).ToLocalTime().IsDaylightSavingTime();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
|
public static TimeSpanType FromSeconds(long seconds)
|
|
|
|
|
{
|
|
|
|
|
return new TimeSpanType(seconds * NanoSecondsPerSecond);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 01:30:08 +00:00
|
|
|
|
public static TimeSpanType FromTimeSpan(TimeSpan timeSpan)
|
|
|
|
|
{
|
|
|
|
|
return new TimeSpanType((long)(timeSpan.TotalMilliseconds * 1000000));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
|
public static TimeSpanType FromTicks(ulong ticks, ulong frequency)
|
|
|
|
|
{
|
|
|
|
|
return FromSeconds((long)ticks / (long)frequency);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|