scrapinghub / dateparser

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

Returned datetime skips a day #1169

Closed Baviaan closed 11 months ago

Baviaan commented 1 year ago

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:

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