wanasit / chrono

A natural language date parser in Javascript
MIT License
4.53k stars 340 forks source link

isTimeOnly() ignores year only #446

Open Novak-Peter opened 2 years ago

Novak-Peter commented 2 years ago

When creating a custom parser for year only, and using this with ranges (like 2019-2021), second date will always be removed by ENMergeDateTimeRefiner / AbstractMergeDateTimeRefiner - due to the following expression:

https://github.com/wanasit/chrono/blob/606c28cf18a7789746c3ebd68a75a34531090169/src/common/refiners/AbstractMergeDateTimeRefiner.ts#L14

As it turns out, isOnlyTime ignores having year only:

https://github.com/wanasit/chrono/blob/606c28cf18a7789746c3ebd68a75a34531090169/src/results.ts#L108-L110 I would definitely add this here: && !this.isCertain("year")

If this is valid in your opinion, I can create a simple PR for this.

wanasit commented 2 years ago

If this is valid in your opinion, I can create a simple PR for this.

Your explanation make senses. Please feel free to submit a PR. Just make sure all current tests pass.