mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 06:35:49 +03:00
Epoch
This commit is contained in:
parent
8e97489def
commit
603bd95c38
@ -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
|
||||
|
@ -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)
|
||||
|
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 @@
|
||||
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user