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

No error raised on invalid dates #519

Closed
ryantuck opened this issue Feb 27, 2018 · 5 comments · Fixed by #655
Closed

No error raised on invalid dates #519

ryantuck opened this issue Feb 27, 2018 · 5 comments · Fixed by #655
Labels

Comments

@ryantuck
Copy link

It seems like an error should be thrown on invalid dates, but this doesn't appear to happen. Is there some parameter I need to pass in to the get() function to enforce these are checked properly?

Using v0.12.1:

In [21]: import arrow

In [22]: arrow.get('2/30/2018')
Out[22]: <Arrow [2018-01-01T00:00:00+00:00]>

In [23]: arrow.get('13/4/2045')
Out[23]: <Arrow [2045-01-01T00:00:00+00:00]>
@akatcha
Copy link

akatcha commented Mar 31, 2018

I would like to tackle this. Any suggestions on where I can start?

@Luca409
Copy link

Luca409 commented Apr 1, 2018

Actually, errors are raised for invalid dates that are correctly formatted:
>>> arrow.get('2018-02-30') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Python/2.7/site-packages/arrow/api.py", line 23, in get return _factory.get(*args, **kwargs) File "/Library/Python/2.7/site-packages/arrow/factory.py", line 164, in get dt = parser.DateTimeParser(locale).parse_iso(arg) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 110, in parse_iso return self._parse_multiformat(string, formats) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 261, in _parse_multiformat _datetime = self.parse(string, fmt) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 167, in parse return self._build_datetime(parts) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 253, in _build_datetime tzinfo=parts.get('tzinfo')) ValueError: day is out of range for month

Notice that your output just points to January 1st of that year. There is a bug with parsing dates in that format. Either these dates need to be correctly parsed (and then the invalid date error can be raised), or dates in this format need to have the same effect as:

>>> >>> arrow.get('hello world') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Library/Python/2.7/site-packages/arrow/api.py", line 23, in get return _factory.get(*args, **kwargs) File "/Library/Python/2.7/site-packages/arrow/factory.py", line 164, in get dt = parser.DateTimeParser(locale).parse_iso(arg) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 110, in parse_iso return self._parse_multiformat(string, formats) File "/Library/Python/2.7/site-packages/arrow/parser.py", line 267, in _parse_multiformat raise ParserError('Could not match input to any of {0} on \'{1}\''.format(formats, string)) arrow.parser.ParserError: Could not match input to any of [u'YYYY-MM-DD HH:mm'] on 'hello world'

@akatcha
Copy link

akatcha commented Apr 3, 2018

Good point. For consistency, which do you think is the best way to tackle this?

@Luca409
Copy link

Luca409 commented Apr 5, 2018

I would count dates in the format "MM/DD/YYYY" as invalid for now.

@akatcha
Copy link

akatcha commented Apr 9, 2018

@Luca409 @ryantuck
I have submitted a pull request for this issue here: #527
Feel free to give it a review!

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