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('date-parser');
Browser
<script src="./script/date-parser.min.js"></script>
Usage
I18n
Select the default locale with:
dateParser.locale('zh-TW');
dateParser.timezone('Asia/Taipei');
Or just specify it on the go:
dateParser.parse('二零一四年五月五日', 'Asia/Taipei', 'zh-TW');
Datetime Parse
The date-parser can parse any kind of spoken datetime into an Data object:
dateParser.parse('2014年10月20日');
dateParser.parse('二零一四年五月五日');
dateParser.parse('2010/2/28 晚上八點');
dateParser.parse('今天中午');
You can just say an incomplete sentence, the parser will smartly guesses what you want:
dateParser.parse('中午');
dateParser.parse('今晚');
dateParser.parse('三點半');
dateParser.parse('五月五');
dateParser.parse('星期五晚上');
Relative datetime is supported too.
dateParser.parse('下星期五晚上');
dateParser.parse('兩小時後');
dateParser.parse('這週末');
dateParser.parse('明天凌晨三點');
dateParser.parse('明年一月一號');
You can specify an ending datetime if needed:
meeting = dateParser.parse('早上八點到晚上十點');
meeting.endTime;
party = dateParser.parse('週五 6:00pm ~ 週六 10:00am');
party.endTime;
BTW, the event's name and location can also be parsed out.
play = dateParser.parse('星期五晚上到下禮拜六早上要一直玩一直玩一直玩');
play.eventName;
dateParser.parse('今天晚上在聽風家有披薩吃');
dateParser.parse('明天中午到下午要開會');