dateparser icon indicating copy to clipboard operation
dateparser copied to clipboard

RETURN_TIME_AS_PERIOD for relative times with hours/minutes/seconds

Open miseran opened this issue 2 years ago • 0 comments

Currently, a relative time with granularity less than a day will still result in a period of day, even when RETURN_TIME_AS_PERIOD is set:

In [1]: parser = dateparser.date.DateDataParser(settings={'RETURN_TIME_AS_PERIOD': True})

In [2]: parser.get_date_data('in 2 hours')
Out[2]: DateData(date_obj=datetime.datetime(2022, 3, 12, 19, 47, 25, 221085), period='day', locale='en')

This PR changes that behaviour, so that a period of time is is returned in this case.

The PR doesn't change the behaviour when RETURN_TIME_AS_PERIOD is false. This means that in 2 months and 2 hours results in period month, even though the actual granularity is much finer. I find this counter-intuitive, however there are tests for this, so I kept that behaviour.

miseran avatar Mar 12 '22 17:03 miseran