Skip to content

Fix DisplayDuration display#647

Merged
KirillOsenkov merged 1 commit intoKirillOsenkov:mainfrom
martin-strecker-sonarsource:FixDurationDisplay
Jan 5, 2023
Merged

Fix DisplayDuration display#647
KirillOsenkov merged 1 commit intoKirillOsenkov:mainfrom
martin-strecker-sonarsource:FixDurationDisplay

Conversation

@martin-strecker-sonarsource
Copy link
Copy Markdown
Contributor

Fixes #646

TextUtilities.DisplayDuration produces invalid output for several different input values. The new tests executed against the old code produce the following test failures:

[xUnit.net 00:00:00.19]   Starting:    StructuredLogger.Tests
[xUnit.net 00:00:01.43]     StructuredLogger.Tests.TextUtilitiesTests.TestDisplayDuration(duration: 60000, expected: "1:00.000") [FAIL]
[xUnit.net 00:00:01.43]       Assert.Equal() Failure
[xUnit.net 00:00:01.43]                 ↓ (pos 0)
[xUnit.net 00:00:01.43]       Expected: 1:00.000
[xUnit.net 00:00:01.43]       Actual:   0.000 s
[xUnit.net 00:00:01.43]                 ↑ (pos 0)
[xUnit.net 00:00:01.45]     StructuredLogger.Tests.TextUtilitiesTests.TestDisplayDuration(duration: 172800040, expected: "2.00:00:00.0400000") [FAIL]
[xUnit.net 00:00:01.45]       Assert.Equal() Failure
[xUnit.net 00:00:01.45]                 ↓ (pos 0)
[xUnit.net 00:00:01.45]       Expected: 2.00:00:00.0400000
[xUnit.net 00:00:01.45]       Actual:   0:00:00
[xUnit.net 00:00:01.46]                 ↑ (pos 0)
[xUnit.net 00:00:01.46]     StructuredLogger.Tests.TextUtilitiesTests.TestDisplayDuration(duration: 3600000, expected: "01:00:00") [FAIL]
[xUnit.net 00:00:01.46]       Assert.Equal() Failure
[xUnit.net 00:00:01.46]                  ↓ (pos 1)
[xUnit.net 00:00:01.46]       Expected: 01:00:00
[xUnit.net 00:00:01.46]       Actual:   0:00.000
[xUnit.net 00:00:01.46]                  ↑ (pos 1)
[xUnit.net 00:00:01.46]     StructuredLogger.Tests.TextUtilitiesTests.TestDisplayDuration(duration: 1000, expected: "1.000 s") [FAIL]
[xUnit.net 00:00:01.46]       Assert.Equal() Failure
[xUnit.net 00:00:01.46]                 ↓ (pos 0)
[xUnit.net 00:00:01.46]       Expected: 1.000 s
[xUnit.net 00:00:01.46]       Actual:   0 ms
[xUnit.net 00:00:01.46]                 ↑ (pos 0)
[xUnit.net 00:00:01.46]     StructuredLogger.Tests.TextUtilitiesTests.TestDisplayDuration(duration: 172800000, expected: "2.00:00:00") [FAIL]
[xUnit.net 00:00:01.46]       Assert.Equal() Failure
[xUnit.net 00:00:01.46]                 ↓ (pos 0)
[xUnit.net 00:00:01.46]       Expected: 2.00:00:00
[xUnit.net 00:00:01.46]       Actual:   0:00:00
[xUnit.net 00:00:01.46]                 ↑ (pos 0)
[xUnit.net 00:00:01.46]   Finished:    StructuredLogger.Tests
========== Test run finished: 9 Tests (4 Passed, 5 Failed, 0 Skipped) run in 1,5 sec ==========

if (span.TotalHours >= 1)
{
return span.ToString(@"h\:mm\:ss");
return span.ToString();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be stable? If so it might be better to specify the InvariantCulture.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine either way, it's for the user display only

Copy link
Copy Markdown
Owner

@KirillOsenkov KirillOsenkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow thank you so much!

👍

@KirillOsenkov KirillOsenkov merged commit cdccaca into KirillOsenkov:main Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: DurationDisplay formats several durations wrong

2 participants