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

Use timezone via settings to get PREFER_DATES_FROM result #1155

Merged
merged 3 commits into from Mar 22, 2023

Conversation

gutsytechster
Copy link
Collaborator

This fixes #1092

This ensures that we are still processing times such as EDT or AEDT which
returns UnknownTimezoneError with pytz.timezone method.
@Gallaecio
Copy link
Member

I have run the minimum working example from the original report, and the output is the same before and after this change.

@gutsytechster
Copy link
Collaborator Author

The test cases would fail on the master branch. Also, for me, the changes result in the correct output.

In [1]: import dateparser
   ...: import datetime
   ...: 
   ...: working_settings={
   ...:         'PREFER_DATES_FROM': 'future',
   ...:         'TO_TIMEZONE': 'etc/utc',
   ...:         'RETURN_AS_TIMEZONE_AWARE': False,
   ...:         'RELATIVE_BASE': datetime.datetime(2022, 11, 6, 22, 0)
   ...:         }
   ...: 
   ...: broken_settings = working_settings
   ...: broken_settings['TIMEZONE'] = 'america/new_york'
   ...: 
   ...: correct_time = dateparser.parse('6pm EST', settings=working_settings)
   ...: print(correct_time) # 2022-11-06 23:00:00
   ...: 
   ...: wrong_time = dateparser.parse('6pm', settings=broken_settings)
   ...: print(wrong_time) # 2022-11-07 23:00:00
2022-11-06 23:00:00
2022-11-06 23:00:00

@Gallaecio
Copy link
Member

You are right, I am getting the expected output with the fix now. I have no idea what I did wrong before, I must have installed the wrong branch 😅

@Gallaecio Gallaecio self-requested a review March 22, 2023 13:36
@Gallaecio
Copy link
Member

Today I Learn pip install git+… does not actually overwrite the installed package if they both have the same version in setup.py 😓

@serhii73 serhii73 merged commit eddaac6 into scrapinghub:master Mar 22, 2023
8 checks passed
@gutsytechster gutsytechster deleted the fix-time-from-future-1092 branch March 23, 2023 13:09
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

Successfully merging this pull request may close these issues.

Returned datetime skips a day when timezone is supplied via settings instead of date string
3 participants