ChronosChronos

register

Injects a plugin into the Chronos system.

register()

Info

This is just an alias for use method. It internally uses Chronos.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 register(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.register(timeZonePlugin); // Injects timeZone() and other timezone specific methods

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

playground.ts

Notes

  • Using 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 this (register) method over use method.

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

On this page