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

Odd parsing from list of formats #447

Closed
richyvk opened this issue Jul 14, 2017 · 2 comments · Fixed by #655
Closed

Odd parsing from list of formats #447

richyvk opened this issue Jul 14, 2017 · 2 comments · Fixed by #655
Labels

Comments

@richyvk
Copy link

richyvk commented Jul 14, 2017

My test script:

date_formats = ['MM/DD/YYYY', 'YYYY-MM-DD', 'X', 'DD-MMMM-YYYY', 'D MMM YYYY']

while True:
    date_to_find = input("Enter date to parse: ")
    parsed_input = arrow.get(date_to_find, date_formats)
    print(parsed_input, ' -- ', parsed_input.timestamp)

Sample output:

Enter date to parse: 07/15/2000
2000-07-15T00:00:00+00:00  --  963619200
Enter date to parse: 2000-07-15
2000-07-15T00:00:00+00:00  --  963619200
Enter date to parse: 963619200
2000-07-15T00:00:00+00:00  --  963619200
Enter date to parse: 15-July-2000
1970-01-01T00:00:15+00:00  --  15
Enter date to parse: 15 Jul 2000
1970-01-01T00:00:15+00:00  --  15

Seems not to like months as words. Is this normal?

@richyvk richyvk changed the title Odd parsing form list of formats Odd parsing from list of formats Jul 14, 2017
@termdew
Copy link

termdew commented Jul 14, 2017

Hi richyvk!

Do you really need the "date_formats" array?
I've edited your code a little bit:

#!/usr/bin/env/python3

import arrow
import datetime

while True:
    date_to_find = input("Enter date to parse: ")
    parsed_input = arrow.get(date_to_find)
    print(parsed_input, ' -- ', parsed_input.timestamp)

And then i get this:

Enter date to parse: 15-July-2000
2000-01-01T00:00:00+00:00  --  946684800

Best regards,
Lightlace

@richyvk
Copy link
Author

richyvk commented Jul 14, 2017

Thanks for that Lightlace. But I think this doesn't work.

From your example the date is wrong no? It should be 2000-07-15 not 2000-01-01

Also, removing the list just raises errors for certain attempted parses - e.g. try 15 Jul 2000 - this errors.

The error says Could not match input to any of ['YYYY-MM-DD HH:mm'] on '15 Jul 2000' so it looks like get expects only that format if no list of formats is provided.

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

Successfully merging a pull request may close this issue.

3 participants