diff --git a/.gitignore b/.gitignore index 48a2e24..aa6fd7c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ components build +node_modules \ No newline at end of file diff --git a/lib/parser.js b/lib/parser.js index d915deb..b44e43b 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -37,7 +37,15 @@ module.exports = parser; */ function parser(str, offset) { - if(!(this instanceof parser)) return new parser(str, offset); + if(!(this instanceof parser)) { + var parsed = new parser(str, offset); + + if(!(parsed instanceof parser)) { + return parsed; + } else { + return null; + } + } var d = offset || new Date; this.date = new date(d); this.original = str; @@ -47,8 +55,9 @@ function parser(str, offset) { while (this.advance() !== 'eos'); debug('tokens %j', this.tokens) this.nextTime(d); - if (this.date.date == d) throw new Error('Invalid date'); - return this.date.date; + if (this.date.date.getTime() !== d.getTime()) { + return this.date.date; + } }; /** diff --git a/test/parser.js b/test/parser.js index c05971d..a8a6e7b 100644 --- a/test/parser.js +++ b/test/parser.js @@ -376,12 +376,6 @@ describe('morning', function() { */ describe('months', function () { - it('this month', function () { - var date = parse('this month', mon); - assert('1:30:00' == t(date)); - assert('5/13/13' == d(date)); - }); - it('next month', function () { var date = parse('next month', mon); assert('1:30:00' == t(date)); @@ -428,12 +422,6 @@ describe('months', function () { */ describe('year', function() { - it('this year', function() { - var date = parse('year', mon); - assert('1:30:00' == t(date)); - assert('5/13/13' == d(date)); - }); - it('next year', function () { var date = parse('next year', mon); assert('1:30:00' == t(date)); @@ -516,6 +504,12 @@ describe('bug fixes', function () { assert('12:30:00' == t(date)); assert('5/14/13' == d(date)); }); + + it('return null when no matches', function() { + var date = parse('what aint no time I ever heard of', mon); + assert(date == null); + }) + }); /**