From fd45122ca2056f911cc4adcec503d7ee855f1b18 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Mon, 12 Aug 2024 15:08:28 +0100 Subject: [PATCH] fix(plugins/dates): match `^in` --- plugins/dates/src/api/parse/range/02-date-range.js | 6 +++--- plugins/dates/tests/duration-range.test.js | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugins/dates/src/api/parse/range/02-date-range.js b/plugins/dates/src/api/parse/range/02-date-range.js index 5c12013df..87a7810ce 100644 --- a/plugins/dates/src/api/parse/range/02-date-range.js +++ b/plugins/dates/src/api/parse/range/02-date-range.js @@ -141,9 +141,9 @@ export default [ }, { - // 2 to 4 weeks - match: '[#Value] to [#Value] [(day|days|week|weeks|month|months|year|years)]', - desc: '2 to 4 weeks', + // in 2 to 4 weeks + match: '^in [#Value] to [#Value] [(day|days|week|weeks|month|months|year|years)]', + desc: 'in 2 to 4 weeks', parse: (m, context) => { const { min, max, unit } = m.groups() diff --git a/plugins/dates/tests/duration-range.test.js b/plugins/dates/tests/duration-range.test.js index a7d7dc993..7d584cb93 100644 --- a/plugins/dates/tests/duration-range.test.js +++ b/plugins/dates/tests/duration-range.test.js @@ -25,12 +25,14 @@ const context = { today: '2024-01-01', } -test('duration-ranges', function (t) { +test('future duration-ranges', function (t) { durArr.forEach(obj => { obj.text.forEach(text => { - const doc = nlp(text) - const duration = doc.dates(context).get()[0].duration + const doc = nlp(`in ${text}`) + const { duration, start, end } = doc.dates(context).get()[0] t.deepEqual(duration, obj.duration, text) + t.ok(start > context.today, 'start date') + t.ok(end > start, 'end date') }) }) t.end()