wanasit / chrono

A natural language date parser in Javascript
MIT License
4.6k stars 341 forks source link

Cannot parse Month and Year #540

Closed ailinvenerus closed 10 months ago

ailinvenerus commented 1 year ago

Not passing when trying to parse:

wanasit commented 10 months ago

The first case is fixed in 2cbe42274d86fbb039c2fa2bf97c1186688a2546

The second case is more tricky.

ailinvenerus commented 10 months ago

Thank you! For the second case I don't have any other option than using the strict mode (this happens a lot in finance), is there another possible solution using strict mode?

wanasit commented 10 months ago

Sorry for my slow reply.

is there another possible solution using strict mode?

For a domain-specific use case, I recommend creating a custom configuration rather than using the pre-built chrono.strict or chronoe.casual.

You can check src/locales/en/configuration.ts and src/locales/en/index.ts on what parsers/refiners are added in English and choose only the ones you want.

const configurations = {
   parsers: [
    new ISOFormatParser(),
    new SlashDateFormatParser(littleEndian),
    new ENTimeUnitWithinFormatParser(strictMode),
    ... 
  ], refiners: [
   new ExtractTimezoneOffsetRefiner(),
   new OverlapRemovalRefiner(),
   ...
  ]
}

const customChrono = new Chrono(configurations);

Hope this helps.