Support for 9 fractional second digits (ns)
Firstly, 9 fractional second digits is approved in ISO8610(RFC3339).
... one or more digits representing a decimal fraction of a second
as it put (https://www.w3.org/TR/NOTE-datetime).
A 9 fractional second digits ISO8610 datetime can be generated in a Linux/Unix environment(not OS X) as this way:
$ date --rfc-3339=ns
2016-06-23 16:40:27.329428631+08:00
I'm using Arrow 0.7.0, with python 2.7.11, on both OS X(10.11.5) and Ubuntu 14.04.
As for Arrow implementation in my environments:
>>> import arrow
>>> s1='2016-06-23 16:40:27.329428631+08:00'
>>> arrow.get(s1)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.7/site-packages/arrow/arrow.py", line 286, in __repr__ return '<{0} [{1}]>'.format(self.__class__.__name__, self.__str__()) File "/usr/lib/python2.7/site-packages/arrow/arrow.py", line 289, in __str__ return self._datetime.isoformat() ValueError: tzinfo.utcoffset() returned 1440; must be in -1439 .. 1439
But works fine in case of 6 fractional second digits:
>>> import arrow
>>> s2='2016-06-23 16:40:27.329428+08:00'
>>> arrow.get(s2)
<Arrow [2016-06-24T16:40:27.329428+08:00]>
Lastly, I have a quick look in parse.py, the reason of the above seems to be Arrow never support a 9 fractional second digits datetime string, and only support up to 6 digits (the _FORMAT_RE in https://github.com/crsmithdev/arrow/blob/master/arrow/parser.py line 17).
Update: I have noticed that datetime itself do not support 9 fractional second digits either (https://docs.python.org/2/library/datetime.html#datetime.datetime.microsecond ):
datetime.microsecond In range(1000000).
I believe this is fixed in 0.9.0. Please have a try.
Not fixed
nor in 0.10.0
Confirmed, but not having it in datetime itself makes fixing it more involved.
Has there been any activity in a potential solution to this problem?
This is the current situation. Arrow will now parse this timestamp but truncate it to 6 fractional seconds.
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> s1='2016-06-23 16:40:27.329428631+08:00'
>>> arrow.get(s1)
<Arrow [2016-06-23T16:40:27.329429+08:00]>
Addressing https://github.com/crsmithdev/arrow/issues/636 should help with rounding large subseconds, but like people have said previously, without official ns support from datetime, the change to support ns will be more involved.