datefinder
datefinder copied to clipboard
Error in parsing date of format dd/mm/yyyy
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.
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)
This is a duplicate of #77 and #42
Or you can simply change the init in class class parserinfo(object): in file _parser.py and set datefirst to True
@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.
@pawankg Please try installing the master branch version and let me know if the solution works. There is a new
firstinit 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