Skip to content

Commit

Permalink
feat(plugins/dates): add basic duration range skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Aug 7, 2024
1 parent 8565e74 commit 651b154
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions plugins/dates/src/api/parse/range/02-date-range.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import parseDate from '../one/index.js'
import reverseMaybe from './_reverse.js'
import Unit from '../one/units/Unit.js'

export default [
{
Expand Down Expand Up @@ -138,4 +139,25 @@ export default [
return null
},
},

{
// 2 to 4 weeks
match: '[<min>#Value] to [<max>#Value] [<unit>#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(),
}
},
},
]

0 comments on commit 651b154

Please sign in to comment.