akoumjian / datefinder

Find dates inside text using Python and get back datetime objects
http://datefinder.readthedocs.org/en/latest/
MIT License
635 stars 165 forks source link

Error in parsing date of format dd/mm/yyyy #78

Open pawankg opened 6 years ago

pawankg commented 6 years ago

While using different dates of format dd/mm/yyyy, I see that it is behaving differently as shown in below example:

Case I:

import datefinder

[i for i in datefinder.find_dates('19/04/2018')]
[datetime.datetime(2018, 4, 19, 0, 0)]

In this case I, it is extracting year = 2018, month = 4 and day = 19 as expected.

Case II:

[i for i in datefinder.find_dates('05/04/2018')]
[datetime.datetime(2018, 5, 4, 0, 0)]

But in case II, it is extracting year = 2018, month = 5 and day = 4 (swapped the value of day and month) but it should have been, month = 4 and day = 5.

ganevgv commented 6 years ago

An easy solution is to set a parameter dayfirst=True everywhere parser.parse is called in datefinder.py i.e.: parser.parse(date_string, default=self.base_date, dayfirst=True)

jsenecal commented 6 years ago

This is a duplicate of #77 and #42

r-deo commented 4 years ago

Or you can simply change the init in class class parserinfo(object): in file _parser.py and set datefirst to True

akoumjian commented 4 years ago

@pawankg Please try installing the master branch version and let me know if the solution works. There is a new first init option which will let you declare if you want ambiguous dates to be determined by year, month, or day first.

https://github.com/akoumjian/datefinder/blob/master/datefinder/__init__.py#L23

I haven't yet put it in a pypi release.

pratiklodha95 commented 3 years ago

@pawankg Please try installing the master branch version and let me know if the solution works. There is a new first init option which will let you declare if you want ambiguous dates to be determined by year, month, or day first.

https://github.com/akoumjian/datefinder/blob/master/datefinder/__init__.py#L23

I haven't yet put it in a pypi release.

Please release this in pypi