Skip to content

Commit af7d086

Browse files
committed
Change to show milliseconds when total time is less than 2 seconds
1 parent b7985b8 commit af7d086

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-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/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)