docs(392): extract shared ComputePadBoundary helper in plan (DRY)
This commit is contained in:
@@ -522,9 +522,58 @@ Verify the exact accessor names against `PlayoutReferenceData.cs` and `ProgramSc
|
||||
exposes `ProgramSchedule`). If an accessor differs, adjust — the intent is "every scheduled item points at its
|
||||
own parent schedule."
|
||||
|
||||
**(b) `PlayoutModeSchedulerBase.cs` — change `AddFiller` return type + add the synthetic-pad branch.**
|
||||
**(b) `PlayoutModeSchedulerBase.cs` — extract the pad boundary-math helper, change `AddFiller` return type, add the synthetic-pad branch.**
|
||||
|
||||
Change the signature (line 282) return type to a named tuple:
|
||||
First, extract the boundary-math (currently inlined at lines 604-626) into one private static helper that BOTH
|
||||
the existing item-pad path and the new synthetic branch call (DRY; the existing `Classic_clock_padded` golden
|
||||
proves this extraction is behavior-preserving). Add this method to the class:
|
||||
```csharp
|
||||
// #392: shared clock-boundary ceiling used by both the item-level Pad filler and the schedule-level pad.
|
||||
// Returns the next `padToNearestMinute` boundary at or after (blockStart + totalDuration); when the block
|
||||
// already ends exactly on a boundary it advances one full interval (matches the pre-#392 Pad behavior).
|
||||
private static DateTimeOffset ComputePadBoundary(
|
||||
DateTimeOffset blockStart,
|
||||
TimeSpan totalDuration,
|
||||
int padToNearestMinute)
|
||||
{
|
||||
int currentMinute = (blockStart + totalDuration).Minute;
|
||||
int targetMinute = (currentMinute + padToNearestMinute - 1) / padToNearestMinute * padToNearestMinute;
|
||||
|
||||
DateTimeOffset almostTargetTime = blockStart + totalDuration -
|
||||
TimeSpan.FromMinutes(currentMinute) +
|
||||
TimeSpan.FromMinutes(targetMinute);
|
||||
|
||||
var targetTime = new DateTimeOffset(
|
||||
almostTargetTime.Year,
|
||||
almostTargetTime.Month,
|
||||
almostTargetTime.Day,
|
||||
almostTargetTime.Hour,
|
||||
almostTargetTime.Minute,
|
||||
0,
|
||||
almostTargetTime.Offset);
|
||||
|
||||
// ensure filler works for content less than one interval (and for content already on a boundary)
|
||||
if (targetTime <= blockStart + totalDuration)
|
||||
{
|
||||
targetTime = targetTime.AddMinutes(padToNearestMinute);
|
||||
}
|
||||
|
||||
return targetTime;
|
||||
}
|
||||
```
|
||||
Then, in the EXISTING item-pad block, replace the inlined ceiling math (lines 604-626 — the `int currentMinute
|
||||
= ...` through the `if (targetTime <= ...) { targetTime = targetTime.AddMinutes(...); }`) with a single call,
|
||||
leaving the `remainingToFill` line (628) intact:
|
||||
```csharp
|
||||
DateTimeOffset targetTime = ComputePadBoundary(
|
||||
playoutItem.StartOffset, totalDuration, padFiller.PadToNearestMinute.Value);
|
||||
|
||||
TimeSpan remainingToFill = targetTime - totalDuration - playoutItem.StartOffset;
|
||||
```
|
||||
(This is a pure extraction: the helper body is byte-identical logic to the removed lines. The
|
||||
`Classic_clock_padded` golden in Step 7 must stay green, proving no behavior change.)
|
||||
|
||||
Change the `AddFiller` signature (line 282) return type to a named tuple:
|
||||
```csharp
|
||||
internal (List<PlayoutItem> Items, DateTimeOffset? OfflinePadTarget) AddFiller(
|
||||
PlayoutBuilderState playoutBuilderState,
|
||||
@@ -559,26 +608,8 @@ schedule has a positive divisor — mutually exclusive with the existing block:
|
||||
TimeSpan.Zero,
|
||||
(acc, i) => acc + (i.FinishOffset - i.StartOffset));
|
||||
|
||||
int currentMinute = (playoutItem.StartOffset + totalDuration).Minute;
|
||||
int targetMinute = (currentMinute + schedulePadMinutes - 1) / schedulePadMinutes * schedulePadMinutes;
|
||||
|
||||
DateTimeOffset almostTargetTime = playoutItem.StartOffset + totalDuration -
|
||||
TimeSpan.FromMinutes(currentMinute) +
|
||||
TimeSpan.FromMinutes(targetMinute);
|
||||
|
||||
var targetTime = new DateTimeOffset(
|
||||
almostTargetTime.Year,
|
||||
almostTargetTime.Month,
|
||||
almostTargetTime.Day,
|
||||
almostTargetTime.Hour,
|
||||
almostTargetTime.Minute,
|
||||
0,
|
||||
almostTargetTime.Offset);
|
||||
|
||||
if (targetTime <= playoutItem.StartOffset + totalDuration)
|
||||
{
|
||||
targetTime = targetTime.AddMinutes(schedulePadMinutes);
|
||||
}
|
||||
DateTimeOffset targetTime = ComputePadBoundary(
|
||||
playoutItem.StartOffset, totalDuration, schedulePadMinutes);
|
||||
|
||||
TimeSpan remainingToFill = targetTime - totalDuration - playoutItem.StartOffset;
|
||||
if (remainingToFill > TimeSpan.Zero)
|
||||
|
||||
Reference in New Issue
Block a user