Skip to content
On this page
Parrot

DateParrot

DateParrot parses natural language into a unified schedule object or ISO date.

npm install date-parrot

This package is in a very early stage and not yet production ready.

Playground

I eat pizza every second friday  
{
  "schedule": {
    "repeatFrequency": "P2W",
    "startDate": "2023-02-10T16:46:11Z",
    "byDay": 5
  },
  "match": {
    "index": 12,
    "length": 19,
    "text": "every second friday"
  }
}

Usage

import { parseDate } from 'date-parrot'

parseDate('lets go out tomorrow')

// =>
// {
//   date: [TOMORROW_AS_ISO_STRING],
//   match: {
//     index: 12,
//     length: 8,
//     text: 'tomorrow',
//   },
// }
import { parseSchedule } from 'date-parrot'

parseSchedule('every second day')

// =>
// {
//   schedule: {
//     repeatFrequency: 'P2D',
//     startDate: '[NOW_AS_ISO_STRING]',
//   },
//   match: {
//     index: 0,
//     length: 16,
//     text: 'every second day',
//   },
// }
import { parseSchedule } from 'date-parrot'

parseSchedule('eat donuts on every 3rd friday')

// =>
// {
//   schedule: {
//     repeatFrequency: 'P1W',
//     startDate: '[NEXT_FRIDAY_AS_ISO_STRING]',
//   },
//   match: {
//     index: 11,
//     length: 16,
//     text: 'every 3rd friday',
//   },
// }

Localization

By default DateParrot only parses english but you can add support for other languages by adding a locales property to the config of the parser functions.

It takes an array of locale identifiers (e.g. ['en', 'de']).

import { parseDate } from 'date-parrot'

parseDate('lass uns morgen ausgehen', { locales: ['de'] })

// =>
// {
//   date: [TOMORROW_AS_ISO_STRING],
//   match: {
//     index: 9,
//     length: 6,
//     text: 'morgen',
//   },
// }

Parrot icon is provided by the awesome AnimalJamArchives.