mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Fix secondsToTime rounding
This commit is contained in:
@@ -104,6 +104,8 @@ export function secondsToTime (options: {
|
||||
|
||||
if (seconds === 0 && format !== 'full') return '0s'
|
||||
|
||||
seconds = Math.round(seconds)
|
||||
|
||||
const formatNumber = (value: number) => {
|
||||
if (format === 'locale-string') return value.toLocaleString()
|
||||
|
||||
@@ -125,7 +127,7 @@ export function secondsToTime (options: {
|
||||
else if (minutes >= 1) time += formatNumber(minutes) + minuteSymbol
|
||||
else if (format === 'full') time += '00' + minuteSymbol
|
||||
|
||||
seconds = Math.round(seconds) % 60
|
||||
seconds %= 60
|
||||
if (seconds >= 1 && seconds < 10 && format === 'full') time += '0' + seconds + secondsSymbol
|
||||
else if (seconds >= 1) time += formatNumber(seconds) + secondsSymbol
|
||||
else if (format === 'full') time += '00'
|
||||
|
||||
@@ -121,6 +121,11 @@ describe('Seconds to time', function () {
|
||||
expect(secondsToTime(61.6)).to.equals('1m2s')
|
||||
expect(secondsToTime(61.51)).to.equals('1m2s')
|
||||
})
|
||||
|
||||
it('Carries the rounding into minutes/hours when crossing a boundary', function () {
|
||||
expect(secondsToTime(59.6)).to.equals('1m')
|
||||
expect(secondsToTime(3599.6)).to.equals('1h')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Milliseconds to time', function () {
|
||||
|
||||
Reference in New Issue
Block a user