Chrono Node

2.9.0 · active · verified Sun Apr 19

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).

Common errors

Warnings

Install

Imports

Quickstart

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());
}

view raw JSON →