spencermountain / compromise

modest natural-language processing
http://compromise.cool
MIT License
11.49k stars 655 forks source link

Compromise-dates plugin: `#Month (next|last) year` projects to this year #1147

Closed Fdawgs closed 1 month ago

Fdawgs commented 1 month ago

Node version: 20.17.0 Compromise version: 14.14.0 Compromise-dates version: 3.6.0

Sorry, probably sick of all the Issues raised by me! Using the compromise-dates plugin, sentences that match #Month (next|last) year are projected as this year. However, (next|last) #Month and #WeekDay (next|last) week work as expected.

Example:

'use strict'

/** @type {import('compromise').default} */
const nlp = require('compromise')
const nlpDates = require('compromise-dates')
nlp.plugin(nlpDates)

const context = {
  today: '2023-01-01',
}

let text = 'June next year'
const doc1 = nlp(text)
const dates1 = doc1.dates(context).get()[0]
console.log(dates1)
/**
Output:
{
  start: '2023-06-01T00:00:00.000+01:00',
  end: '2023-06-30T23:59:59.999+01:00',
  timezone: 'Europe/London',
  duration: { years: 0, months: 1, days: 0, hours: 0, minutes: 0 }
}

Expected:
{
  start: '2024-06-01T00:00:00.000+01:00',
  end: '2024-06-30T23:59:59.999+01:00',
  timezone: 'Europe/London',
  duration: { years: 0, months: 1, days: 0, hours: 0, minutes: 0 }
}
*/

text = 'next June'
const doc2 = nlp(text)
const dates2 = doc2.dates(context).get()[0]
console.log(dates2)
/**
Output:
{
  start: '2024-06-01T00:00:00.000+01:00',
  end: '2024-06-30T23:59:59.999+01:00',
  timezone: 'Europe/London',
  duration: { years: 0, months: 1, days: 0, hours: 0, minutes: 0 }
}
*/

text = 'Monday next week'
const doc3 = nlp(text)
const dates3 = doc3.dates(context).get()[0]
console.log(dates3)
/**
Output:
{
  start: '2023-01-02T00:00:00.000+00:00',
  end: '2023-01-02T23:59:59.999+00:00',
  timezone: 'UTC',
  duration: { years: 0, months: 0, days: 0, hours: 0, minutes: 0 }
}
*/
spencermountain commented 1 month ago

shipped in compromise-dates 3.7.0 cheers

Fdawgs commented 1 month ago

@spencermountain Sorry just got around testing 3.7.0. This is almost fixed, the year shifts correctly but the end date is now the first day of the month rather than the last.

June next year:

{
  start: '2024-06-01T00:00:00.000+01:00',
  end: '2024-06-01T23:59:59.999+01:00', // expected '2024-06-30T23:59:59.999+01:00',
  timezone: 'Europe/London',
  duration: { years: 0, months: 0, days: 1, hours: 0, minutes: 0 }
}

#Month this year and #Month last year also has the same issue with the day no longer being the last day of the month.

spencermountain commented 1 month ago

Yeah. It's a little awkward. I think it's maybe library-wide. Only a millisecond, but still awkward.

Fdawgs commented 4 weeks ago

You've lost me there @spencermountain.