Registry / data / chrono-node

chrono-node

JSON →
library2.9.0jsnpmunverified

Chrono Node (chrono-node) is a natural language date and time parser for JavaScript, currently at version 2.9.0. It allows developers to extract and interpret date and time information from arbitrary text, supporting a wide range of formats including relative phrases ("tomorrow," "5 days ago"), absolute dates ("17 August 2013"), and date ranges ("Sep 12-13"). Since its v2 rewrite, the library is implemented in TypeScript, offering a more modular architecture with distinct parser and refiner interfaces. It differentiates itself by focusing on a performant, native JavaScript date/time core (having removed `dayjs` in v2.9.0) and providing robust control over parsing context, including explicit reference dates and timezones. While previous versions attempted to parse all known languages by default, v2.0.0 and later default to international English, requiring explicit configuration for other supported locales (e.g., Japanese, French, Dutch, Russian, Ukrainian).

npm install chrono-node
INSTALL
IMPORT
SIG · CHRONO-NODE
C
chrono-node
datajavascriptv2.9.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

chrono
import * as chrono from 'chrono-node';
import chrono from 'chrono-node';
Chrono is exported as a namespace object, so use `* as chrono` for all exports in ESM. Default import (`import chrono from 'chrono-node'`) will likely result in `undefined` or an empty object in many environments.
parseDate
import { parseDate } from 'chrono-node';
import { parseDate } from 'chrono-node/dist/chrono.js';
The `parseDate` function is a direct named export from the main package. Accessing internal paths like `dist/chrono.js` is not recommended and may break in future versions. You can also access it via the namespace import: `chrono.parseDate`.
ParsedResult, ParsingReference, ParsingOption
import type { ParsedResult, ParsingReference, ParsingOption } from 'chrono-node';
import { ParsedResult, ParsingReference, ParsingOption } from 'chrono-node';
These are TypeScript types and interfaces. Use `import type` for type-only imports to ensure they are stripped during compilation, preventing potential runtime errors or unnecessary bundle size increases.
chrono (CommonJS)
const chrono = require('chrono-node');
For CommonJS environments, the entire library is exported, accessible through `chrono.parseDate()` and `chrono.parse()`.

This quickstart demonstrates basic date parsing, advanced parsing with a reference date and timezone, and the use of the `forwardDate` option for future-only interpretations. It also shows how to get detailed parsing results.

