dateparser
dateparser copied to clipboard
Not detecting date when adding words to date string
Hi,
I am testing dateparser
and it seems that it may not work in some cases if the string containing the date contains additional words.
In the following example, I added the term "fr" to the string (randomly chosen), and tested DateDataParser
in Spanish and English. While the latter worked, the former did not.
Spanish
IN
dt = "fr 18 Mayo 2021"
ddp = DateDataParser(languages=['es'])
ddp.get_date_data(dt, date_formats=["fr %d %B %Y"])
OUT
DateData(date_obj=None, period='day', locale=None)
English
IN
dt = "fr 18 May 2021"
ddp = DateDataParser(languages=['en'])
ddp.get_date_data(dt, date_formats=["fr %d %B %Y"])
OUT
DateData(date_obj=datetime.datetime(2021, 5, 18, 0, 0), period='day', locale=None)
Any thoughts on this? I am using v1.0.0
UPDATE
After searching a bit more I realised that you state
The input string it's a valid date and it doesn't contain any other words or numbers.
I understand this if no format is given. However, if a format is given, where the added word is included (like in the example), perhaps it should work?
For now I'll be using:
from datetime import datetime
import locale
locale.setlocale(locale.LC_TIME, "es_ES")
dt = "fr 18 Mayo 2021"
datetime.strptime(dt, "fr %d %B %Y")
Why not remove the "fr "
from the input before passing it to dateparser?