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

Returned datetime skips a day when timezone is supplied via settings instead of date string #1092

Closed
Baviaan opened this issue Nov 6, 2022 · 3 comments · Fixed by #1155
Closed
Assignees

Comments

@Baviaan
Copy link
Contributor

Baviaan commented Nov 6, 2022

#1002 promised to fix #403 and has been merged to master. As I discovered now it is only a partial fix.

Recall the issue was the dateparser would skip ahead a day if the time had already passed in UTC when preferring dates from the future. For example parsing 6pm EST (11pm UTC) at 10pm UTC would return tomorrow 11pm, instead of today 11pm UTC.

#1002 addresses this by passing the time zone so the correct relative base can be computed. What I didn't realize at the time is that ptz is only the time zone popped off the string. So, if the timezone is supplied via settings instead, nothing is passed along and the old bug from #403 reappears.

I might submit a pull request in the future but I wanted to report it already.

Versions:

  • Ubuntu 22.04.1 LTS
  • Python 3.10.6
  • dateparser (1.1.3)
    • python-dateutil (2.8.2)
    • pytz (2022.6)
    • regex (2022.3.2)
    • tzlocal (4.2)

Minimum working example:

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
@gutsytechster
Copy link
Collaborator

I am planning to work on it. Thanks!

@Baviaan
Copy link
Contributor Author

Baviaan commented Feb 25, 2023

I am planning to work on it. Thanks!

@gutsytechster are you still planning to work on this? Otherwise I have free time coming up in March, but I don't want to do duplicate work.

@gutsytechster
Copy link
Collaborator

Hi @Baviaan yes I have done some work on it.

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 a pull request may close this issue.

2 participants