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

improving get method #538

Closed
aster94 opened this issue Apr 28, 2018 · 5 comments · Fixed by #655
Closed

improving get method #538

aster94 opened this issue Apr 28, 2018 · 5 comments · Fixed by #655
Labels

Comments

@aster94
Copy link

aster94 commented Apr 28, 2018

hello,
i would like to ask for a new feature which is present in other library which manages times, for example in moment
in that module i can do something like
moment.date(d)
where d is 01/01/2001 or 1/1/2001 or 01/01/01 or 01-01-2001
i am trying to say that it accept quite everything, it would be nice if get() was able to be feed with everything too

here there is a code snippet if you want to try

import arrow, moment

d = ["01/01/2001", "2/2/2002", "03/03/03", "04-04-2004"]
for item in d:
    m = moment.date(item)
    a = arrow.get(item)
    print ("m: ")
    print(m)
    print ("a: ")
    print (a)
    print ()
@mscansian
Copy link

How does this lib handle dates like 10/05/2018. Is it October 5th or May 10th?

@aster94
Copy link
Author

aster94 commented Apr 30, 2018

You can specify what you are parsing with ".format("DD/MM/YYYY)"

The default should be this MM/DD/YYYY

Btw is this related to the issue?

@labrys
Copy link

labrys commented Jun 19, 2018

@aster94 If anything the default should probably be DMY as its used in more countries than MDY.
source: Date Format By Country

@aster94
Copy link
Author

aster94 commented Jun 19, 2018

Hi,
The default is not related to the issue, please read again the first post

@systemcatch
Copy link
Collaborator

The current situation.

Python 3.6.7 (default, Oct 25 2018, 09:16:13) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> d = ["01/01/2001", "2/2/2002", "03/03/03", "04-04-2004"]
>>> for ts in d:
...     arrow.get(ts)
... 
<Arrow [2001-01-01T00:00:00+00:00]>
<Arrow [2002-01-01T00:00:00+00:00]>
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/chris/arrow/arrow/api.py", line 22, in get
    return _factory.get(*args, **kwargs)
  File "/home/chris/arrow/arrow/factory.py", line 174, in get
    dt = parser.DateTimeParser(locale).parse_iso(arg)
  File "/home/chris/arrow/arrow/parser.py", line 119, in parse_iso
    return self._parse_multiformat(string, formats)
  File "/home/chris/arrow/arrow/parser.py", line 286, in _parse_multiformat
    raise ParserError('Could not match input to any of {} on \'{}\''.format(formats, string))
arrow.parser.ParserError: Could not match input to any of ['YYYY-MM-DD', 'YYYY/MM/DD', 'YYYY.MM.DD', 'YYYY-MM', 'YYYY/MM', 'YYYY.MM', 'YYYY', 'YYYY', 'YYYY'] on '03/03/03'
<Arrow [2004-01-01T00:00:00+00:00]>

2nd and 4th results are examples of .get() returning very hard to detect errors rather than simply failing. This is already reported and needs to be fixed, I also suspect 1st result is lucky rather than reliable. 3rd result is kind of whatever tbh.

Until the .get() problem is fixed I strongly advise you to always pass formats if possible.

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.

5 participants