Skip to content

Commit

Permalink
3 failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 6, 2024
1 parent b6b5560 commit 32101c7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
3 changes: 1 addition & 2 deletions plugins/dates/scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nlp.verbose('date')

const fmt = iso => (iso ? spacetime(iso).format('{day-short} {nice} {year}') : '-')

// process.env.DEBUG_DATE = true
process.env.DEBUG_DATE = true

// date issues:
// 'the month before christmas' vs 'a month before christmas'
Expand Down Expand Up @@ -48,7 +48,6 @@ 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
5 changes: 5 additions & 0 deletions plugins/dates/src/api/parse/one/units/_year.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class Month extends Unit {
this.d = this.d.startOf('month')
return this
}
middle() {
this.d = this.d.add(15, 'days')
this.d = this.d.startOf('day')
return this
}
}

class AnyQuarter extends Unit {
Expand Down
27 changes: 26 additions & 1 deletion plugins/dates/src/api/parse/range/02-date-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default [


{
// one month, no year - 'january 5 to 7'
// implicit range
match: '^until [<to>#Date+]',
desc: 'until christmas',
parse: (m, context) => {
Expand All @@ -202,4 +202,29 @@ export default [
return null
},
},

{
// second half of march
match: '[<part>(1st|initial|2nd|latter)] half of [<month>#Month] [<year>#Year?]',
desc: 'second half of march',
parse: (m, context) => {
const { part, month, year } = m.groups()
let obj = {
month: month.text('reduced'),
date: 1, //assume 1st
year: year && year.found ? year.text('reduced') : context.today.year()
}
let unit = new Month(obj, null, context)
if (part.has('(1st|initial)')) {
return {
start: unit.start(),
end: unit.clone().middle(),
}
}
return {
start: unit.middle(),
end: unit.clone().end(),
}
},
},
]
2 changes: 2 additions & 0 deletions plugins/dates/src/compute/matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,7 @@ let matches = [
{ match: '(from|by|before) now', unTag: 'Time', tag: 'Date' },
// 18th next month
{ match: '#Value of? (this|next|last) #Date', tag: 'Date' },
// first half of march
{ match: '(first|initial|second|latter) half of #Month', tag: 'Date' },
]
export default matches
8 changes: 5 additions & 3 deletions plugins/dates/tests/equals.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ const arr = [
['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'],
['first half of march', '2020-03-01 to 2020-03-16'],
['second half of march', '2020-03-16 to 2020-03-30 '],
]

test('date-variety', function (t) {
arr.forEach((a) => {
let left = nlp(a[0]).dates(context).json()[0] || {}
let right = nlp(a[1]).dates(context).json()[0] || {}
left.date = left.date || {}
right.date = right.date || {}
t.equal(left.date.start, right.date.start, a[0])
left.dates = left.dates || {}
right.dates = right.dates || {}
t.equal(left.dates.start, right.dates.start, a[0] + ' -> ' + a[1])
})
t.end()
})

0 comments on commit 32101c7

Please sign in to comment.