ChronosChronos

use

Injects a plugin into the Chronos system.

use()

Injects a plugin into the Chronos system. This enables dynamic extension of the Chronos class at runtime by registering external functionality as methods on its prototype.

One-time Injection

A plugin is only injected once per runtime. Re-registering the same plugin has no effect.

Info

  • Plugins should be injected before any instance creation.
  • Internally, Chronos maintains a #plugins set to prevent duplicate injections.
  • This system is ideal for modular features like seasons, zodiac, or timeZone etc. support.

Signature

static use(plugin: ChronosPlugin): void

Parameters

NameTypeDescription
pluginChronosPluginA plugin function that receives the Chronos class constructor and augments it.

Example

import { Chronos } from "chronos-date";
import { timeZonePlugin } from "chronos-date/plugins/timeZonePlugin";

Chronos.use(timeZonePlugin); // Injects timeZone() and other timezone specific methods

Once injected, the plugin methods become available on all Chronos instances:

playground.ts

Alias

This method is also available as Chronos.register(). Both behave the same way.

Notes

  • Using this (use) method in React projects may trigger linter error like "React Hooks must be called in a React function component or a custom React Hook function."
  • To prevent this incorrect linter error in React projects, prefer using register method (alias of use method).

Last updated: Thu, May 21, 2026 07:12:18AM (UTC)

On this page