Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

search_dates() wrong result for 12:xx am #894

Open
jfbauer432 opened this issue Mar 3, 2021 · 2 comments
Open

search_dates() wrong result for 12:xx am #894

jfbauer432 opened this issue Mar 3, 2021 · 2 comments

Comments

@jfbauer432
Copy link

search_dates() gives wrong results for times between 12:00 am and 12:59 am (hour is off by 12), but parse() is correct.

>>> import dateparser
>>> from dateparser.search import search_dates 
>>> dateparser.__version__
'1.0.0'
>>> 
>>> search_dates('March 3, 2021, 12:47 am')
[('March 3, 2021, 12:47 am', datetime.datetime(2021, 3, 3, 12, 47))]
>>>
>>> dateparser.parse('March 3, 2021, 12:47 am')
datetime.datetime(2021, 3, 3, 0, 47)

Python version is 3.8.9, OS is Ubuntu 20.10

@jfbauer432
Copy link
Author

If anyone else runs into this I have a workaround. It wraps the search_dates() function to reparse (with dateparser.parse) dates that have the hour equal to 12. Just put the following code before your first call to search_dates()

import functools
import dateparser
from dateparser.search import search_dates

def fix_search_dates(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        odates = func(*args, **kwargs)
        if odates is None:
            return None

        ndates = []
        for (dstr, dt) in odates:
            if dt.hour == 12:
                dt = dateparser.parse(dstr)
            ndates.append((dstr, dt))
        return ndates
    return wrapper

search_dates = fix_search_dates(search_dates)

@StarTrooper08
Copy link

search_dates() gives wrong results for times between 12:00 am and 12:59 am (hour is off by 12), but parse() is correct.

>>> import dateparser
>>> from dateparser.search import search_dates 
>>> dateparser.__version__
'1.0.0'
>>> 
>>> search_dates('March 3, 2021, 12:47 am')
[('March 3, 2021, 12:47 am', datetime.datetime(2021, 3, 3, 12, 47))]
>>>
>>> dateparser.parse('March 3, 2021, 12:47 am')
datetime.datetime(2021, 3, 3, 0, 47)

Python version is 3.8.9, OS is Ubuntu 20.10

I guess Search dates function uses 24 hrs time format not the 12 hrs ones .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants