tsentials-time

Inject DateTimeProvider with UTC methods and a fake clock for deterministic tests.

49|Updated May 12, 2026
One-click install
npx skills add https://github.com/senrecep/tsentials --skill tsentials-time
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tsentials-time
Source: https://github.com/senrecep/tsentials/tree/main/.well-known/agent-skills/tsentials-time
Command: npx skills add https://github.com/senrecep/tsentials --skill tsentials-time

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves nondeterministic tests and inconsistent timestamps caused by using Date.now() or new Date() directly in production code.

Core Features & Use Cases

  • Testable time abstraction: Define a DateTimeProvider that your services depend on, so time is injectable and controllable.
  • UTC-focused methods: Use utcNow(), utcNowDate(), and utcNowMs() to keep behavior consistent and time-zone safe.
  • Deterministic fake clock for tests: Use createFakeDateTimeProvider to freeze time, advance time, and set an exact moment for assertions.

Quick Start

In your service, inject SystemDateTimeProvider for production behavior and inject createFakeDateTimeProvider for deterministic tests.

Frequently Asked Questions about tsentials-time

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

FAQPage Schema
How do I make deterministic tests for code using Date.now and new Date?

To write deterministic tests, replace direct Date.now() calls with a DateTimeProvider interface. This injectable abstraction lets you control time in tests by using a fake clock to freeze or advance timestamps as needed.

How does dependency injection fix nondeterministic time behavior in testing?

Dependency injection fixes nondeterministic time behavior by replacing direct Date.now() calls with an injectable DateTimeProvider. You inject a SystemDateTimeProvider for production and a fake clock for controlled, predictable test scenarios.

Can I freeze and advance time in UTC for date-only comparisons?

Yes, you can freeze and advance UTC time for date-only comparisons using a fake clock. The DateTimeProvider exposes utcNow(), utcNowDate(), and utcNowMs() methods, while the test double supports advance(ms) and setTime(date).

What is the best way to abstract time for consistent UTC timestamps?

The best way to abstract time for consistent UTC timestamps is implementing a DateTimeProvider interface. It provides utcNow(), utcNowDate(), and utcNowMs() methods to keep behavior time-zone safe and predictable across domain and service code.

Do I need to replace all Date.now calls to use a fake clock?

You need to replace Date.now() and new Date() calls in domain and service code that requires consistent UTC timestamps. Inject the DateTimeProvider into these specific areas to enable deterministic testing with a fake clock.