wanasit / chrono

A natural language date parser in Javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`parseResult.text` Missing Prefix "in" for Relative Time Expressions

ilDon opened this issue · comments

commented

Description:

If a relative time expression has the prefix "in", the parseResult.text omits this prefix. This inconsistency makes it difficult to match the result against the library a second time since the text without the "in " is no longer parsed as a date

Steps to Reproduce:

  1. Parse a relative time expression with the "in" prefix:
let result = chrono.parse('in 1 month');
  1. Observe the parseResult.text value:
console.log(result[0].text);  // Outputs: "1 month"

Expected Behavior:

The parseResult.text value should be "in 1 month".

Actual Behavior:

The parseResult.text value is "1 month", missing the "in" prefix.

Impact:

This behavior makes it challenging to check the parsed result against the library again since the "in" prefix is missing.
It would be helpful to have a consistent representation of the parsed text in parseResult.text.

Environment:

chrono-node version: 2.6.4

Hello @ilDon.

Thanks for reporting this, but I cannot reproduce the issue that you mention on the latest codebase (see. 2d09189).

Could you share more details about your project? Ideally, could you send me a link to a code example I could checkout and try?

commented

I'm not able to reproduce this anymore with 2.6.6 either :-)

commented

I stand corrected, I am able to reproduce this bug also in 2.6.6.

Try this:

const configuration = chrono.casual.defaultConfig.createCasualConfiguration(false)
const chronoInstance = new chrono.Chrono(configuration)
const forwardFrom = new Date()
const result = chronoInstance.parse(text, forwardFrom, { startDayHour: 8 })

.text will be 1 month, without in

ok. I found a bug with {forwardDate: true} options (not { startDayHour: 8 } in your example though).

Could you check if it's fixed in: 2421760 (should be in 2.7.0+).