Feature request: Report smallest interval of parsed string

Bug #828003 reported by Tim Cera
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
dateutil
New
Undecided
Unassigned

Bug Description

I need the smallest date interval that is in the parsed string.

For example, currently:

In [1]: import dateutil.parser as ps

In [2]: ps.parse('5/18/1964')
Out[2]: datetime.datetime(1964, 5, 18, 0, 0)

In [3]: ps.parse('5/18/1964 00:00')
Out[3]: datetime.datetime(1964, 5, 18, 0, 0)

I need to know how detailed the string is. The datetime doesn't tell me since parsing both strings results in hour = 0 and minute = 0.

Perhaps something like

ps.functionname('5/18/1964')
'Day'

ps.functionname('5/18/1964 00:00')
'Second'

ps.functionname('1964')
'Year'

...etc.

Started looking at the code to see where I could fit this in, but thought it best to post the feature request since it might be a very easy thing to do for someone who is already familiar with the code.

It would be nice for the reported interval to be consistent with pytseries.sf.net.

Kindest regards,
Tim

Revision history for this message
Tim Cera (timcera) wrote :

Can't edit the bug report, but as I submitted found that one of my examples is incorrect.

The following:

ps.functionname('5/18/1964 00:00')
'Second'

Should be:

ps.functionname('5/18/1964 00:00')
'Minute'

Revision history for this message
Tim Cera (timcera) wrote :

Well, here is a patch that implements an 'interval_precision' function. Probably not the best implementation wise in terms of the Don't Repeat Yourself in that I just copied a portion of the 'parse' function instead of working out something else, but it works.

Kindest regards,
Tim

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.