dateutil icon indicating copy to clipboard operation
dateutil copied to clipboard

Add isoparse example to the documentation

Open dpriskorn opened this issue 5 years ago • 2 comments

I'm trying to parse this: "2020-08-20T03:33:46.000Z" and it does not seem to work. I have not found any examples in the documentation that I can try so I don't know if if I'm doing something wrong or if I found a bug.

I get these errors:

>>> import dateutil.parser
>>> dateutil.parser.isoparser("2020-08-20T03:33:46")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/dateutil/parser/isoparser.py", line 52, in __init__
    raise ValueError('Separator must be a single, non-numeric ' +
ValueError: Separator must be a single, non-numeric ASCII character 
>>> dateutil.parser.isoparser("2020-08-20T03:33:46.000Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/dateutil/parser/isoparser.py", line 52, in __init__
    raise ValueError('Separator must be a single, non-numeric ' +
ValueError: Separator must be a single, non-numeric ASCII character

I tried supplying a separator like this:

>>> dateutil.parser.isoparser("2020-08-20T03:33:46.000Z", sep="T")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __init__() got multiple values for argument 'sep'

I also tried with a string from the RFC standard but that failed too:

>>> dateutil.parser.isoparser("1997-07-16T19:20+01:00")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.8/site-packages/dateutil/parser/isoparser.py", line 52, in __init__
    raise ValueError('Separator must be a single, non-numeric ' +
ValueError: Separator must be a single, non-numeric ASCII character

dpriskorn avatar Aug 24 '20 10:08 dpriskorn

You are actually using the class isoparser instead of the documented method isoparse. After fixing the typo it should work:

>>> from dateutil.parser import isoparse
>>> isoparse("2020-08-20T03:33:46.000Z")
datetime.datetime(2020, 8, 20, 3, 33, 46, tzinfo=tzutc())

An example to copy and paste would have probably avoided this issue, so adding one to the docs definitely wouldn't hurt.

ffe4 avatar Aug 24 '20 14:08 ffe4

@ffe4 I would like to work on this could you tell me how should I make the PR

king-11 avatar May 17 '21 15:05 king-11