Skip to content

Deterministic time-window eligibility engine for GuildPass rules - #407

Merged
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
Violetlove200100:feat/380-time-window-engine
Aug 30, 2026
Merged

Deterministic time-window eligibility engine for GuildPass rules#407
Lakes41 merged 3 commits into
Adamantine-guild:mainfrom
Violetlove200100:feat/380-time-window-engine

Conversation

@Violetlove200100

Copy link
Copy Markdown
Contributor

Closes #380

Summary

Implements packages/time-window, a pure, dependency-free time-window evaluator for GuildPass rules, per the issue's independence requirement (no membership/reward/governance/persistence integration).

What's included

  • TimeWindow with explicit startInclusive / endInclusive boundary flags
  • Validation: rejects reversed windows and invalid dates (InvalidTimeWindowError); zero-length windows allowed
  • isWithinWindow — single-window evaluation with exact boundary semantics
  • isWithinWindows — multi-window evaluation with documented any (default) and all modes
  • isWindowActive — current-time evaluation with an injectable clock (no real-time sleeps in tests)
  • mergeWindows — pure helper merging overlapping/touching windows; inclusive edge wins; input order irrelevant; output sorted
  • All comparisons on UTC epoch instants (.getTime()), never local-time strings

Acceptance criteria coverage (47 unit tests)

  • ✅ Inclusive & exclusive start boundaries tested
  • ✅ Inclusive & exclusive end boundaries tested
  • ✅ Instants inside / outside evaluate correctly
  • ✅ Reversed windows rejected
  • ✅ Invalid dates rejected safely (including non-Date values)
  • ✅ UTC-equivalent instants (UTC string, Date.UTC, -04:00 offset, offset-defined window edges) evaluate identically
  • ✅ Multi-window semantics deterministic and documented (empty list → true for both modes)
  • ✅ Exact boundary timestamps covered (including ±1 ms probes)
  • ✅ Injected clock for current-time evaluation
  • pnpm typecheck / pnpm build / pnpm test pass in the package
  • ✅ No domain integration included

Test plan

  • pnpm --filter @guildpass/time-window typecheck
  • pnpm --filter @guildpass/time-window build
  • pnpm --filter @guildpass/time-window test (47/47 pass)

🤖 Generated with Codebuff

…amantine-guild#380)

Adds packages/time-window, a pure rule-evaluation primitive with explicit
boundary semantics: inclusive/exclusive edges, UTC-normalized comparisons,
any/all multi-window evaluation, a pure merge helper, injectable clock,
and safe rejection of reversed/invalid dates. 47 unit tests covering all
acceptance criteria; no domain or persistence dependencies.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Lakes41

Lakes41 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

This PR cannot be merged automatically because it has merge conflicts.

Please update the branch with the latest base branch and resolve the conflicts.

After the conflicts are resolved and checks pass, the automation can review it again.

Violetlove200100 and others added 2 commits August 30, 2026 16:11
Upstream tsconfig.base.json pins types to ["node"], which dropped the
jest globals in test files. Declare ["node", "jest"] locally.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@Lakes41
Lakes41 merged commit 144b8d4 into Adamantine-guild:main Aug 30, 2026
2 checks passed
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.

Build a deterministic time-window eligibility engine for GuildPass rules

2 participants