Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions PolyShim.Tests/Net100/TimeSpanTests.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
17 changes: 17 additions & 0 deletions PolyShim.Tests/Net90/TimeSpanTests.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
19 changes: 19 additions & 0 deletions PolyShim/Net100/TimeSpan.cs
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions PolyShim/Net90/TimeSpan.cs
Original file line number Diff line number Diff line change
@@ -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
Loading