Skip to content

Use timezone via settings to get PREFER_DATES_FROM result#1155

Merged
serhii73 merged 3 commits intoscrapinghub:masterfrom
gutsytechster:fix-time-from-future-1092
Mar 22, 2023
Merged

Use timezone via settings to get PREFER_DATES_FROM result#1155
serhii73 merged 3 commits intoscrapinghub:masterfrom
gutsytechster:fix-time-from-future-1092

Conversation

@gutsytechster
Copy link
Copy Markdown
Collaborator

This fixes #1092

This ensures that we are still processing times such as EDT or AEDT which
returns UnknownTimezoneError with pytz.timezone method.
@gutsytechster gutsytechster requested a review from Gallaecio March 22, 2023 08:39
@Gallaecio
Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor

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
Copy Markdown
Contributor

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
@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