Home/Tools/@tpmjs/tools-date-parse

dateParseTool

@tpmjs/tools-date-parse

Parse dates from natural language text like "tomorrow at 3pm", "next Friday", "in 2 weeks", or "December 25th, 2024". Returns all found dates with their original text, ISO format, and Unix timestamps.

Official
data
v0.1.0
MIT

Interactive Playground

Test @tpmjs/tools-date-parse (dateParseTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-date-parse
pnpm add @tpmjs/tools-date-parse
yarn add @tpmjs/tools-date-parse
bun add @tpmjs/tools-date-parse
deno add npm:@tpmjs/tools-date-parse

2. Import the tool

import { dateParseTool } from '@tpmjs/tools-date-parse';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { dateParseTool } from '@tpmjs/tools-date-parse';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { dateParseTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
text
Required
Type: string

Text containing one or more date/time expressions

referenceDate
Optional
Type: string

ISO 8601 date string to use as reference for relative dates (e.g., "2024-01-15T10:00:00Z"). Defaults to current date/time.

strict
Optional
Type: boolean

Use strict parsing mode for more accurate results with fewer false positives (default: false)

Schema extracted: 1/1/2026, 8:18:35 AM

README

@tpmjs/tools-date-parse

Parse dates in various natural language formats using chrono-node.

Installation

npm install @tpmjs/tools-date-parse

Usage

import { dateParseTool } from '@tpmjs/tools-date-parse';

const result = await dateParseTool.execute({
  text: 'Meeting tomorrow at 3pm and follow-up next Friday'
});

console.log(result.count);
// => 2

console.log(result.dates[0]);
// => {
//   parsed: "Thursday, January 16, 2025 at 3:00:00 PM EST",
//   original: "tomorrow at 3pm",
//   iso: "2025-01-16T20:00:00.000Z",
//   timestamp: 1737057600000
// }

Options

// Use a custom reference date
const result = await dateParseTool.execute({
  text: 'in 2 weeks',
  referenceDate: '2024-01-01T00:00:00Z'
});

// Use strict mode for fewer false positives
const result = await dateParseTool.execute({
  text: 'The year 2024 was great',
  strict: true
});

Features

  • Natural language: Parses dates like "tomorrow", "next week", "in 3 days"
  • Absolute dates: Handles "December 25th, 2024", "Jan 1", "2024-01-15"
  • Times: Supports "3pm", "15:30", "9:00 AM"
  • Multiple dates: Extracts all dates from a single text input
  • Reference dates: Calculate relative dates from a custom starting point
  • Strict mode: Reduce false positives with stricter parsing

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
date
time
parse
chrono
natural-language

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai
dateParseTool | TPMJS | TPMJS