-
-
Notifications
You must be signed in to change notification settings - Fork 678
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
Accurate handling of parsing errors #91
Comments
The challenge with this issue is that, based on how the parser works, its supposed to behave this way. It found a year, and returned a date/time that has the right year and everything else zeroed out. The issue here is that the input needs to be sanitized, and that (IMO) would be the job of the application prior to calling I would suggest closing this issue as a non-issue. |
I don't think its supposed to behave this way. Documentation for
As I see ISO-8601 describe wide range of date strings formats that can be unambiguously interpreted. Here is the list of supported ISO-8601 formats in
In my opinion |
There could be a way how to switch the parser to a strict mode, if one needs it. Sometimes it's useful to fail fast and be strict about inputs. Also, |
Hi, is there any movement on this? Or a workaround? We are parsing OG tags on pages and some of them have some really malformed shit there. And Arrow is not helping: In [52]: arrow_get('blabla102015').isoformat()
Out[52]: '1020-01-01T00:00:00+00:00' |
Really annoying that it parses so relaxedly. Almost worse than php date parsing. |
Ditto, I deal with various data sources and date formats on a daily basis and arrow has been very valuable in handling parsing automagically. Would also be useful to document the complete list of supported formats, |
@laruellef I don't think it's documented anywhere. @rutsky I agree, but inorder to not break backwards compatibility it would need to be a flag to be set. |
Related to #292, #267 and #399 I'd like to handle two situations which might be fixed with the same code:
|
I don't think JS and JS libraries are good example of robust design in general. moment.js it's a good library, but Python good practices enforces the use of exceptions (or at least to return a None, if you want a C-style speedup in your code) |
@MarcoSulla Agreed, it's just a basis, but doesn't mean Arrow has to implement it verbatim. |
The current situation for all these examples. >>> arrow.get('2014-01-25 01:22:58')
<Arrow [2014-01-25T01:22:58+00:00]>
>>> arrow.get('blabla102015').isoformat()
'1020-01-01T00:00:00+00:00'
>>> arrow.get("Happy 2014!")
Traceback (most recent call last):
File "<stdin>", line 1, 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 HH:mm'] on 'Happy 2014!'
>>> arrow.get("02/01/2004")
<Arrow [2004-01-01T00:00:00+00:00]>
>>> arrow.get("10/10/2016")
<Arrow [2016-01-01T00:00:00+00:00]>
>>> arrow.get("2016-1-10")
<Arrow [2016-01-01T00:00:00+00:00]> |
Arrow can silently fail to parse complete date string and return invalid result when date string partially matches one of formats.
Consider parsing SQLite date-time string:
Note that time part of date not parsed and were silently lost.
Or parsing even not date-time sting:
The text was updated successfully, but these errors were encountered: