chrono (GitHub: wanasit/chrono, License: MIT) is a natural language date parser in Javascript. It is designed to extract date informations from any given text. Works in node and browser. Check out the nifty test page.
npm install chrono-node
chrono supports a number of date and time formats, including:
- Today, Tomorrow, Yesterday, last Friday, etc
- 10/13/2013
- this Friday from 13:00 – 16.00
- Saturday, 17 August 2013 – Monday, 19 August 2013
- Sat Aug 17 2013 18:40:39 GMT+0900 (JST)
Usage
> var chrono = require('chrono-node')
> chrono.parseDate('An appointment on Sep 12-13')
Thu Sep 12 2013 12:00:00 GMT+0900 (JST)
> chrono.parse('An appointment on Sep 12-13')
[ { start:
{ year: 2013,
month: 8,
day: 12,
impliedComponents: [Object],
isCertain: [Function],
date: [Function] },
startDate: Thu Sep 12 2013 12:00:00 GMT+0900 (JST),
end:
{ year: 2013,
month: 8,
day: 13,
impliedComponents: [Object],
isCertain: [Function],
date: [Function] },
endDate: Fri Sep 13 2013 12:00:00 GMT+0900 (JST),
referenceDate: Sat Aug 17 2013 17:54:57 GMT+0900 (JST),
index: 18,
text: 'Sep 12-13',
concordance: 'An appointment on Sep 12-13' } ]
What’s even more cool, chrono is designed to work with long text (notes, emails, articles, etc). chrono.parse
will return an array of every date mentioned in the story.
> var text = 'October 7, 2011, of which details were not revealed out of respect to Jobs\'s family.[239] Apple announced on the same day that they had no plans for a public service, but were encouraging "well-wishers" to send their remembrance messages to an email address created to receive such messages.[240] Sunday, October 16, 2011'
> chrono.parse(text)
[{ start:
{ year: 2011,
month: 9,
day: 7,
....
{ start:
{ year: 2011,
month: 9,
day: 16,
....
There are plenty of examples and information on the . Check it out!