Fix desktop notification duration formatting #4358
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a simple fix for a bug with the duration formatting in desktop notifications.
As an example, a time of 2 hours 45 minutes and 12 seconds was being formatted as
3:165:9912
rather than2:45:12
, which I believe was the original intention.This happens because
Hours()
,Minutes()
andSeconds()
give the total duration in that unit, rather than that specific "part" of the duration. The%02.f
format string specifier adds rounding as well, which makes even the hours unit incorrect half of the time.I've just fixed this by using
time.Duration
'sString()
function, with some conditional rounding to prevent displaying tons of decimal places. This does change the output format, i.e. it's now2h45m12s
rather than2:45:12
, but I think the new format is clearer anyway, especially with times shorter than 1 second (it now shows425ms
), and it means we don't have to manually do any math ourselves.