scrapinghub / dateparser

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

Feature request: add PREFER_TIME_OF_DAY in settings #802

Open monatis opened 4 years ago

monatis commented 4 years ago

Hi, Thank you for this great project --we find it quite useful for our conversational AI projects. Let me explain the feature I'm suggesting: In current / default behavior, when time is missing it is interpreted as the current time of day. A flag in settings called PREFER_TIME_OF_DAY might be useful just like PREFER_DAY_OF_MONTH. For example, a date string tomorrow is parsed as 24 hours from now. With PREFER_TIME_OF_DAY introduced, it can be parsed as a preferred time of day (e.g., 9:00 a.m.).

Thanks.

noviluni commented 4 years ago

Hi @monatis !

Thank you for your comment. I'm going to think about it and return to you.

For then meanwhile, you can use something like:

import dateparser

>>> dateparser.parse('tomorrow').replace(hour=9, minute=0, second=0, microsecond=0)                                                                 
datetime.datetime(2020, 9, 30, 9, 0)
monatis commented 4 years ago

Hi @noviluni, thank you for the tip! I'll think through it --it might be the solution when applied with some extra conditionals to detect if a time expression is missing.

Gallaecio commented 4 years ago

Hi @noviluni, thank you for the tip! I'll think through it --it might be the solution when applied with some extra conditionals to detect if a time expression is missing.

That should be easy once https://github.com/scrapinghub/dateparser/pull/778 is merged (e.g. if date_data.period == "day").

Bubu commented 3 years ago

I'm looking for a similar thing. I just wanted to add that currently specifying a day of the week gives a time of 0:00. It would be nice to have this apply to that as well.