Refactor TimeCode frame-based formatting into ITimeFormatter strategy#11539
Open
ivandrofly wants to merge 3 commits into
Open
Refactor TimeCode frame-based formatting into ITimeFormatter strategy#11539ivandrofly wants to merge 3 commits into
ivandrofly wants to merge 3 commits into
Conversation
Replace ToHHMMSSFF, ToShortStringHHMMSSFF, ToHHMMSS, ToHHMMSSFFDropFrame, ToSSFF and ToHHMMSSPeriodFF with formatter classes implementing ITimeFormatter, passed to TimeCode.ToString(ITimeFormatter). Shared frame-rounding/second-carry logic lives in FrameBasedTimeFormatter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…n-based - ITimeFormatter.Format now takes a TimeSpan instead of a TimeCode; TimeCode.ToString(ITimeFormatter) delegates via its TimeSpan property - Add TimeSpanExtensions in libse with ToString(ITimeFormatter), ToString(localize), ToShortString and ToShortDisplayString; TimeCode now delegates its string formatting to these extensions - Paragraph.Duration is now a TimeSpan; remove DurationTotalMilliseconds and DurationTotalSeconds, all callers go through Duration - Add TimeSpan overloads to subtitle format helpers (Edius, FilmEditXml, FinalCutProXml15, TimedText10, UnknownSubtitle76/90) so durations are formatted without creating TimeCode instances Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
TimeCodeformat methods (ToHHMMSSFF,ToShortStringHHMMSSFF,ToHHMMSS,ToHHMMSSFFDropFrame,ToSSFF,ToHHMMSSPeriodFF) into formatter classes implementing a newITimeFormatterinterface, invoked viaTimeCode.ToString(ITimeFormatter)FrameBasedTimeFormatterbase class; previously it was duplicated across five methodsTimeFormatterstatic class exposes shared singleton instances (TimeFormatter.HhMmSsFf, etc.) so call sites allocate nothingToSSFFcarry-over quirk (59→60, no minute rollover) and the leading-00:-group trimming of the short formatMotivation
This is part 1 of a larger refactor aimed at reducing allocations caused by the
Durationproperty inParagraph, which allocates a newTimeCodeon every access. Centralizing formatting behindITimeFormatterdecouples string formatting from theTimeCodeinstance itself, so a follow-up PR can make formatting work without materializing intermediateTimeCode/TimeSpanobjects on hot paths (grid rendering, audio visualizer).Test plan
dotnet build SubtitleEdit.slnsucceeds with 0 warnings/errorsdotnet test tests/libse/LibSETests.csproj— 385 passeddotnet test tests/UI/UITests.csproj— 335 passed🤖 Generated with Claude Code