sisyphsu / dateparser

dateparser is a smart and high-performance date parser library, it supports hundreds of different formats, nearly all format that we may used. And this is also a showcase for "retree" algorithm.
MIT License
95 stars 23 forks source link

preferMonthFirst is not reset when month is given greater than 12 #24

Closed Kiruthikaaarthi closed 2 years ago

Kiruthikaaarthi commented 2 years ago

Hi ,

While using DateParser lib for en_US language, where it considers month first, it works as expected if we provide any values within 12 for month. Example: 09/21/2021. But when we provide greater than 12( example, 17/03/2021), it is behaving a bit different. From my understanding from document, it should not consider a preferMonthFirst if it is greater than 12. So, expected date in this case is March 17, 2021. But it displays, May 3, 2022.

Case 1: prefer date first: In the below example, when we provided the month greater than 12, it prefers first value as a month. This is expected and correct behaviour

dateParser.setPreferMonthFirst(false); dateParser.parseDate("12/17/21") Result: Date@64 "Fri Dec 17 00:00:00 IST 2021"

Case 2: prefer month first: In the below example, when we provide month greater than 12, it ideally should reset to prefer date first.

dateParser.setPreferMonthFirst(true); dateParser.parseDate("17/09/2021") Result: Date@72 "Mon May 09 00:00:00 IST 2022" Expected Value: : Mon Sept 17 00:00:00 IST 2021

Not sure why the behaviour is like this. We would also expect it to parse without considering preferMonthFirst.

Could you please help us here on how we can handle this so that we get date as first prefered only in this edge case?

Kiruthikaaarthi commented 2 years ago

@sisyphsu , We have a fix for this and created a PR for the same: https://github.com/sisyphsu/dateparser/pull/25 Can you please review this?

Thanks in advance, Kiruthika

sisyphsu commented 2 years ago

Thanks for your PR.

I have merged it into 1.0.10 version

Kiruthikaaarthi commented 2 years ago

Thanks @sisyphsu ! :)