scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.56k stars 465 forks source link

Time part should not be there if time in search_dates output if time information is not present in text. #1162

Open KalakondaKrish opened 1 year ago

KalakondaKrish commented 1 year ago

I have used search_dates in dateparser.search. The output of search_dates is 00:00:00 when time information is not present. For example in I will connect with you on Monday, the output is [('on monday', datetime.datetime(2023, 4, 10, 0, 0))].

Is it possible for these cases where time is not present, we return only the date part of the datetime and not return time as 0,0? In postprocessing to remove time when it is 0,0. But, it will create problems when the time is indeed 0,0. How to solve this?

Gallaecio commented 1 year ago

I don’t think we support that for search_dates that the moment. We do have something like that for parsing, though.

As a workaround, for now, you could parse search match strings again with DateDataParser:

>>> from dateparser import DateDataParser
>>> parser = DateDataParser()
>>> parser.get_date_data("on monday")
DateData(date_obj=datetime.datetime(2023, 4, 10, 0, 0), period='day', locale='en')

The date still has time, but period indicates the granularity of the parsed date.