mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-26 23:09:37 +03:00
Epoch
This commit is contained in:
parent
8e97489def
commit
603bd95c38
@ -95,7 +95,7 @@ namespace Steamworks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the time of the purchase of the app
|
/// Returns the time of the purchase of the app
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Checks if the user is subscribed to the current app through a free weekend
|
/// Checks if the user is subscribed to the current app through a free weekend
|
||||||
|
@ -68,7 +68,7 @@ namespace Steamworks
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Steam server time. Number of seconds since January 1, 1970, GMT (i.e unix time)
|
/// Steam server time. Number of seconds since January 1, 1970, GMT (i.e unix time)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DateTime SteamServerTime => Utility.Epoch.ToDateTime( Internal.GetServerRealTime() );
|
public static DateTime SteamServerTime => Epoch.ToDateTime( Internal.GetServerRealTime() );
|
||||||
|
|
||||||
/// <summary>
|
/// <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)
|
/// 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)
|
||||||
|
36
Facepunch.Steamworks/Utility/Epoch.cs
Normal file
36
Facepunch.Steamworks/Utility/Epoch.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,7 +7,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Steamworks
|
namespace Steamworks
|
||||||
{
|
{
|
||||||
public static partial class Utility
|
public static partial class Utility
|
||||||
{
|
{
|
||||||
static internal uint Swap( uint x )
|
static internal uint Swap( uint x )
|
||||||
{
|
{
|
||||||
@ -27,39 +27,6 @@ namespace Steamworks
|
|||||||
return new IPAddress( Swap( 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)
|
internal static string FormatPrice(string currency, ulong price)
|
||||||
{
|
{
|
||||||
return FormatPrice(currency, price / 100.0);
|
return FormatPrice(currency, price / 100.0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user