diff --git a/X10D/DateTimeExtensions.cs b/X10D/DateTimeExtensions.cs index 0c3130f..bc8c2c2 100644 --- a/X10D/DateTimeExtensions.cs +++ b/X10D/DateTimeExtensions.cs @@ -11,11 +11,6 @@ /// public static class DateTimeExtensions { - /// - /// Represents the Unix epoch - midnight on January 1, 1970. - /// - public static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0); - /// /// Calculates someone's age based on a date of birth. /// @@ -146,8 +141,8 @@ /// Returns a Unix timestamp representing the provided . public static long ToUnixTimeStamp(this DateTime time, bool useMillis = false) { - TimeSpan difference = time - UnixEpoch; - return (long)(useMillis ? difference.TotalMilliseconds : difference.TotalSeconds); + DateTimeOffset offset = time; + return useMillis ? offset.ToUnixTimeSeconds() : offset.ToUnixTimeMilliseconds(); } /// diff --git a/X10D/DoubleExtensions.cs b/X10D/DoubleExtensions.cs index 1dd50e7..9974f41 100644 --- a/X10D/DoubleExtensions.cs +++ b/X10D/DoubleExtensions.cs @@ -31,19 +31,6 @@ public static double DegreesToRadians(this double angle) => Math.PI * angle / 180.0; - /// - /// Converts the to a treating it as a Unix timestamp. - /// - /// The timestamp. - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to . - /// Returns a representing seconds since the Unix - /// epoch. - public static DateTime FromUnixTimestamp(this double timestamp, bool isMillis = false) => - isMillis - ? DateTimeExtensions.UnixEpoch.AddMilliseconds(timestamp) - : DateTimeExtensions.UnixEpoch.AddSeconds(timestamp); - /// /// Converts the to a []. /// diff --git a/X10D/Int64Extensions.cs b/X10D/Int64Extensions.cs index 889eb72..d8c6cb7 100644 --- a/X10D/Int64Extensions.cs +++ b/X10D/Int64Extensions.cs @@ -82,8 +82,14 @@ /// to . /// Returns a representing seconds since the Unix /// epoch. - public static DateTime FromUnixTimestamp(this long timestamp, bool isMillis = false) => - ((double)timestamp).FromUnixTimestamp(isMillis); + public static DateTime FromUnixTimestamp(this long timestamp, bool isMillis = false) + { + DateTimeOffset offset = isMillis + ? DateTimeOffset.FromUnixTimeMilliseconds(timestamp) + : DateTimeOffset.FromUnixTimeSeconds(timestamp); + + return offset.DateTime; + } /// /// Converts the to a []. diff --git a/X10D/SingleExtensions.cs b/X10D/SingleExtensions.cs index ec37e84..ef4357c 100644 --- a/X10D/SingleExtensions.cs +++ b/X10D/SingleExtensions.cs @@ -31,17 +31,6 @@ public static float DegreesToRadians(this float angle) => (float)((double)angle).DegreesToRadians(); - /// - /// Converts the to a treating it as a Unix timestamp. - /// - /// The timestamp. - /// Optional. Whether or not the input value should be treated as milliseconds. Defaults - /// to . - /// Returns a representing seconds since the Unix - /// epoch. - public static DateTime FromUnixTimestamp(this float timestamp, bool isMillis = false) => - ((double)timestamp).FromUnixTimestamp(isMillis); - /// /// Converts the to a []. ///