Chronos Wrapper Function
Chronos Wrapper Function — Chronos Documentation.
Overview
Key Features
- Same functionality as
new Chronos()but with function syntax - Full access to all
Chronosinstance methods - Inherits all static methods from
Chronosclass (chronoswithout call signature) - Supports all
Chronosinput types - Maintains identical type safety
🧩 Plugin System
Chronos supports a modular plugin system that allows you to extend its capabilities without bloating the core. Plugin methods are not available by default, you must explicitly register them using the .use() or .register() static method.
How it works
playground.ts
Info
Each plugin enhances the Chronos prototype and becomes available globally after registration.
Usage
Import
import { chronos } from "chronos-date";Basic Instantiation
// Function style
const date = chronos('2023-12-31')
date.year // 2023
date.formatSafe() // Formatted date string
// Class style (equivalent)
const date = new Chronos('2023-12-31')
date.year // 2023
date.formatSafe() // Formatted date stringWith Components
const date = chronos(2023, 12, 31, 15, 30)
date.year // 2023
date.formatSafe() // Formatted date stringAvailable Methods & Properties
The wrapper provides access to all Chronos methods through the returned instance:
Static Methods
All Chronos static methods are available directly on the wrapper function:
| Method | Short Description |
|---|---|
| now() | Returns the number of milliseconds since 1970-01-01 UTC. |
| use() | Injects a plugin into the Chronos system. |
| register() | Alias for use() |
| utc() | Creates a UTC-based Chronos instance. |
| with() | Creates a new instance with the provided time component(s). |
| reconstruct | Reconstructs a Chronos instance from a given value. |
| parse() | Parses a date string with a given format (limited support only). |
| min() | Returns earliest Chronos. |
| max() | Returns latest Chronos. |
| clamp() | Restricts a date to a specified range |
| today() | Returns the current date in a specified format in local time. |
| tomorrow() | Returns a new Chronos instance representing tomorrow's date. |
| yesterday() | Returns a new Chronos instance representing yesterday's date. |
| formatTimePart() | Formats a time-only string into a formatted time string. |
| getDatesForDay() | Returns ISO date strings for each occurrence of a weekday. |
| isLeapYear() | Checks if the year in the date or year is a leap year. |
| isValidChronos() | Checks if the given value is an instance of Chronos. |
| isValidDate() | Checks if the given value is a valid Date object. |
| isDateString() | Checks if the given value is a valid date string. |
| isReconstructable | Checks if a value can be used to reconstruct a Chronos instance. |
Some Examples
import { chronos, Chronos } from "chronos-date";
import { timeZonePlugin } from "chronos-date/plugins/timeZonePlugin";
// Using wrapper function
chronos.parse('2023-12-31', 'YYYY-MM-DD');
chronos.today();
chronos.isLeapYear(2024);
// Registering a plugin
chronos.use(timeZonePlugin);
// Using class equivalent
Chronos.parse('2023-12-31', 'YYYY-MM-DD');
Chronos.today();
Chronos.isLeapYear(2024);
// Registering a plugin
Chronos.use(timeZonePlugin);Full Documentation
For complete method documentation, see the Chronos class reference. All methods shown there are available through this wrapper.
Last updated: Tue, Jun 23, 2026 07:34:42PM (UTC)
