File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed
UnitsNet/CustomCode/Quantities Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,17 @@ public static void ToTimeSpanShouldNotThrowExceptionOnValuesSlightlySmallerThanT
63
63
AssertEx . EqualTolerance ( duration . Seconds , timeSpan . TotalSeconds , 1e-3 ) ;
64
64
}
65
65
66
+ [ Theory ]
67
+ [ InlineData ( 100 , Units . DurationUnit . Nanosecond ) ]
68
+ [ InlineData ( 1 , Units . DurationUnit . Microsecond ) ]
69
+ [ InlineData ( 1.234 , Units . DurationUnit . Millisecond ) ]
70
+ public static void ToTimeSpanShouldNotRoundToMillisecond ( double value , Units . DurationUnit unit )
71
+ {
72
+ Duration duration = Duration . From ( value , unit ) ;
73
+ TimeSpan timeSpan = duration . ToTimeSpan ( ) ;
74
+ AssertEx . EqualTolerance ( duration . Milliseconds , timeSpan . TotalMilliseconds , 1e-10 ) ;
75
+ }
76
+
66
77
[ Fact ]
67
78
public static void ExplicitCastToTimeSpanShouldReturnSameValue ( )
68
79
{
Original file line number Diff line number Diff line change 1
1
<Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
- <TargetFrameworks >net5.0</TargetFrameworks >
4
+ <TargetFrameworks >net5.0;net48 </TargetFrameworks >
5
5
<RootNamespace >UnitsNet.Tests</RootNamespace >
6
6
<LangVersion >latest</LangVersion >
7
7
<IsTestProject >true</IsTestProject >
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ public TimeSpan ToTimeSpan()
18
18
if ( Seconds > TimeSpan . MaxValue . TotalSeconds ||
19
19
Seconds < TimeSpan . MinValue . TotalSeconds )
20
20
throw new ArgumentOutOfRangeException ( nameof ( Duration ) , "The duration is too large or small to fit in a TimeSpan" ) ;
21
- return TimeSpan . FromSeconds ( Seconds ) ;
21
+ return TimeSpan . FromTicks ( ( long ) ( Seconds * TimeSpan . TicksPerSecond ) ) ;
22
22
}
23
23
24
24
/// <summary>Get <see cref="DateTime"/> from <see cref="DateTime"/> plus <see cref="Duration"/>.</summary>
You can’t perform that action at this time.
0 commit comments