From 78db1c1a26c167419e5570709ef5828e0e5d8a40 Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Sat, 12 Oct 2019 19:34:41 -0500 Subject: [PATCH] Restore forward-bias for timespan parsing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This broke as a result of updating the Chrono version in e1b7b1b. It’s too bad because it wasn’t a major version change! Other parsing bugs remain but it addresses this one: https://github.com/backspace/prison-rideshare-ui/issues/68#issuecomment-527691809 --- app/utils/parse-timespan.js | 2 +- tests/unit/utils/parse-timespan-test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/utils/parse-timespan.js b/app/utils/parse-timespan.js index 0522d0da..2a1983db 100644 --- a/app/utils/parse-timespan.js +++ b/app/utils/parse-timespan.js @@ -44,7 +44,7 @@ chronoInstance.refiners.push(assumePM); export default function parseTimespan(value) { const [parsed] = chronoInstance.parse(value, new Date(), { - forwardDatesOnly: true, + forwardDate: true, }); return parsed; } diff --git a/tests/unit/utils/parse-timespan-test.js b/tests/unit/utils/parse-timespan-test.js index 1fe29088..ccc66ff9 100644 --- a/tests/unit/utils/parse-timespan-test.js +++ b/tests/unit/utils/parse-timespan-test.js @@ -72,4 +72,23 @@ module('Unit | Utility | parse timespan', function(hooks) { ); assert.notOk(parsed.end); }); + + test('it assumes future dates unless fully specified', function(assert) { + window.chronokinesis.travel(new Date(1570925744254)); + // Saturday 2019-10-12 19:15 + + assertParsing( + assert, + 'thursday from 7 to 9', + '2019-10-17 19:00', + '2019-10-17 21:00' + ); + + assertParsing( + assert, + 'oct 10 2019 from 1 to 4', + '2019-10-10 13:00', + '2019-10-10 16:00' + ); + }); });