A tiny library to rapidly have time !
It's a very simple typescript library to setup a source of time. A time provider works with a compatible adapter (even for native Date or Temporal), so you must both import the core library and the plugin of your choice (See usage).
| Name | NPM package |
|---|---|
| @time-provider/core |
Currently supported plugins are :
| Plugin | Name | Returned Type | NPM package |
|---|---|---|---|
| Temporal | @time-provider/plugin-temporal | Instant | |
| Native | @time-provider/plugin-native | Date | |
| Luxon | @time-provider/plugin-luxon | DateTime | |
| Day.js | @time-provider/plugin-dayjs | Dayjs | |
| Moment.js | @time-provider/plugin-moment | Moment |
- Each plugin (adapter) exports a
TimeAdapterand aFixedTimeAdapterclass - Select your desired plugin (
native/dayjs/moment/luxon/temporal) - call
createTimeProvider.for(/*your adapter here*/)
import { createTimeProvider } from "@time-provider/core";
//Import the plugin of your choice (here the temporal plugin)
import { TimeAdapter } from "@time-provider/plugin-temporal";
import { Temporal } from "@js-temporal/polyfill";
const timeProvider = createTimeProvider.for(new TimeAdapter());import { createTimeProvider } from "@time-provider/core";
//Import the plugin of your choice (here the temporal plugin)
import { FixedTimeAdapter } from "@time-provider/plugin-temporal";
import { Temporal } from "@js-temporal/polyfill";
const fixedTimeProvider = createTimeProvider.for(
new FixedTimeAdapter(Temporal.Instant.from("2026-01-01T00:00Z")),
);interface ITimeProvider<TDate> {
localNow(): TDate;
utcNow(): TDate;
parse(input: string | number | TDate): TDate;
}