effect-clock-patterns

Replace new Date with Effect Clock for deterministic timestamps in tests.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/aitchwhy/dotfiles --skill effect-clock-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: effect-clock-patterns
Source: https://github.com/aitchwhy/dotfiles/tree/main/config/quality/generated/skills/effect-clock-patterns
Command: npx skills add https://github.com/aitchwhy/dotfiles --skill effect-clock-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

Why Not new Date()?

Code uses Clock service for testable time.

Core Features & Use Cases

  • CurrentTime via Clock
  • Test clocks via TestClock

Quick Start

Replace Date with Clock.currentTimeMillis in code.

Frequently Asked Questions about effect-clock-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make time-dependent code testable in TypeScript with Effect?

Time-dependent code becomes testable by injecting a Clock service instead of calling new Date or Date.now directly. Effect's Clock.currentTimeMillis provides deterministic timestamps that you control in tests, replacing hardcoded time dependencies with injectable, mockable time sources.

What's the best way to replace Date.now in Effect projects?

Replace Date.now and new Date calls with yield* currentTimestamp or Clock.currentTimeMillis within Effect code. This yields control of time to the Effect runtime, enabling test clocks to intercept and manipulate timestamps for deterministic test scenarios.

Can I simulate time in tests without mocking Date globally?

Yes. TestClock provides isolated time manipulation scoped to individual tests without global mocking. You control timestamp advancement, enabling replayable CI scenarios and reliable time-based migrations without affecting other code or tests running concurrently.

Why should I use injectable clocks instead of freezing Date in tests?

Injectable clocks decouple time from implementation details, making migrations safer and tests more composable. TestClock enables deterministic time control per test without global state, preventing test pollution and supporting complex scenarios like time-based migrations with full auditability.

Does this work for TypeScript projects outside Effect?

This Skill applies specifically to TypeScript projects using the Effect library. Effect's Clock service and TestClock utilities integrate with Effect's type system and runtime to manage time as a dependency, not as a general-purpose Date replacement.