scrapinghub / dateparser

python parser for human readable dates
BSD 3-Clause "New" or "Revised" License
2.56k stars 465 forks source link

Use timezone via settings to get PREFER_DATES_FROM result #1155

Closed gutsytechster closed 1 year ago

gutsytechster commented 1 year ago

This fixes #1092

Gallaecio commented 1 year ago

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

gutsytechster commented 1 year ago

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 commented 1 year ago

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 :sweat_smile:

Gallaecio commented 1 year ago

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