Skip to content

Commit 424223a

Browse files
committed
2 parents 73eff75 + e1dd609 commit 424223a

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

.vscode/tasks.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"args": [
1313
"build",
1414
"${workspaceFolder}",
15-
"/p:GenerateFullPaths=true"
15+
"/p:GenerateFullPaths=true",
16+
"/consoleloggerparameters:NoSummary"
1617
],
1718
"problemMatcher": "$msCompile"
1819
},
@@ -27,7 +28,8 @@
2728
"args": [
2829
"test",
2930
"${workspaceFolder}",
30-
"/p:GenerateFullPaths=true"
31+
"/p:GenerateFullPaths=true",
32+
"/consoleloggerparameters:NoSummary"
3133
],
3234
"problemMatcher": "$msCompile"
3335
},

src/Exceptionless.DateTimeExtensions/TimeSpanExtensions.cs

+14-8
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,20 @@ public string ToString(int maxParts, bool shortForm = false, bool includeMillise
148148
if (seconds > 10)
149149
seconds = Math.Round(seconds);
150150

151-
if (AppendPart(sb, "second", seconds, shortForm, ref partCount))
152-
if (maxParts > 0 && partCount >= maxParts)
153-
return sb.ToString();
154-
155-
if (includeMilliseconds && AppendPart(sb, "millisecond", Milliseconds, shortForm, ref partCount))
156-
if (maxParts > 0 && partCount >= maxParts)
157-
return sb.ToString();
158-
151+
if (Math.Abs(TotalSeconds) > 2) {
152+
if (AppendPart(sb, "second", seconds, shortForm, ref partCount))
153+
if (maxParts > 0 && partCount >= maxParts)
154+
return sb.ToString();
155+
156+
if (includeMilliseconds && AppendPart(sb, "millisecond", Milliseconds, shortForm, ref partCount))
157+
if (maxParts > 0 && partCount >= maxParts)
158+
return sb.ToString();
159+
} else {
160+
if (AppendPart(sb, "millisecond", TotalMilliseconds, shortForm, ref partCount))
161+
if (maxParts > 0 && partCount >= maxParts)
162+
return sb.ToString();
163+
}
164+
159165
return sb.ToString();
160166
}
161167

tests/Exceptionless.DateTimeExtensions.Tests/Exceptionless.DateTimeExtensions.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</ItemGroup>
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.0" />
1213
<PackageReference Include="xunit" Version="2.4.1" />
1314
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
1415
<PackageReference Include="Foundatio.Xunit" Version="10.0.0-beta8" />

tests/Exceptionless.DateTimeExtensions.Tests/TimeSpanExtensionTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ public class TimeSpanExtensionTests {
66
[Fact]
77
public void ToWords() {
88
TimeSpan value = TimeSpan.FromMilliseconds(100);
9-
Assert.Equal("0.1 second", value.ToWords());
9+
Assert.Equal("100 milliseconds", value.ToWords());
1010

1111
value = TimeSpan.FromMilliseconds(-100);
12-
Assert.Equal("-0.1 second", value.ToWords());
12+
Assert.Equal("-100 milliseconds", value.ToWords());
1313

1414
value = TimeSpan.FromMilliseconds(100);
15-
Assert.Equal("0.1s", value.ToWords(true));
15+
Assert.Equal("100ms", value.ToWords(true));
1616

1717
value = TimeSpan.FromMilliseconds(2500);
1818
Assert.Equal("2.5 seconds", value.ToWords());

0 commit comments

Comments
 (0)