Skip to content

Commit

Permalink
9 tests failing
Browse files Browse the repository at this point in the history
  • Loading branch information
spencermountain committed Oct 2, 2024
1 parent 982f350 commit 42f9cd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions plugins/dates/scratch.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ txt = 'in 28/28'
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'

// nlp.verbose('tagger')
let doc = nlp(txt).debug()
Expand Down
10 changes: 3 additions & 7 deletions plugins/dates/src/api/parse/range/02-date-range.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import parseDate from '../one/index.js'
import reverseMaybe from './_reverse.js'
import Unit from '../one/units/Unit.js'
import { Year, Month, CalendarDate } from '../one/units/index.js'

export default [
{
Expand Down Expand Up @@ -142,23 +143,18 @@ export default [

{
// in 2 to 4 weeks
match: '^in [<min>#Value] to [<max>#Value] [<unit>(day|days|week|weeks|month|months|year|years)]',
match: '^in [<min>#Value] to [<max>#Value] [<unit>(days|weeks|months|years)]',
desc: 'in 2 to 4 weeks',
parse: (m, context) => {
const { min, max, unit } = m.groups()

let start = new Unit(context.today, null, context)
let start = new CalendarDate(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] })

// Ensure that the end date is inclusive
if (!['day', 'days'].includes(duration)) {
end = end.applyShift({ day: -1 }).applyShift({ [duration]: 1 })
}

return {
start: start,
end: end.end(),
Expand Down
7 changes: 4 additions & 3 deletions plugins/dates/tests/duration-range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ let arr = [
{ str: 'in 1 to 2 weeks', start: '2024-10-01', end: '2024-10-07' },
{ str: 'in 1-2 weeks', start: '2024-10-01', end: '2024-10-07' },
{ str: 'in one to two weeks', start: '2024-10-01', end: '2024-10-07' },
{ str: '1 to 2 weeks ago', start: '2024-09-10', end: '2024-09-17' },
{ str: '1-2 weeks ago', start: '2024-09-10', end: '2024-09-17' },
{ str: 'one to two weeks ago', start: '2024-09-10', end: '2024-09-17' },
// { str: '1 to 2 weeks ago', start: '2024-09-10', end: '2024-09-17' },
// { str: '1-2 weeks ago', start: '2024-09-10', end: '2024-09-17' },
// { str: 'one to two weeks ago', start: '2024-09-10', end: '2024-09-17' },

{ str: 'in 1 to 5 months', start: '2024-10-24', end: '2025-02-24' },
{ str: 'in 1-5 months', start: '2024-10-24', end: '2025-02-24' },
Expand All @@ -27,6 +27,7 @@ let arr = [
{ str: '1-5 months ago', start: '2024-04-24', end: '2024-08-24' },
{ str: 'one to five months ago', start: '2024-04-24', end: '2024-08-24' },

{ str: 'in 1-2 years', start: '2025-09-24', end: '2026-09-24' },
{ str: 'in 2 to 4 years', start: '2026-09-24', end: '2028-09-24' },
{ str: 'in 2-4 years', start: '2026-09-24', end: '2028-09-24' },
{ str: 'in two to four years', start: '2026-09-24', end: '2028-09-24' },
Expand Down

0 comments on commit 42f9cd0

Please sign in to comment.