scrapinghub / dateparser

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

Incomplete time - missing minutes are effecively making the hour ignored #1080

Open shalak opened 2 years ago

shalak commented 2 years ago

Hello!

I don't know if I'm missing something, or not. Is there a way to parse tomorrow at 12 and have the lib assume the minutes value? (i.e. have the same result as tomorrow at 12:00?)

Currently it looks like it completely ignores the hour:

>>> dateparser.parse("tomorrow")
datetime.datetime(2022, 9, 21, 1, 35, 9, 50714)

>>> dateparser.parse("tomorrow at 12")
datetime.datetime(2022, 9, 21, 1, 35, 11, 6990)

>>> dateparser.parse("tomorrow at 12:00")
datetime.datetime(2022, 9, 21, 12, 0)
owocado commented 2 years ago

from my testing, it works if you pass AM/PM after 12 but not sure if that's what you're looking for.

shalak commented 2 years ago

from my testing, it works if you pass AM/PM after 12 but not sure if that's what you're looking for.

Not really. I don't use 12h hour format. Thanks for the tip, though.

gutsytechster commented 2 years ago

The reason that the time wasn't parsed as mentioned is that the time directives defined here don't have a time format with only an hour string. If it would contain %H or %I as a directive option, the time would have been parsed in 24 hr and 12 hr formats respectively.

Apparently, there is currently no way to specify additional time formats or change the order of these time formats. This could be a potential feature I believe. I can try working on this, but let other people also chime in with their suggestions.