This commit is contained in:
Garry Newman 2019-04-16 14:40:59 +01:00
parent 8e97489def
commit 603bd95c38
4 changed files with 39 additions and 36 deletions

View File

@ -95,7 +95,7 @@ internal static void InstallEvents()
/// <summary>
/// Returns the time of the purchase of the app
/// </summary>
public static DateTime PurchaseTime( AppId appid ) => Utility.Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );
public static DateTime PurchaseTime( AppId appid ) => Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );
/// <summary>
/// Checks if the user is subscribed to the current app through a free weekend

View File

@ -68,7 +68,7 @@ internal static void InstallEvents()
/// <summary>
/// Steam server time. Number of seconds since January 1, 1970, GMT (i.e unix time)
/// </summary>
public static DateTime SteamServerTime => Utility.Epoch.ToDateTime( Internal.GetServerRealTime() );
public static DateTime SteamServerTime => Epoch.ToDateTime( Internal.GetServerRealTime() );
/// <summary>
/// returns the 2 digit ISO 3166-1-alpha-2 format country code this client is running in (as looked up via an IP-to-location database)

View File

@ -0,0 +1,36 @@
using System;
namespace Steamworks
{
static internal class Epoch
{
private static readonly DateTime epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
/// <summary>
/// Returns the current Unix Epoch
/// </summary>
public static int Current
{
get
{
return (int)(DateTime.UtcNow.Subtract( epoch ).TotalSeconds);
}
}
/// <summary>
/// Convert an epoch to a datetime
/// </summary>
public static DateTime ToDateTime( decimal unixTime )
{
return epoch.AddSeconds( (long)unixTime );
}
/// <summary>
/// Convert a DateTime to a unix time
/// </summary>
public static uint FromDateTime( DateTime dt )
{
return (uint)(dt.Subtract( epoch ).TotalSeconds);
}
}
}

View File

@ -7,7 +7,7 @@
namespace Steamworks
{
public static partial class Utility
public static partial class Utility
{
static internal uint Swap( uint x )
{
@ -27,39 +27,6 @@ static public IPAddress Int32ToIp( uint ipAddress )
return new IPAddress( Swap( ipAddress ) );
}
static internal class Epoch
{
private static readonly DateTime epoch = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );
/// <summary>
/// Returns the current Unix Epoch
/// </summary>
public static int Current
{
get
{
return (int)( DateTime.UtcNow.Subtract( epoch ).TotalSeconds );
}
}
/// <summary>
/// Convert an epoch to a datetime
/// </summary>
public static DateTime ToDateTime( decimal unixTime )
{
return epoch.AddSeconds( (long)unixTime );
}
/// <summary>
/// Convert a DateTime to a unix time
/// </summary>
public static uint FromDateTime( DateTime dt )
{
return (uint)( dt.Subtract( epoch ).TotalSeconds );
}
}
internal static string FormatPrice(string currency, ulong price)
{
return FormatPrice(currency, price / 100.0);