From 588aa7fa711d166e9caaa0df651183da454f684b Mon Sep 17 00:00:00 2001 From: David Kaneda Date: Sat, 29 Jun 2013 14:10:19 -0700 Subject: [PATCH 1/2] Ignore node_modules --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From 94a813d074b3246fbd75094141f9017ad34636a5 Mon Sep 17 00:00:00 2001 From: David Kaneda Date: Sat, 29 Jun 2013 14:19:13 -0700 Subject: [PATCH 2/2] Return null with no matches and nix "this month" and "this year." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a bit of a subjective patch: It changes the behavior so that unmatched entries return null. Previously, there was code that looked to throw an error in this situation, though the code wasn't constructed right and would never throw. When implemented properly, the code errors on "this year" and "this month" as they both fulfill the "error" requirement of Date.js output matching "now." I think it would be good if we always expect something consistent out of date.js — which I believe is a specific time & date based off the input. ie, the library should support: * "Next tuesday," or "tomorrow" (guessing the time based off of now) * Tomorrow at 3pm * Now (this should probably be added...) * etc. But it should _not_ support: * Every 5 minutes (iterative time increments) * For the next 3 months (span of time) * "This month" and "this year" (vague) Just a thought, discussion welcome :) --- lib/parser.js | 15 ++++++++++++--- test/parser.js | 18 ++++++------------ 2 files changed, 18 insertions(+), 15 deletions(-) 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); + }) + }); /**