Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Fdawgs opened this issue Oct 2, 2024 · 4 comments
Closed

Comments

@Fdawgs
Copy link
Contributor

Fdawgs commented Oct 2, 2024

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 }
}
*/
@Fdawgs Fdawgs changed the title Compromise-dates plugin: #Month next/last year projects to this year Compromise-dates plugin: #Month (next|last) year projects to this year Oct 2, 2024
spencermountain added a commit that referenced this issue Oct 2, 2024
@spencermountain
Copy link
Owner

shipped in compromise-dates 3.7.0
cheers

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Oct 24, 2024

@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
Copy link
Owner

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

@Fdawgs
Copy link
Contributor Author

Fdawgs commented Oct 28, 2024

You've lost me there @spencermountain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants