date-parser
Parses spoken datetime sentence into an Date object. Only Traditional Chinese is supported now.
Installation
Node.js
$ npm install --save date-parser$ node> dateParser = require;
Browser
Usage
I18n
Select the default locale with:
dateParser;dateParser;
Or just specify it on the go:
dateParser;
Datetime Parse
The date-parser can parse any kind of spoken datetime into an Data object:
dateParser; // -> Mon Oct 20 2014 00:00:00 GMT+0800 (CST)dateParser; // -> Mon May 05 2014 00:00:00 GMT+0800 (CST)dateParser; // -> Sun Feb 28 2010 20:00:00 GMT+0800 (CST)dateParser; // -> (Today!) 12:00:00 GMT+0800 (CST)
You can just say an incomplete sentence, the parser will smartly guesses what you want:
dateParser; // -> (Today!) 12:00:00 GMT+0800 (CST)dateParser; // -> (Today!) 18:00:00 GMT+0800 (CST)dateParser; // -> (Today!) 15:30:00 GMT+0800 (CST) (or 03:30:00, depends on current time)dateParser; // -> ... May 05 ... 00:00:00 GMT+0800 (CST)dateParser; // -> Fri ... 18:00:00 GMT+0800 (CST)
Relative datetime is supported too.
dateParser; // -> Fri ... 18:00:00 GMT+0800 (CST)dateParser; // -> ...dateParser; // -> ...dateParser; // -> (Tomorrow!) 03:00:00 GMT+0800 (CST)dateParser; // -> ... Jan 01 ... 00:00:00 GMT+0800 (CST)
You can specify an ending datetime if needed:
meeting = dateParser; // -> { (Today!) 08:00:00 GMT+0800 endTime: (Today!) 22:00:00 GMT+0800 }meetingendTime; // -> (Today!) 22:00:00 GMT+0800party = dateParser; // -> { Fri ... 18:00:00 GMT+0800 endTime: Sat ... 08:00:00 GMT+0800 }partyendTime; // -> Sat ... 08:00:00 GMT+0800
BTW, the event's name and location can also be parsed out.
play = dateParser;// -> { ... 18:00:00 GMT+0800// eventName: '一直玩一直玩一直玩',// endTime: ... 09:00:00 GMT+0800 }playeventName; // -> '一直玩一直玩一直玩'dateParser;// -> { ... 18:00:00 GMT+0800// location: '聽風家',// eventName: '披薩吃' }dateParser;// -> { (Tomorrow!) 12:00:00 GMT+0800// eventName: '開會',// endTime: (Tomorrow!) 14:00:00 GMT+0800 }