scrapinghub / dateparser

python parser for human readable dates

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Returned datetime skips a day

Baviaan opened this issue · comments

I reported in #1092 that the datetime is returned correctly only when supplying the timezone in the argument but not via settings, which is still the behaviour as of 1.1.7. As of 1.1.8, both options give the same result again, however the date is wrong. See an example below.

Note this is a different example than the one provided in #1092, the original example now works correctly on 1.1.8. This bug seems to occur when the time is already the next day in UTC.

Versions:

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

Minimum working example

#!/usr/bin/env python3
import dateparser
import datetime

parse_settings={
        'PREFER_DATES_FROM': 'future',
        'TO_TIMEZONE': 'etc/utc',
        'RETURN_AS_TIMEZONE_AWARE': False,
        'RELATIVE_BASE': datetime.datetime(2023, 5, 21, 15, 0)
        }

time = dateparser.parse('7pm EDT', settings=parse_settings)
print(time) # 2023-05-21 23:00:00
time = dateparser.parse('9pm EDT', settings=parse_settings)
print(time) # 2023-05-23 01:00:00

parse_settings['TIMEZONE'] = 'america/new_york'
time = dateparser.parse('7pm', settings=parse_settings)
print(time) # 2023-05-21 23:00:00
time = dateparser.parse('9pm', settings=parse_settings)
print(time) # 2023-05-23 01:00:00