import * as chrono from 'chrono-node'; import type { ParsingReference, ParsingOption } from 'chrono-node'; const text1 = 'An appointment on Sep 12-13 from 2 PM to 4 PM next Friday'; const text2 = 'Tomorrow at noon in New York'; const text3 = 'In 3 days'; // Basic parsing const result1 = chrono.parseDate(text1); console.log('Result 1 (basic):', result1?.toISOString()); // Parsing with a specific reference date and timezone const referenceInstant = new Date('2025-02-27T10:00:00Z'); // UTC instant const referenceOptions: ParsingReference = { instant: referenceInstant, timezone: 'America/Los_Angeles' // Reference timezone for interpretation }; const result2 = chrono.parseDate(text2, referenceOptions); console.log('Result 2 (ref + timezone):', result2?.toISOString()); // Parsing with the 'forwardDate' option to ensure future dates const today = new Date('2025-03-01T12:00:00Z'); // Saturday, March 1, 2025 const forwardOptions: ParsingOption = { forwardDate: true }; const result3 = chrono.parseDate(text3, today, forwardOptions); console.log('Result 3 (forwardDate):', result3?.toISOString()); // Full parsed result (including text, index, start/end components) const detailedResult = chrono.parse('Book a meeting for next Tuesday at 3pm', new Date('2025-03-01T00:00:00Z'), { forwardDate: true }); if (detailedResult.length > 0) { console.log('Detailed result:', JSON.stringify(detailedResult[0], null, 2)); console.log(' Extracted text:', detailedResult[0].text); console.log(' Parsed date:', detailedResult[0].date().toISOString()); }
Debug
Known issues
breakingChrono v2.0.0 changed its default behavior from attempting to parse all known languages to only international English. Code relying on auto-detection or parsing non-English text without explicit locale configuration will produce incorrect results or fail to parse.
fix
For non-English text, explicitly import and use the desired locale parser, e.g., `import { ja } from 'chrono-node'; ja.parseDate('...')` or `chrono.ja.parseDate('...')`. You can also create a custom Chrono instance with specific locales.
affects: >=2.0.0
breakingVersion 2.9.0 removed the `dayjs` dependency and consequently deprecated and removed `ParsingComponent.dayjs()`. Any custom parsers or existing code relying on this function will break.
fix
Refactor custom components or code to use native JavaScript `Date` objects directly or other date utility libraries, as `chrono-node` now exclusively relies on native `Date` functionality.
affects: >=2.9.0
gotchaIncorrect date interpretation for relative terms (e.g., 'tomorrow', 'next Friday') can occur if the `ParsingReference` is not correctly set. The meaning of such terms is highly dependent on the `instant` and `timezone` provided in the reference.
fix
Always provide a `ParsingReference` object with both `instant` (the current `Date` or a specific reference point) and `timezone` (e.g., 'America/New_York' or a minute offset) to ensure consistent and accurate parsing relative to a specific context.
affects: >=2.0.0
gotchaThe `forwardDate` parsing option, when `true`, forces Chrono to interpret relative dates (like 'Friday' or 'next month') as being in the future relative to the `reference` date. If not set, it may resolve to a past date if it's closer.
fix
If you consistently need dates to be in the future, explicitly set `{ forwardDate: true }` in the `ParsingOption` object when calling `chrono.parseDate` or `chrono.parse`.
affects: >=2.0.0
gotchaVersion 2.8.0 introduced a fix where reference date calculations (e.g., for "1 day ago", "tomorrow at 9am") are now based on the *assigned timezone* of the reference instant/timestamp, rather than the system's local timezone. This change might subtly alter results for users relying on implicit system timezone behavior.
fix
Review existing code that provides reference instants and relies on system timezone interpretations for relative dates. Ensure that the `timezone` property within `ParsingReference` accurately reflects the intended time context for your parsing operations.
affects: >=2.8.0
Errors
Common errors & fixes
TypeError: chrono.ParsingComponent.dayjs is not a function
Upgrading to chrono-node v2.9.0 without updating code that used the `dayjs` integration. The `dayjs` dependency and its related functions were removed in v2.9.0.
fix
Remove any calls to `ParsingComponent.dayjs()` or other `dayjs`-specific logic from your custom parsers or integrations. Refactor to use native JavaScript `Date` methods.
Error: Cannot find module 'chrono-node' or undefined is not a function/object for chrono
Incorrect import statement for ESM or CommonJS modules, or trying to use named imports when the library uses a namespace export, especially in mixed environments.
fix
For ESM, use `import * as chrono from 'chrono-node';`. For CommonJS, use `const chrono = require('chrono-node');`. Ensure your build configuration (webpack, rollup, TypeScript `moduleResolution`) correctly handles module types.
Date results are in the past when expecting future dates (e.g., 'Friday' parses to last Friday)
The parser defaults to the closest matching date. If 'Friday' has already passed in the current week relative to the reference date, it will pick the past Friday.
fix
Pass the `forwardDate: true` option in the `ParsingOption` object: `chrono.parseDate('Friday', referenceDate, { forwardDate: true });`
Parsing results for relative dates (e.g., 'today', 'tomorrow') are incorrect when timezones are involved.
The reference date's timezone might not be correctly applied during interpretation, especially when the system timezone differs from the intended reference timezone. This was explicitly fixed in v2.8.0 for some scenarios.
fix
Always provide a comprehensive `ParsingReference` object with both `instant` (a `Date` object) and `timezone` (a string like 'America/Los_Angeles' or a minute offset) to ensure consistent timezone-aware parsing.
Upgrade
Version history
2.9.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources