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

"Friday" with preference set to future yields a Tuesday in the past. #1243

Open
yspreen opened this issue Nov 1, 2024 · 2 comments
Open

Comments

@yspreen
Copy link

yspreen commented Nov 1, 2024

Python 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dateparser
>>> from datetime import datetime, timedelta
>>>
>>> def date(s):
...     parsed_date = dateparser.parse(s, settings={"PREFER_DATES_FROM": "future"})
...     return parsed_date.strftime("%a %b %d")
...
>>>
>>> date("Friday")
'Tue Oct 08'
>>> datetime.now()
datetime.datetime(2024, 10, 31, 21, 37, 14, 810455)

I called this method earlier today, before UTC time (I'm -4) was past midnight and I got Oct 1 instead, also a Tuesday. Checking the year reveals that it's indeed Oct 2024 which is in the past.

dateparser==1.2.0

@yspreen
Copy link
Author

yspreen commented Nov 1, 2024

in other news, when I parse "Nov 1" I now get "Sat Nov 1" which is also incorrect since Nov 1 is a friday this year.

@yspreen
Copy link
Author

yspreen commented Nov 1, 2024

doesn't seem like the library is actively maintained, so for anyone running into this issue in the future, this worked for me:

def date(s):
    cal = parsedatetime.Calendar()
    time_struct, parse_status = cal.parse(s)
    date = datetime(*time_struct[:6])

    # Format in Eastern timezone if needed

    eastern_date = pytz.timezone("US/Eastern").localize(date)
    return eastern_date.strftime("%a %b %d")

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

No branches or pull requests

1 participant