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

v1.2.0 returns wrong month with future dates #1202

Open
realtimeprojects opened this issue Nov 27, 2023 · 2 comments
Open

v1.2.0 returns wrong month with future dates #1202

realtimeprojects opened this issue Nov 27, 2023 · 2 comments

Comments

@realtimeprojects
Copy link

realtimeprojects commented Nov 27, 2023

tested on 2023-11-27, 15:33 UTC:

v1.1.8:

>>> import dateparser
>>> dateparser.parse("Friday 15:53", settings={'PREFER_DATES_FROM': 'future'})
datetime.datetime(2023, 12, 1, 15, 53)

v1.2.0:

>>> import dateparser
>>> dateparser.parse("Friday 15:53", settings={'PREFER_DATES_FROM': 'future'})
datetime.datetime(2023, 11, 1, 15, 53)
@jgayfer
Copy link

jgayfer commented Feb 1, 2024

A workaround is to set the relative base with an explicit time zone (tested on Wednesday January 31st).

>>> import dateparser
>>> from datetime import datetime, timezone
>>> dateparser.parse("Thursday at 6pm")
datetime.datetime(2024, 1, 1, 18, 0)
>>> dateparser.parse("Thursday at 6pm", settings={"RELATIVE_BASE": datetime.now(timezone.utc)})
datetime.datetime(2024, 2, 1, 18, 0)

EDIT: This may have been because it's late enough in January, that changing the timezone pushed me over into February.

@jgayfer
Copy link

jgayfer commented Feb 1, 2024

I have a hunch this change is what caused the issue: #1179

There is a change from datetime.datetime.utcnow() to datetime.datetime.now(datetime.timezone.utc), which changes us from a naive timestamp to a timezone aware timestamp. Most notably here.

However, this is purely a hunch.

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

No branches or pull requests

3 participants