Add Stopwatch and Countdown facades over the elapsed anchor#7
Merged
Conversation
Thin presentation clocks built on the run-relative (elapsed) anchor. Both take the same distortions array a Clock does and start their run at construction. - Stopwatch counts up in warped time: elapsedInMillis (warped) and referenceElapsedInMillis (real), via relativeTimeInMillis - runStart. - Countdown counts down to a real-time target: remainingInMillis (clamped at zero), isComplete, elapsedInMillis, targetInMillis. Because the offset is cumulative (a dilation repaid by a later compression), it can crawl early and sprint late yet still reach zero on the real deadline. - Clock exposes runStartInMillis (the run anchor) so the facades measure warped time since start. - Extract the shared Duration interface and durationToMillis helper into src/duration.ts; RelativeTimeDistortion re-exports Duration for compat. - Export Stopwatch, Countdown, and the Duration type. Adds Stopwatch and Countdown tests (including the crawl-early/sprint-late countdown that lands on zero at the real deadline) and a README section. Full suite green (61 tests), tsc and eslint clean. No version bump. Refs #4 Co-Authored-By: Claude Opus 4.8 <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.
What & why
Adds the two presentation clocks from issue #4 (step 3), built on the run-relative
elapsedanchor landed in #6:Stopwatch(counts up) andCountdown(counts downto a real deadline). Both are thin views over a
Clock.API
new Stopwatch(distortions?)—elapsedInMillis(warped),referenceElapsedInMillis(real).new Countdown(target: Duration, distortions?)—remainingInMillis(warped, clamped at0),
isComplete,elapsedInMillis,targetInMillis.Clockinternally and expose it via.clock.ClockgainsrunStartInMillis(the run anchor /t=0).The headline behavior: because the offset is cumulative — a dilation repaid by a later
compression — a countdown can crawl early and sprint late yet still reach zero exactly on
the real deadline (covered by a test).
Housekeeping
Duration+durationToMillisintosrc/duration.ts(was private toRelativeTimeDistortion), reused byCountdown;RelativeTimeDistortionre-exportsDurationso existing imports are unaffected.Stopwatch,Countdown, and theDurationtype.Tests / docs
StopwatchandCountdownsuites — 61 tests total,tsc --noEmitand eslint clean.Not in this PR
The
absoluteanchor + true multi-day spans (step 4),dailyrecurrence, and easeddistortions. No version bump (0.2.0 isn't shipped yet).
Refs #4
🤖 Generated with Claude Code