开发者社区> 镜像站> NPM> compromise-dates
compromise-dates
plugin for nlp-compromise
Last updated 2 months ago by spencermountain .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install compromise-dates 
SYNC missed versions from official npm registry.
date-parsing plugin for compromise

npm install compromise-dates
`compromise-date` also depends on [compromise-numbers](../numbers)
npm install compromise-numbers
const nlp = require('compromise')
nlp.extend(require('compromise-dates'))
nlp.extend(require('compromise-numbers'))

let doc = nlp('my birthday is June 5th 1998')
doc.dates().json()
/*[{ 
  text: 'June 5th 1998',
  date: { start: '1998-06-05T00:00:00.000-04:00', end: null } 
}]*/

Date-Formats

explicit-dates

  • march 2nd
  • 2 march
  • tues march 2
  • march the second
  • on the 2nd numerical-dates
  • 1999/03/02
  • 1999-03-02
  • 03-02-1999
  • 03/02
  • 2015.08.13 named-dates
  • today
  • easter
  • q1
  • tomorrow time:
  • 2pm
  • 2:12pm
  • 2:12
  • 02:12:00
  • 2 oclock
  • before 1
  • noon
  • at night
  • in the morning
  • tomorrow evening timezone:
  • eastern time
  • est
  • peru time
  • GMT+9 relative duration
  • this march
  • this week
  • this sunday
  • next april
  • this past year
  • second week of march
  • last weekend of march
  • last spring
  • the saturday after next punt
  • two days after tomorrow
  • in seven weeks
  • 2 weeks from now
  • 2 weeks after
  • 2 years 4 months 5 days ago
  • a week friday
  • a week and a half before
  • on the 1st start/end
  • end of the week
  • start of next year
  • start of next year
  • middle of q2 last year

Date-ranges

  • between [june] and [july]
  • from [today] to [haloween]
  • [aug 1] - [aug 31]
  • [today] to [next friday]
  • during june
  • before [2019]
  • by march
  • after february
  • 22-23 February

API

  • .dates() - find dates like June 8th or 03/03/18
    • .dates().json() - overloaded output with date metadata
    • .dates().format('') - convert the dates to specific formats

.dates() accepts an optional object, that lets you set the context for the date parsing.

const context = {
  timezone: 'Canada/Eastern', //the default timezone is 'ETC/UTC'
  today: '2020-02-20', //the implicit, or reference day/year
  casual_duration: { weeks: 2 }, // the implied duration to use for 'after june 2nd'
}

nlp('in two days')
  .dates(context)
  .json()

Work in progress.

MIT

Current Tags

  • 1.2.0                                ...           latest (2 months ago)

8 Versions

  • 1.2.0                                ...           2 months ago
  • 1.1.0                                ...           3 months ago
  • 1.0.0                                ...           6 months ago
  • 0.0.5                                ...           10 months ago
  • 0.0.4                                ...           a year ago
  • 0.0.3                                ...           a year ago
  • 0.0.2                                ...           a year ago
  • 0.0.1                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 20
Last Month 29
Dependencies (2)
Dependents (1)