mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
Add FromUnixTime(Milli)Seconds for unsigned types
This commit is contained in:
parent
cacdf148d5
commit
155a604812
@ -7,6 +7,18 @@ namespace X10D.Tests.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public class UInt16Tests
|
public class UInt16Tests
|
||||||
{
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeMilliseconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), ((ushort)0).FromUnixTimeMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeSeconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), ((ushort)0).FromUnixTimeSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,18 @@ namespace X10D.Tests.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public class UInt32Tests
|
public class UInt32Tests
|
||||||
{
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeMilliseconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), 0U.FromUnixTimeMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeSeconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), 0U.FromUnixTimeSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
||||||
{
|
{
|
||||||
|
@ -7,6 +7,18 @@ namespace X10D.Tests.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public class UInt64Tests
|
public class UInt64Tests
|
||||||
{
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeMilliseconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), 0UL.FromUnixTimeMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void FromUnixTimeSeconds_ShouldBeEpoch_GivenZero()
|
||||||
|
{
|
||||||
|
Assert.AreEqual(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc), 0UL.FromUnixTimeSeconds());
|
||||||
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
public void IsLeapYear_ShouldBeFalse_GivenMultipleOf100()
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,48 @@ namespace X10D.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public static class UInt16Extensions
|
public static class UInt16Extensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z (January 1,
|
||||||
|
/// 1970, at 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800,000.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeMilliseconds(this ushort value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeMilliseconds(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at
|
||||||
|
/// 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeSeconds(this ushort value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeSeconds(value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -9,6 +9,48 @@ namespace X10D.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public static class UInt32Extensions
|
public static class UInt32Extensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z (January 1,
|
||||||
|
/// 1970, at 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800,000.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeMilliseconds(this uint value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeMilliseconds(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at
|
||||||
|
/// 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeSeconds(this uint value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeSeconds(value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -9,6 +9,48 @@ namespace X10D.Time;
|
|||||||
[CLSCompliant(false)]
|
[CLSCompliant(false)]
|
||||||
public static class UInt64Extensions
|
public static class UInt64Extensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z (January 1,
|
||||||
|
/// 1970, at 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800,000.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799,999.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeMilliseconds(this ulong value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeMilliseconds((long)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a
|
||||||
|
/// <see cref="DateTimeOffset" /> value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">
|
||||||
|
/// A Unix time, expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at
|
||||||
|
/// 12:00 AM UTC). For Unix times before this date, its value is negative.
|
||||||
|
/// </param>
|
||||||
|
/// <returns>A date and time value that represents the same moment in time as the Unix time.</returns>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException">
|
||||||
|
/// <para><paramref name="value" /> is less than -62,135,596,800.</para>
|
||||||
|
/// -or-
|
||||||
|
/// <para><paramref name="value" /> is greater than 253,402,300,799.</para>
|
||||||
|
/// </exception>
|
||||||
|
[Pure]
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static DateTimeOffset FromUnixTimeSeconds(this ulong value)
|
||||||
|
{
|
||||||
|
return DateTimeOffset.FromUnixTimeSeconds((long)value);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
/// Returns a value indicating whether the current integer, representing a year, is a leap year.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user