1
0
mirror of https://github.com/mifi/lossless-cut.git synced 2024-11-22 10:22:31 +01:00

fix duration formatting

This commit is contained in:
Mikael Finstad 2023-07-26 09:56:46 +02:00
parent c5fb004626
commit 351b8673ee
No known key found for this signature in database
GPG Key ID: 25AB36E3E81CBC26
2 changed files with 13 additions and 3 deletions

View File

@ -12,8 +12,8 @@ export function formatDuration({ seconds: totalSecondsIn, fileNameFriendly, show
const seconds = Math.floor(totalUnits / unitsPerSec);
const secondsPadded = padStart(seconds % 60, 2, '0');
const minutes = Math.floor((totalUnits / 1000 / 60)) % 60;
const hours = Math.floor(totalUnits / 1000 / 60 / 60);
const minutes = Math.floor(totalUnits / unitsPerSec / 60) % 60;
const hours = Math.floor(totalUnits / unitsPerSec / 60 / 60);
const minutesPadded = shorten && hours === 0 ? `${minutes}` : padStart(minutes, 2, '0');

View File

@ -42,12 +42,22 @@ it('should format and parse duration with correct rounding', () => {
expect(formatDuration({ seconds: parseDuration('01:00:00.000') })).toBe('01:00:00.000');
});
it('should handle issue 1603', () => {
// https://github.com/mifi/lossless-cut/issues/1603
it('should round up properly', () => {
const fps = 30;
const halfFrame = (1 / fps) / 2;
expect(formatDuration({ seconds: 1 })).toBe('00:00:01.000');
expect(formatDuration({ seconds: 1, fps })).toBe('00:00:01.00');
expect(formatDuration({ seconds: 0.999999 })).toBe('00:00:01.000');
expect(formatDuration({ seconds: 1 - halfFrame + 0.001, fps })).toBe('00:00:01.00');
expect(formatDuration({ seconds: 0.999 })).toBe('00:00:00.999');
expect(formatDuration({ seconds: 1 - halfFrame - 0.001, fps })).toBe('00:00:00.29');
expect(formatDuration({ seconds: 59.999 })).toBe('00:00:59.999');
expect(formatDuration({ seconds: 60 - halfFrame - 0.001, fps })).toBe('00:00:59.29');
expect(formatDuration({ seconds: 59.9999 })).toBe('00:01:00.000');
expect(formatDuration({ seconds: (60 - halfFrame) + 0.001, fps })).toBe('00:01:00.00');
expect(formatDuration({ seconds: 3599.999 })).toBe('00:59:59.999');
expect(formatDuration({ seconds: (3600 - halfFrame) - 0.001, fps })).toBe('00:59:59.29');
expect(formatDuration({ seconds: 3599.9999 })).toBe('01:00:00.000');
expect(formatDuration({ seconds: (3600 - halfFrame) + 0.001, fps })).toBe('01:00:00.00');
});