scrapinghub / dateparser

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

parse method returns incorrect result #1156

Open gutsytechster opened 1 year ago

gutsytechster commented 1 year ago

I have found that the following MWE also seems to produce the same bug, even if PREFER_DATES_FROM is not set:

from datetime import datetime
from dateparser import parse
DATEPARSER_SETTINGS = {
    'TIMEZONE': 'UTC',
    'TO_TIMEZONE': 'UTC',
    'RETURN_AS_TIMEZONE_AWARE': False,
    'RELATIVE_BASE': datetime(2019, 8, 18, 3, 55, 1, 0)
}

dt = parse("9:57 PM MDT", settings=DATEPARSER_SETTINGS)  # datetime(2019, 8, 19, 3, 57, 0)
expected = datetime(2019, 8, 18, 3, 57, 0)
assert dt == expected  # fail:  dt is a day later than expected

Note that RELATIVE_BASE is set to 9:55:01 PM MDT on 17 August, which is before the specified time of "9:57 PM MDT" in the parse input. The returned dt value is neither the nearest future or past instance of 9:57 PM MDT relative to the current time (RELATIVE_BASE).

Originally posted by @Laogeodritt in https://github.com/scrapinghub/dateparser/issues/403#issuecomment-524612341