Skip to content

Refactor TimeCode frame-based formatting into ITimeFormatter strategy#11539

Open
ivandrofly wants to merge 3 commits into
SubtitleEdit:mainfrom
ivandrofly:refactor/timecode-time-formatters
Open

Refactor TimeCode frame-based formatting into ITimeFormatter strategy#11539
ivandrofly wants to merge 3 commits into
SubtitleEdit:mainfrom
ivandrofly:refactor/timecode-time-formatters

Conversation

@ivandrofly

@ivandrofly ivandrofly commented Jun 11, 2026

Copy link
Copy Markdown
Member

Summary

  • Extract the six frame-based TimeCode format methods (ToHHMMSSFF, ToShortStringHHMMSSFF, ToHHMMSS, ToHHMMSSFFDropFrame, ToSSFF, ToHHMMSSPeriodFF) into formatter classes implementing a new ITimeFormatter interface, invoked via TimeCode.ToString(ITimeFormatter)
  • Shared frame-rounding/second-carry logic now lives once in an abstract FrameBasedTimeFormatter base class; previously it was duplicated across five methods
  • TimeFormatter static class exposes shared singleton instances (TimeFormatter.HhMmSsFf, etc.) so call sites allocate nothing
  • All 71 call-site files updated mechanically; output is byte-for-byte identical, including the ToSSFF carry-over quirk (5960, no minute rollover) and the leading-00:-group trimming of the short format

Motivation

This is part 1 of a larger refactor aimed at reducing allocations caused by the Duration property in Paragraph, which allocates a new TimeCode on every access. Centralizing formatting behind ITimeFormatter decouples string formatting from the TimeCode instance itself, so a follow-up PR can make formatting work without materializing intermediate TimeCode/TimeSpan objects on hot paths (grid rendering, audio visualizer).

Test plan

  • dotnet build SubtitleEdit.sln succeeds with 0 warnings/errors
  • dotnet test tests/libse/LibSETests.csproj — 385 passed
  • dotnet test tests/UI/UITests.csproj — 335 passed
  • Save a subtitle in a frame-based format (e.g. Adobe Encore, Avid Caption) and confirm timecodes are unchanged
  • Toggle Options → time format HH:MM:SS:FF and confirm grid/display strings render as before

🤖 Generated with Claude Code

ivandrofly and others added 3 commits June 11, 2026 01:11
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant