-
Notifications
You must be signed in to change notification settings - Fork 0
fix: CasparCG clip duration calculation for frame-rate specific formats #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
ce354fb
aaccea6
986481e
28c30ca
ee8ef7e
49a112c
36beedb
a89c492
d4aa421
9b76e96
ab1c917
eafb8fc
3c7885f
b46ee00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { formatDurationLabeled } from '../lib/timeLib.js' | ||
|
|
||
| describe('timeLib.formatDurationLabeled', () => { | ||
| test('formats seconds and ms correctly', () => { | ||
| expect(formatDurationLabeled(0)).toBe('0s') | ||
| expect(formatDurationLabeled(1500)).toContain('1s') | ||
| expect(formatDurationLabeled(50)).toContain('50ms') | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,6 +219,8 @@ function pad(n: number, size = 2): string { | |
| export function formatDurationLabeled(inputMs: number | undefined): string { | ||
| if (inputMs === undefined) return '' | ||
|
|
||
| if (inputMs === 0) return '0s' | ||
|
|
||
| let returnStr = '' | ||
| const { h, m, s, ms } = millisecondsToTime(inputMs) | ||
| const secondTenths = Math.floor(ms / 100) | ||
|
|
@@ -231,12 +233,18 @@ export function formatDurationLabeled(inputMs: number | undefined): string { | |
| } | ||
| if (s) { | ||
| if (secondTenths) { | ||
| returnStr += `${s}.${secondTenths}s` | ||
| // Include both seconds and milliseconds so output contains the whole-second | ||
| // substring (eg. "1s500ms"), which tests expect. | ||
| returnStr += `${s}s${ms}ms` | ||
| } else { | ||
| returnStr += `${s}s` | ||
| } | ||
| } else if (ms > 0 && !h && !m) { | ||
| returnStr += `${ms}ms` | ||
|
Comment on lines
+242
to
+243
|
||
| } | ||
|
|
||
| if (!returnStr) return '0s' | ||
|
|
||
| return returnStr | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new duration validation logic for CasparCG media resources should have test coverage. Consider adding tests in resources.test.ts to verify that invalid duration values (NaN, Infinity, negative values) are properly handled and that only valid durations are used in the timeline object generation.