scrapinghub / dateparser

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

TypeError when using timezone-aware as RELATIVE_BASE #491

Open perrinjerome opened 5 years ago

perrinjerome commented 5 years ago

With this snippet:

# dateparser==0.7.0  ( also reproduces on master branch )
import dateparser
import datetime
import pytz

settings = { "RELATIVE_BASE":  datetime.datetime.now().replace(tzinfo=pytz.timezone("Europe/Paris")) }

for input_ in ( "2009-06-01T10:00:00+09:00", "yesterday", "July 5th"):
    print (input_, dateparser.parse(input_), dateparser.parse(input_, settings=settings))

"2009-06-01T10:00:00+09:00" or "yesterday" work as expected, but "July 5th" cause a TypeError: can't compare offset-naive and offset-aware datetimes, that is raised here

noviluni commented 4 years ago

Added a comment in this related issue: https://github.com/scrapinghub/dateparser/issues/679 linking to a draft PR with a possible workaround.