Formats like "1h20m" should be treated as relative but are actually absolute
When parsing a string like "1h20m", it should be treated as a relative date; i.e. the same as it would treat the string "1 hour and 20 minutes". However this is not the actual behaviour.
>>> from datetime import datetime
>>> from dateparser import parse
>>> datetime.now()
datetime.datetime(2021, 10, 28, 18, 17, 11, 563442)
>>> parse("1h20m")
datetime.datetime(2021, 10, 28, 1, 20)
>>> parse("in 1h20m")
datetime.datetime(2021, 10, 28, 1, 20)
>>> parse("in 1 hour and 20 minutes")
datetime.datetime(2021, 10, 28, 19, 37, 34, 355178)
I agree that “in 1h20m” needs fixing, I’m less sure about the one without the “in”. I feel like for the interpretation of that one we should have a setting that could indicate if it should be interpreted as time in the future, time in the past, or absolute time (which I would keep as default).
Even with the setting to prefer in the future it still treats "1h20m" as absolute.
Also, I feel it would definitely make the most sense for "1h20m" and "1 hour 20 minutes" to give the same results as one is a literal abbreviation of the other.
Note that a space makes a difference:
>>> parse("1h20m")
datetime.datetime(2021, 10, 28, 1, 20)
>>> parse("1h 20m")
datetime.datetime(2021, 10, 28, 16, 46, 56, 916241)
That is really counter intuitive. I think it would make most sense to make all those as relative.
A possible workaround for the time being:
string = re.sub(r"([dhms])(\d)", r"\1 \2", "1h20m")
parse(string)
This will add a space which will cause it to be treated relatively