Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing of **12/31/2014** date in csv fails #148

Open
ranjanprj opened this issue Dec 4, 2015 · 2 comments
Open

Parsing of **12/31/2014** date in csv fails #148

ranjanprj opened this issue Dec 4, 2015 · 2 comments

Comments

@ranjanprj
Copy link

The parsing of following date format in csv is failing
12/31/2014

This I'm guessing is due to following lines in
dateparser.py ->

def create_date_formats(day_first=True):
    """generate combinations of time and date
    formats with different delimeters
    """

    if day_first:
        date_formats = ['dd/mm/yyyy', 'dd/mm/yy', 'yyyy/mm/dd']
        python_date_formats = ['%d/%m/%Y', '%d/%m/%y', '%Y/%m/%d']
    else:
        date_formats = ['mm/dd/yyyy', 'mm/dd/yy', 'yyyy/mm/dd']
        python_date_formats = ['%m/%d/%Y', '%m/%d/%y', '%Y/%m/%d']

The day_first is always true so it never takes mm/dd/yyyy format.
Request to have a look.

Regards

@ThrawnCA
Copy link
Contributor

ThrawnCA commented Nov 8, 2016

It's actually a default value for day_first, not forced. But yes, the code currently uses the default. What would you have it do instead?

@dragondave
Copy link

If there's a spreadsheet which contains strings which are unambiguously m/d/y and no/very few strings that are unambigously d/m/y, then it'd be reasonable to parse it as m/d/y by default.
(anything with a first number <13 and a second number >12/<32 is unambiguously m/d/y)
That'd mean parsing the sheet twice, though, and would lead to issues if there were only sometimes unambiguous m/d/y dates across a range of consistently m/d/y sheets.

There's also no obvious way to override messytable's behaviour; whilst I suspect something like messytables.types.DateType.formats = messytables.dateparser.create_date_formats(day_first=False) would work, it's not a nice, public, documented override; being able to configure it somewhere at a high level would make sense. Not sure where the right place would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants