From 651b154c23a1dd06a050768ccb219bd775096fb9 Mon Sep 17 00:00:00 2001 From: Frazer Smith Date: Wed, 7 Aug 2024 09:42:11 +0100 Subject: [PATCH] feat(plugins/dates): add basic duration range skeleton --- .../src/api/parse/range/02-date-range.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 eb7bba40a..2bbe76f50 100644 --- a/plugins/dates/src/api/parse/range/02-date-range.js +++ b/plugins/dates/src/api/parse/range/02-date-range.js @@ -1,5 +1,6 @@ import parseDate from '../one/index.js' import reverseMaybe from './_reverse.js' +import Unit from '../one/units/Unit.js' export default [ { @@ -138,4 +139,25 @@ export default [ return null }, }, + + { + // 2 to 4 weeks + match: '[#Value] to [#Value] [#Duration]', + desc: '2 to 4 weeks', + parse: (m, context) => { + const { min, max, unit } = m.groups() + + let start = new Unit(context.today, null, context) + let end = start.clone() + + const duration = unit.text('implicit') + start = start.applyShift({ [duration]: min.numbers().get()[0] }) + end = end.applyShift({ [duration]: max.numbers().get()[0] }) + + return { + start: start, + end: end.end(), + } + }, + }, ]