diff --git a/PolyShim.Tests/Net100/TimeSpanTests.cs b/PolyShim.Tests/Net100/TimeSpanTests.cs new file mode 100644 index 0000000..55b1e02 --- /dev/null +++ b/PolyShim.Tests/Net100/TimeSpanTests.cs @@ -0,0 +1,17 @@ +using System; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net100; + +public class TimeSpanTests +{ + [Fact] + public void FromMilliseconds_Test() + { + // Act & assert + TimeSpan.FromMilliseconds(1234).Should().Be(TimeSpan.FromSeconds(1.234)); + TimeSpan.FromMilliseconds(0).Should().Be(TimeSpan.Zero); + TimeSpan.FromMilliseconds(-1000).Should().Be(TimeSpan.FromSeconds(-1)); + } +} diff --git a/PolyShim.Tests/Net90/TimeSpanTests.cs b/PolyShim.Tests/Net90/TimeSpanTests.cs new file mode 100644 index 0000000..3fe8413 --- /dev/null +++ b/PolyShim.Tests/Net90/TimeSpanTests.cs @@ -0,0 +1,17 @@ +using System; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net90; + +public class TimeSpanTests +{ + [Fact] + public void FromMilliseconds_Test() + { + // Act & assert + TimeSpan.FromMilliseconds(1234, 567).Should().Be(TimeSpan.FromSeconds(1.234567)); + TimeSpan.FromMilliseconds(0, 0).Should().Be(TimeSpan.Zero); + TimeSpan.FromMilliseconds(-1000, -500).Should().Be(TimeSpan.FromSeconds(-1.0005)); + } +} diff --git a/PolyShim/Net100/TimeSpan.cs b/PolyShim/Net100/TimeSpan.cs new file mode 100644 index 0000000..47d755f --- /dev/null +++ b/PolyShim/Net100/TimeSpan.cs @@ -0,0 +1,19 @@ +#if (NETCOREAPP && !NET10_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; + +internal static partial class PolyfillExtensions +{ + extension(TimeSpan) + { + // https://learn.microsoft.com/dotnet/api/system.timespan.frommilliseconds#system-timespan-frommilliseconds(system-int64) + public static TimeSpan FromMilliseconds(long milliseconds) => + TimeSpan.FromMilliseconds(milliseconds, 0); + } +} +#endif diff --git a/PolyShim/Net90/TimeSpan.cs b/PolyShim/Net90/TimeSpan.cs new file mode 100644 index 0000000..3f77cf1 --- /dev/null +++ b/PolyShim/Net90/TimeSpan.cs @@ -0,0 +1,19 @@ +#if (NETCOREAPP && !NET9_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; + +internal static partial class PolyfillExtensions +{ + extension(TimeSpan) + { + // https://learn.microsoft.com/dotnet/api/system.timespan.frommilliseconds#system-timespan-frommilliseconds(system-int64-system-int64) + public static TimeSpan FromMilliseconds(long milliseconds, long microseconds) => + TimeSpan.FromMilliseconds(milliseconds + microseconds / 1_000.0); + } +} +#endif