mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-26 06:35:49 +03:00
Utility cleanup
This commit is contained in:
parent
28e8f261e2
commit
6e350f4d08
@ -9,28 +9,16 @@ static internal class Epoch
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the current Unix Epoch
|
/// Returns the current Unix Epoch
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static int Current
|
public static int Current => (int)(DateTime.UtcNow.Subtract( epoch ).TotalSeconds);
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return (int)(DateTime.UtcNow.Subtract( epoch ).TotalSeconds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert an epoch to a datetime
|
/// Convert an epoch to a datetime
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DateTime ToDateTime( decimal unixTime )
|
public static DateTime ToDateTime( decimal unixTime ) => epoch.AddSeconds( (long)unixTime );
|
||||||
{
|
|
||||||
return epoch.AddSeconds( (long)unixTime );
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Convert a DateTime to a unix time
|
/// Convert a DateTime to a unix time
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static uint FromDateTime( DateTime dt )
|
public static uint FromDateTime( DateTime dt ) => (uint)(dt.Subtract( epoch ).TotalSeconds);
|
||||||
{
|
|
||||||
return (uint)(dt.Subtract( epoch ).TotalSeconds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,44 +83,5 @@ public static string FormatPrice(string currency, double price)
|
|||||||
default: return $"{decimaled} {currency}";
|
default: return $"{decimaled} {currency}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string ReadNullTerminatedUTF8String( this BinaryReader br, byte[] buffer = null )
|
|
||||||
{
|
|
||||||
if ( buffer == null )
|
|
||||||
buffer = new byte[1024];
|
|
||||||
|
|
||||||
byte chr;
|
|
||||||
int i = 0;
|
|
||||||
while ( (chr = br.ReadByte()) != 0 && i < buffer.Length )
|
|
||||||
{
|
|
||||||
buffer[i] = chr;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Encoding.UTF8.GetString( buffer, 0, i );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<T> UnionSelect<T>(
|
|
||||||
this IEnumerable<T> first,
|
|
||||||
IEnumerable<T> second,
|
|
||||||
Func<T, T, T> selector) where T : IEquatable<T>
|
|
||||||
{
|
|
||||||
var items = new Dictionary<T, T>();
|
|
||||||
|
|
||||||
foreach (var i in first)
|
|
||||||
{
|
|
||||||
items[i] = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var i in second)
|
|
||||||
{
|
|
||||||
T firstValue;
|
|
||||||
if (items.TryGetValue(i, out firstValue))
|
|
||||||
{
|
|
||||||
items.Remove(i);
|
|
||||||
yield return selector(firstValue, i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user