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>
|
||||
/// Returns the current Unix Epoch
|
||||
/// </summary>
|
||||
public static int Current
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)(DateTime.UtcNow.Subtract( epoch ).TotalSeconds);
|
||||
}
|
||||
}
|
||||
public static int Current => (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 );
|
||||
}
|
||||
public static DateTime ToDateTime( decimal unixTime ) => 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);
|
||||
}
|
||||
public static uint FromDateTime( DateTime dt ) => (uint)(dt.Subtract( epoch ).TotalSeconds);
|
||||
}
|
||||
}
|
||||
|
@ -83,44 +83,5 @@ public static string FormatPrice(string currency, double price)
|
||||
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