Closed hexcowboy closed 3 years ago
Thanks for the report!
Just one thing, it looks like there is a Z (zulu) time zone in your example, when I try it I get UTC as the time zone (not exactly right, I know). Can you confirm this without the Z character? Thanks!
When I try without the Z uses the default:
❯ ipython
Python 3.9.0 (default, Oct 9 2020, 13:52:19)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import iso8601
In [2]: iso8601.parse_date("2021-06-24T14:54:41.634362969Z")
Out[2]: datetime.datetime(2021, 6, 24, 14, 54, 41, 634362, tzinfo=datetime.timezone.utc)
In [3]: iso8601.parse_date("2021-06-24T14:54:41.634362969")
Out[3]: datetime.datetime(2021, 6, 24, 14, 54, 41, 634362, tzinfo=datetime.timezone.utc)
In [4]: iso8601.parse_date("2021-06-24T14:54:41.634362969Z", default_timezone=None)
Out[4]: datetime.datetime(2021, 6, 24, 14, 54, 41, 634362, tzinfo=datetime.timezone.utc)
In [5]: iso8601.parse_date("2021-06-24T14:54:41.634362969", default_timezone=None)
Out[5]: datetime.datetime(2021, 6, 24, 14, 54, 41, 634362)
Confirming that it is indeed the Zulu that is causing unexpected behavior
➜ ipython
Python 3.9.5 (default, May 10 2021, 19:47:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import iso8601
In [2]: iso8601.parse_date("2013-10-15T18:30Z", default_timezone=None)
Out[2]: datetime.datetime(2013, 10, 15, 18, 30, tzinfo=datetime.timezone.utc)
In [3]: iso8601.parse_date("2013-10-15T18:30", default_timezone=None)
Out[3]: datetime.datetime(2013, 10, 15, 18, 30)
Cool, thanks for checking! It looks like the code is behaving itself as we're expecting, I'll close this issue but ping again if it's still a problem!
When parsing an ISO time and supplying the
default_timezone=None
, a naive time should be returned. Instead, a UTC timezonedatetime
is returned.From the annotations:
According to the Python docs,
Expected:
Actual: