Skip to content

Keep a tenth of a second in an SRT timestamp - #549

Open
SashaMIT wants to merge 1 commit into
collabora:mainfrom
SashaMIT:codered-srt-ms
Open

SashaMIT wants to merge 1 commit into
collabora:mainfrom
SashaMIT:codered-srt-ms

Conversation

@SashaMIT

Copy link
Copy Markdown

format_time(1.2) came back as 00:00:01,199. format_time(2.3) came back as 00:00:02,299. The fractional seconds sit just under the millisecond, and int() drops it. format_time(1.5) is still 00:00:01,500. format_time(0.9999) is still 00:00:00,999.

Red: format_time(1.2) was 00:00:01,199. Green: tests.test_utils.TestFormatTime, including test_tenth_of_a_second.

1.2 seconds was formatted as 1.199 because the millisecond product sits just under the integer.

@boxerab boxerab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, the bug is real. the epsilon plus the nested carry is more than this needs though. converting to whole milliseconds once handles the carry by itself:

total_milliseconds = round(s * 1000)
hours, remainder = divmod(total_milliseconds, 3_600_000)
minutes, remainder = divmod(remainder, 60_000)
seconds, milliseconds = divmod(remainder, 1000)

this rounds to the nearest millisecond instead of truncating, so test_rounding_edge should expect 00:00:01,000 for 0.9999, and test_large_value can assert 23:59:59,999 exactly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants