Introduction
Time abstraction for NestJS
In most applications, time is everywhere:
But calling new Date() directly inside your business logic makes your system:
Difficult to reason about
@nestjstools/clock solves this by introducing a clean abstraction over time.
Instead of:
You write:
And now:
You can freeze time in tests
You remove infrastructure concerns from your domain layer
The Problem with new Date()
Direct system time usage:
Creates:
Tight coupling to system clock
Time is infrastructure — it should be abstracted.
The Solution: IClock
Clock introduces a simple interface:
This allows you to:
Last updated