Skip to content

Commit

Permalink
Merge pull request #1317 from ilyfairy/master
Browse files Browse the repository at this point in the history
update Utils.cs
  • Loading branch information
yaakov-h authored Dec 28, 2023
2 parents 1bb0583 + d72679d commit cb146fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
13 changes: 0 additions & 13 deletions SteamKit2/SteamKit2/Util/KeyValuePairExtensions.cs

This file was deleted.

18 changes: 4 additions & 14 deletions SteamKit2/SteamKit2/Util/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ static class Utils
{
public static string EncodeHexString(byte[] input)
{
return input.Aggregate(new StringBuilder(),
(sb, v) => sb.Append(v.ToString("x2"))
).ToString();
return Convert.ToHexString(input).ToLower();
}

[return: NotNullIfNotNull( nameof( hex ) )]
Expand All @@ -32,13 +30,7 @@ public static string EncodeHexString(byte[] input)
if (hex == null)
return null;

int chars = hex.Length;
byte[] bytes = new byte[chars / 2];

for (int i = 0; i < chars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);

return bytes;
return Convert.FromHexString( hex );
}

public static EOSType GetOSType()
Expand Down Expand Up @@ -165,8 +157,7 @@ public static class DateUtils
/// <returns>DateTime representation</returns>
public static DateTime DateTimeFromUnixTime(ulong unixTime)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return origin.AddSeconds(unixTime);
return DateTimeOffset.FromUnixTimeSeconds( (long)unixTime ).DateTime;
}
/// <summary>
/// Converts a given DateTime into a unix timestamp representing seconds since the unix epoch.
Expand All @@ -175,8 +166,7 @@ public static DateTime DateTimeFromUnixTime(ulong unixTime)
/// <returns>64-bit wide representation</returns>
public static ulong DateTimeToUnixTime(DateTime time)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
return (ulong)(time - origin).TotalSeconds;
return (ulong)new DateTimeOffset( time ).ToUnixTimeSeconds();
}
}

Expand Down

0 comments on commit cb146fc

Please sign in to comment.