@multitenantkit/adapter-system-system-clock
v0.2.0
Published
System Clock adapter using real system time
Maintainers
Readme
multitenantkit/adapter-system-system-clock
System adapter that implements clock functionality using real system time.
Overview
This package provides a concrete implementation of the ClockPort interface from multitenantkit/domain-contracts, using JavaScript's built-in Date object.
Installation
This package is part of the MultiTenantKit monorepo and is installed automatically via workspace dependencies.
Usage
import { SystemClock } from '@multitenantkit/adapter-system-system-clock';
const clock = new SystemClock();
const currentTime = clock.now(); // Returns current DateArchitecture
This adapter follows the Hexagonal Architecture (Ports & Adapters) pattern:
- Port:
ClockPortinterface defined inmultitenantkit/domain-contracts - Adapter:
SystemClockclass that implements the port using JavaScript Date
Features
- ✅ Real system time using
new Date() - ✅ Type-safe implementation of
ClockPort - ✅ Zero external dependencies (uses JavaScript built-in Date)
- ✅ Suitable for production use
Why Separate Package?
This adapter is extracted into its own package to:
- Separation of Concerns: System utilities are independent from persistence logic
- Reusability: Can be used by any adapter (JSON, Postgres, etc.) without coupling
- Testability: Easy to mock with fixed time for deterministic tests
- Clean Architecture: Respects dependency inversion principle
Testing
For testing purposes, you can easily create a mock clock:
class MockClock implements ClockPort {
constructor(private fixedTime: Date) {}
now(): Date {
return this.fixedTime;
}
}
// Use in tests
const fixedDate = new Date('2024-01-01T00:00:00Z');
const mockClock = new MockClock(fixedDate);Related Packages
multitenantkit/domain-contracts- Defines theClockPortinterfacemultitenantkit/adapter-system-crypto-uuid- UUID generation adapter
