Add absolute anchor and Clock-level timezone#8
Merged
Merged
Conversation
The third and final window anchor (issue #4): { absolute } pins a distortion to a fixed real-world instant, independent of when the Clock was constructed. True multi-day spans fall out for free -- AbsoluteWindow is plain instant arithmetic, so an arbitrarily long referenceDuration (e.g. { hours: 72 }) has none of the ~24h overnight-wrap limit a time-of-day window has. Resolving an absolute wall-clock start needs a zone, so the Clock gains a read-only timeZone (default 'UTC'), threaded into window resolution and used by both time-of-day and absolute windows. This also closes a latent gap: time-of-day windows were silently UTC-only. - resolveAt(anchorMs) -> resolveAt(anchorMs, timeZone?) across the DistortionWindow contract; TimeWindow uses it with construction-zone fallback, ElapsedWindow ignores it. - New AbsoluteWindow; { absolute: Date | AbsoluteDescriptor } added to DistortionAnchor (bare descriptor still defaults to time-of-day). - Clock: new Clock(distortions, { timeZone }) + timeZone getter. - Export the AbsoluteDescriptor type. Zone is immutable (construct a new Clock to change it); mid-run zone changes are deferred -- they need an injectable run-anchor/offset and a time-of-day refire policy. Adds AbsoluteWindow, absolute-anchor (incl. a multi-day span across a sparse read), and Clock-timezone tests. Full suite green (72 tests), coverage thresholds met, 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
The third and final window anchor from issue #4.
{ absolute }pins a distortion to afixed real-world instant, independent of when the
Clockwas constructed — and, sinceit's plain instant arithmetic, it delivers true multi-day spans (an arbitrarily long
referenceDurationlike{ hours: 72 }, with none of the ~24h overnight-wrap limit atime-of-day window has).
Resolving an absolute wall-clock start needs a timezone, so the
Clockgains one — whichalso closes a latent gap: time-of-day windows were silently UTC-only.
API
{ absolute: Date | AbsoluteDescriptor }added toDistortionAnchor(bare descriptorstill defaults to time-of-day;
{ elapsed }unchanged).Date= an instant;AbsoluteDescriptor={ year, month, day, hour?, ... }resolved in the clock's zone.new Clock(distortions, { timeZone })— read-only, default'UTC', plus atimeZonegetter. Used by time-of-day and absolute windows alike.
AbsoluteDescriptortype.How it fits
The
resolveAt(anchorMs, timeZone?)extension to the window contract absorbed everything —the offset integrator is unchanged.
TimeWindowhonors the passed zone (construction-zonefallback for standalone use);
ElapsedWindowignores it (run-relative).Design note
The zone is immutable — to run in a different zone, build a new
Clock. Mid-run zone changesare deliberately out of scope: the offset is path-dependent and time-of-day windows refire/skip
ambiguously when local time jumps, so that needs an injectable run-anchor/offset (seeded
successor clock) plus a refire policy — a separable follow-up.
Tests / docs
AbsoluteWindow,AbsoluteAnchor(incl. a 3-day span integrated once across a sparseread), and
ClockTimezone(same window, different instants per zone) suites — 72 tests,coverage thresholds met,
tsc+ eslint clean.{ absolute }anchor (multi-day example) and the{ timeZone }option.Not in this PR
Mid-run zone rebasing,
dailyrecurrence, eased distortions, calendar-aware durations. Noversion bump (0.2.0 isn't shipped yet).
Refs #4
🤖 Generated with Claude Code