Skip to content

Commit

Permalink
support until christmas
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 6, 2024
1 parent 072e0ec commit b6b5560
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/dates/scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const fmt = iso => (iso ? spacetime(iso).format('{day-short} {nice} {year}') : '
// 'the month before christmas' vs 'a month before christmas'
// middle september
// end of september
// first half of march
// week of june 3rd
// fridays in june
// every saturday
Expand Down Expand Up @@ -48,6 +47,8 @@ txt = '1 to 5 weeks ago'
txt = 'in 2-4 years from now'
txt = 'in 1-2 weeks from now'
txt = 'in 1 to 2 months'
txt = `first half of march`
txt = `until christmas`

// nlp.verbose('tagger')
let doc = nlp(txt).debug()
Expand Down
20 changes: 20 additions & 0 deletions plugins/dates/src/api/parse/range/02-date-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,24 @@ export default [
}
},
},



{
// one month, no year - 'january 5 to 7'
match: '^until [<to>#Date+]',
desc: 'until christmas',
parse: (m, context) => {
let to = m.groups('to')
to = parseDate(to, context)
if (to) {
let start = new CalendarDate(context.today, null, context)
return {
start: start,
end: to.start(),
}
}
return null
},
},
]
2 changes: 2 additions & 0 deletions plugins/dates/tests/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ const arr = [
[`tuesday at 1`, `tuesday at 1pm`],
['this fri, monday', 'fri jan 24 and mon jan 27'],
['next friday, this monday', 'fri jan 31 and mon jan 27'],
['until christmas', '2020-01-21 to 2020-12-25'],
['until feb 3 2024', '2020-01-21 to 2024-02-03'],
]

test('date-variety', function (t) {
Expand Down

0 comments on commit b6b5560

Please sign in to comment.