fix: correct moment.js duration formatting in format-time utilities #1261
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.
Fix incorrect moment.js usage in time formatting functions
Summary
This PR fixes a bug in the time formatting functions where
moment().millisecond()was incorrectly used instead ofmoment().add()to format durations. Themillisecond()method only sets the millisecond component (0-999), not total milliseconds, which could cause incorrect time formatting for durations over 1 second.Problem
Both
main/utils/format-time.tsandrenderer/utils/format-time.jsusemoment().startOf('day').millisecond(time * 1000)to format time durations. This is semantically incorrect because:millisecond()sets only the millisecond component (0-999), not total millisecondstime = 65seconds,time * 1000 = 65000millisecondsmillisecond(65000)would set milliseconds to65000 % 1000 = 0, losing the actual durationSolution
Replace
moment().startOf('day').millisecond(time * 1000)withmoment().startOf('day').add(time, 'seconds')in both files. This correctly adds the duration as seconds to a moment at the start of the day, which can then be formatted properly.Changes
main/utils/format-time.ts(line 19)renderer/utils/format-time.js(line 19)test/format-time.tsTesting
Added tests covering:
Why This Is Safe