mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-31 11:59:10 +00:00
2.9 KiB
2.9 KiB
runtimeState time-core migration
Status: In progress
Goal
Make temporal meaning explicit across runtimeState and timer calculations. Prevent mixing:
Instant: epoch timestamp;TimeOfDay: local milliseconds since midnight, range[0, dayInMs);Duration: elapsed or remaining milliseconds;Day: calendar-day offset.
Use apps/server/src/lib/time-core/timeCore.ts for conversions and temporal arithmetic. Branded types remain numbers at serialization boundaries.
Current state
Completed foundation:
- temporal brands in
ontime-types; timeCorehelpers for now, conversion, duration arithmetic, midnight crossing, calendar-day distance;- partial
runtimeStateadoption ofInstant,TimeOfDay,Day, andtimeCore.
Remaining ambiguity:
TimerState,RundownState, andOffsetexpose temporal fields asnumber/MaybeNumber;timerUtilsaccepts/returns raw numbers with different meanings;runtimeStateretains raw duration fields, manual arithmetic, andas TimeOfDay/as Durationcasts.
Migration rules
- Classify each temporal field before changing it. No generic
Timetype. - Convert only through
timeCoreor an explicit transport adapter. - Keep public/websocket JSON numeric where required; brand at the boundary.
- Keep type migration separate from behaviour changes.
- Preserve current midnight, rollover, pause, add-time, roll, and offset behaviour per slice.
- Add helpers only when they encode a named temporal rule and remove caller casts/arithmetic.
Slices
- Add temporal brands and initial
timeCorehelpers/tests. - Inventory temporal fields in
TimerState,RundownState,Offset, and private runtime state; assign intended types. - Migrate pure
timerUtilsfunctions by temporal concept; add focused midnight/rollover tests. - Migrate private
RuntimeStatefields and calculations; remove local casts/manual conversions. - Migrate shared runtime contracts and add numeric transport adapters where compatibility requires them.
- Update remaining callers, fixtures, and mocks.
- Remove superseded helpers, casts, and ambiguous temporal numbers.
Each slice must leave old/new boundaries explicit, compile cleanly, and preserve behaviour.
Required coverage
- before, at, and after midnight;
- overnight and multi-day rundowns;
- local-day calculation across timezone/DST offset changes;
- pause/resume, added time, elapsed/remaining duration;
- roll secondary targets and expected finish;
- absolute/relative offsets and day offsets.
Complete when
- Runtime/timer boundaries use semantic temporal types or documented numeric transport fields.
- Temporal conversions/arithmetic use
timeCoreor named pure helpers. - No unexplained temporal casts or ambiguous numeric fields remain in migrated scope.
- Focused tests cover the required boundaries.
After completion, remove this migration tracker. Keep durable rules in docs/agent-guides/domain-invariants.md.