Claude Code Plugins

Community-maintained marketplace

Feedback

effect-clock-patterns

@aitchwhy/dotfiles
3
0

Effect Clock for injectable, testable time. Never use new Date() directly.

Install Skill

1Download skill
2Enable skills in Claude

Open claude.ai/settings/capabilities and find the "Skills" section

3Upload to Claude

Click "Upload skill" and select the downloaded ZIP file

Note: Please verify skill by going through its instructions before using it.

SKILL.md

name effect-clock-patterns
description Effect Clock for injectable, testable time. Never use new Date() directly.
allowed-tools Read, Write, Edit
token-budget 800
version 1.0.0

Effect Clock Patterns

Why Not new Date()?

// UNTESTABLE
const createdAt = new Date();

Clock Service

import { Clock, Effect } from "effect";

// Helper (put in lib/clock.ts)
export const currentTimestamp = Effect.map(
  Clock.currentTimeMillis,
  (ms) => new Date(ms)
);

// Usage
const program = Effect.gen(function* () {
  const now = yield* currentTimestamp;
  yield* db.update(records).set({ updatedAt: now });
});

Testing

import { TestClock, Effect } from "effect";

const test = Effect.gen(function* () {
  yield* TestClock.setTime(new Date("2024-06-15").getTime());
  const result = yield* myTimeDependentCode;
  yield* TestClock.adjust("1 hour");
});

Effect.runPromise(test.pipe(Effect.provide(TestClock.layer)));

Migration

Before After
new Date() yield* currentTimestamp
Date.now() yield* Clock.currentTimeMillis